forked from CopernicaMarketingSoftware/PHP-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsobject.h
176 lines (155 loc) · 3.46 KB
/
jsobject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* jsobject.h
*
* Class that wraps around an ecmascript object
* and makes it available to PHP userspace.
*
* @copyright 2015 Copernica B.V.
*/
/**
* Include guard
*/
#pragma once
/**
* Dependencies
*/
#include <phpcpp.h>
#include <v8.h>
#include "stack.h"
/**
* Start namespace
*/
namespace JS {
/**
* Class definition
*/
class JSObject :
public Php::Base,
public Php::Traversable
{
private:
/**
* The underlying ecmascript object
* @var Stack<v8::Object>
*/
Stack<v8::Object> _object;
public:
/**
* Class definition
*/
class Iterator : public Php::Iterator
{
private:
/**
* The underlying ecmascript object
* @var Stack<v8::Object>
*/
Stack<v8::Object> _object;
/**
* All properties in the object
* @var Stack<v8::Array>
*/
Stack<v8::Array> _keys;
/**
* Current position in the object
* @var uint32_t
*/
uint32_t _position;
/**
* Number of valid keys
* @var uint32_t
*/
uint32_t _size;
public:
/**
* Constructor
*
* @param base The base that PHP-CPP insists on
* @param object The object to iterate
*/
Iterator(Php::Base *base, const Stack<v8::Object> &object);
/**
* Is the iterator still valid?
*
* @return is an element present at the current offset
*/
bool valid() override;
/**
* Retrieve the current value
*
* @return value at current offset
*/
Php::Value current() override;
/**
* Retrieve the current key
*
* @return the current key
*/
Php::Value key() override;
/**
* Move ahead to the next item
*/
void next() override;
/**
* Start over at the beginning
*/
void rewind() override;
};
/**
* Constructor
*
* @param object The ecmascript object
*/
JSObject(v8::Handle<v8::Object> object);
/**
* Retrieve a property
*
* @param name Name of the property
* @return The requested property
*/
Php::Value __get(const Php::Value &name) const;
/**
* Change a property
*
* @param name Name of the property
* @param property New value for the property
*/
void __set(const Php::Value &name, const Php::Value &property);
/**
* Check if a property is set
*
* @param name Name of the property
* @return Is the property set
*/
bool __isset(const Php::Value &name);
/**
* Call a function
*
* @param name Name of the function to call
* @param params The input parameters
* @return The result of the function call
*/
Php::Value __call(const char *name, Php::Parameters ¶ms);
/**
* Cast to a string
*
* @return The result of the string conversion
*/
Php::Value __toString();
/**
* Retrieve the iterator
*
* @return The iterator
*/
Php::Iterator *getIterator() override;
/**
* Retrieve the original ecmascript value
*
* @return original ecmascript value
*/
v8::Local<v8::Object> object() const;
};
/**
* End namespace
*/
}