-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtemplate.h
More file actions
162 lines (137 loc) · 4.14 KB
/
template.h
File metadata and controls
162 lines (137 loc) · 4.14 KB
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
/**
* Template.h
*
* The template for regular PHP objects and arrays that are exposed to JS space.
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2025 Copernica BV
*/
/**
* Include guard
*/
#pragma once
/**
* Dependencies
*/
#include <phpcpp.h>
#include <v8.h>
/**
* Begin of namespace
*/
namespace JS {
/**
* Class definition
*/
class Template
{
protected:
/**
* The isolate to which it belongs
* @var v8::Isolate
*/
v8::Isolate *_isolate;
/**
* Handle to the template object
* @var v8::Global<ObjectTemplate>
*/
v8::Global<v8::ObjectTemplate> _template;
/**
* We want to remember which features have been enabled for this template
* @var bool
*/
bool _realarray = false;
bool _arrayaccess = false;
bool _callable = false;
private:
/**
* Retrieve a property or function from the object
* @param property The name to find the property
* @param info callback info
* @return v8::Intercepted
*/
static v8::Intercepted getProperty(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value> &info);
/**
* Retrieve a symbol from the object
* @param symbol the symbol to retrieve
* @param info callback info
*/
static v8::Intercepted getSymbol(v8::Local<v8::Symbol> symbol, const v8::PropertyCallbackInfo<v8::Value> &info);
/**
* Convert to a string
* @param info callback info
*/
static v8::Intercepted getString(const v8::PropertyCallbackInfo<v8::Value> &info);
/**
* Convert to an iterator
* @param info callback info
*/
static v8::Intercepted getIterator(const v8::PropertyCallbackInfo<v8::Value> &info);
/**
* Retrieve a property or function from the object
* @param index The index to find the property
* @param info callback info
* @return v8::Intercepted
*/
static v8::Intercepted getIndex(unsigned index, const v8::PropertyCallbackInfo<v8::Value> &info);
/**
* Set a property or function on the object
* @param property the property to update
* @param input the new property value
* @param info callback info
*/
static v8::Intercepted setProperty(v8::Local<v8::Name> property, v8::Local<v8::Value> input, const v8::PropertyCallbackInfo<void>& info);
/**
* Set a property or function on the object
* @param index The index to update
* @param input the new property value
* @param info callback info
*/
static v8::Intercepted setIndex(unsigned index, v8::Local<v8::Value> input, const v8::PropertyCallbackInfo<void>& info);
/**
* Retrieve a list of string properties for enumeration
* @param info callback info
*/
static void enumerateProperties(const v8::PropertyCallbackInfo<v8::Array> &info);
/**
* Retrieve a list of integer properties for enumeration
* @param info callback info
*/
static void enumerateIndexes(const v8::PropertyCallbackInfo<v8::Array> &info);
/**
* A function is called that happens to be a method
* @param into callback info
*/
static void method(const v8::FunctionCallbackInfo<v8::Value>& info);
/**
* The object is called as if it was a function
* @param into callback info
*/
static void call(const v8::FunctionCallbackInfo<v8::Value>& info);
public:
/**
* Constructor
* @param isolate
* @param value
*/
Template(v8::Isolate *isolate, const Php::Value &value);
/**
* Destructor
*/
virtual ~Template();
/**
* Is this template useful for a certain object
* @param value
* @return bool
*/
bool matches(const Php::Value &value) const;
/**
* Apply the template on a PHP variable, to turn it into a JS object
* @param value
* @return v8::Local<v8::Object>
*/
v8::Local<v8::Value> apply(const Php::Value &value) const;
};
/**
* End of namespace
*/
}