| 14 |
liveuser |
1 |
/*********************************************************************
|
|
|
2 |
* NAN - Native Abstractions for Node.js
|
|
|
3 |
*
|
|
|
4 |
* Copyright (c) 2016 NAN contributors
|
|
|
5 |
*
|
|
|
6 |
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
|
|
|
7 |
********************************************************************/
|
|
|
8 |
|
|
|
9 |
#ifndef NAN_MAYBE_43_INL_H_
|
|
|
10 |
#define NAN_MAYBE_43_INL_H_
|
|
|
11 |
|
|
|
12 |
template<typename T>
|
|
|
13 |
using MaybeLocal = v8::MaybeLocal<T>;
|
|
|
14 |
|
|
|
15 |
template<typename T>
|
|
|
16 |
using Maybe = v8::Maybe<T>;
|
|
|
17 |
|
|
|
18 |
template<typename T>
|
|
|
19 |
inline Maybe<T> Nothing() {
|
|
|
20 |
return v8::Nothing<T>();
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
template<typename T>
|
|
|
24 |
inline Maybe<T> Just(const T& t) {
|
|
|
25 |
return v8::Just<T>(t);
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
v8::Local<v8::Context> GetCurrentContext();
|
|
|
29 |
|
|
|
30 |
inline
|
|
|
31 |
MaybeLocal<v8::String> ToDetailString(v8::Local<v8::Value> val) {
|
|
|
32 |
return val->ToDetailString(GetCurrentContext());
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
inline
|
|
|
36 |
MaybeLocal<v8::Uint32> ToArrayIndex(v8::Local<v8::Value> val) {
|
|
|
37 |
return val->ToArrayIndex(GetCurrentContext());
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
inline
|
|
|
41 |
Maybe<bool> Equals(v8::Local<v8::Value> a, v8::Local<v8::Value>(b)) {
|
|
|
42 |
return a->Equals(GetCurrentContext(), b);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
inline
|
|
|
46 |
MaybeLocal<v8::Object> NewInstance(v8::Local<v8::Function> h) {
|
|
|
47 |
return h->NewInstance(GetCurrentContext());
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
inline
|
|
|
51 |
MaybeLocal<v8::Object> NewInstance(
|
|
|
52 |
v8::Local<v8::Function> h
|
|
|
53 |
, int argc
|
|
|
54 |
, v8::Local<v8::Value> argv[]) {
|
|
|
55 |
return h->NewInstance(GetCurrentContext(), argc, argv);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
inline
|
|
|
59 |
MaybeLocal<v8::Object> NewInstance(v8::Local<v8::ObjectTemplate> h) {
|
|
|
60 |
return h->NewInstance(GetCurrentContext());
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
inline MaybeLocal<v8::Function> GetFunction(
|
|
|
65 |
v8::Local<v8::FunctionTemplate> t) {
|
|
|
66 |
return t->GetFunction(GetCurrentContext());
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
inline Maybe<bool> Set(
|
|
|
70 |
v8::Local<v8::Object> obj
|
|
|
71 |
, v8::Local<v8::Value> key
|
|
|
72 |
, v8::Local<v8::Value> value) {
|
|
|
73 |
return obj->Set(GetCurrentContext(), key, value);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
inline Maybe<bool> Set(
|
|
|
77 |
v8::Local<v8::Object> obj
|
|
|
78 |
, uint32_t index
|
|
|
79 |
, v8::Local<v8::Value> value) {
|
|
|
80 |
return obj->Set(GetCurrentContext(), index, value);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
inline Maybe<bool> ForceSet(
|
|
|
84 |
v8::Local<v8::Object> obj
|
|
|
85 |
, v8::Local<v8::Value> key
|
|
|
86 |
, v8::Local<v8::Value> value
|
|
|
87 |
, v8::PropertyAttribute attribs = v8::None) {
|
|
|
88 |
return obj->ForceSet(GetCurrentContext(), key, value, attribs);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
inline MaybeLocal<v8::Value> Get(
|
|
|
92 |
v8::Local<v8::Object> obj
|
|
|
93 |
, v8::Local<v8::Value> key) {
|
|
|
94 |
return obj->Get(GetCurrentContext(), key);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
inline
|
|
|
98 |
MaybeLocal<v8::Value> Get(v8::Local<v8::Object> obj, uint32_t index) {
|
|
|
99 |
return obj->Get(GetCurrentContext(), index);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
inline v8::PropertyAttribute GetPropertyAttributes(
|
|
|
103 |
v8::Local<v8::Object> obj
|
|
|
104 |
, v8::Local<v8::Value> key) {
|
|
|
105 |
return obj->GetPropertyAttributes(GetCurrentContext(), key).FromJust();
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
inline Maybe<bool> Has(
|
|
|
109 |
v8::Local<v8::Object> obj
|
|
|
110 |
, v8::Local<v8::String> key) {
|
|
|
111 |
return obj->Has(GetCurrentContext(), key);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
inline Maybe<bool> Has(v8::Local<v8::Object> obj, uint32_t index) {
|
|
|
115 |
return obj->Has(GetCurrentContext(), index);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
inline Maybe<bool> Delete(
|
|
|
119 |
v8::Local<v8::Object> obj
|
|
|
120 |
, v8::Local<v8::String> key) {
|
|
|
121 |
return obj->Delete(GetCurrentContext(), key);
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
inline
|
|
|
125 |
Maybe<bool> Delete(v8::Local<v8::Object> obj, uint32_t index) {
|
|
|
126 |
return obj->Delete(GetCurrentContext(), index);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
inline
|
|
|
130 |
MaybeLocal<v8::Array> GetPropertyNames(v8::Local<v8::Object> obj) {
|
|
|
131 |
return obj->GetPropertyNames(GetCurrentContext());
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
inline
|
|
|
135 |
MaybeLocal<v8::Array> GetOwnPropertyNames(v8::Local<v8::Object> obj) {
|
|
|
136 |
return obj->GetOwnPropertyNames(GetCurrentContext());
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
inline Maybe<bool> SetPrototype(
|
|
|
140 |
v8::Local<v8::Object> obj
|
|
|
141 |
, v8::Local<v8::Value> prototype) {
|
|
|
142 |
return obj->SetPrototype(GetCurrentContext(), prototype);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
inline MaybeLocal<v8::String> ObjectProtoToString(
|
|
|
146 |
v8::Local<v8::Object> obj) {
|
|
|
147 |
return obj->ObjectProtoToString(GetCurrentContext());
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
inline Maybe<bool> HasOwnProperty(
|
|
|
151 |
v8::Local<v8::Object> obj
|
|
|
152 |
, v8::Local<v8::String> key) {
|
|
|
153 |
return obj->HasOwnProperty(GetCurrentContext(), key);
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
inline Maybe<bool> HasRealNamedProperty(
|
|
|
157 |
v8::Local<v8::Object> obj
|
|
|
158 |
, v8::Local<v8::String> key) {
|
|
|
159 |
return obj->HasRealNamedProperty(GetCurrentContext(), key);
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
inline Maybe<bool> HasRealIndexedProperty(
|
|
|
163 |
v8::Local<v8::Object> obj
|
|
|
164 |
, uint32_t index) {
|
|
|
165 |
return obj->HasRealIndexedProperty(GetCurrentContext(), index);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
inline Maybe<bool> HasRealNamedCallbackProperty(
|
|
|
169 |
v8::Local<v8::Object> obj
|
|
|
170 |
, v8::Local<v8::String> key) {
|
|
|
171 |
return obj->HasRealNamedCallbackProperty(GetCurrentContext(), key);
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
inline MaybeLocal<v8::Value> GetRealNamedPropertyInPrototypeChain(
|
|
|
175 |
v8::Local<v8::Object> obj
|
|
|
176 |
, v8::Local<v8::String> key) {
|
|
|
177 |
return obj->GetRealNamedPropertyInPrototypeChain(GetCurrentContext(), key);
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
inline MaybeLocal<v8::Value> GetRealNamedProperty(
|
|
|
181 |
v8::Local<v8::Object> obj
|
|
|
182 |
, v8::Local<v8::String> key) {
|
|
|
183 |
return obj->GetRealNamedProperty(GetCurrentContext(), key);
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
inline MaybeLocal<v8::Value> CallAsFunction(
|
|
|
187 |
v8::Local<v8::Object> obj
|
|
|
188 |
, v8::Local<v8::Object> recv
|
|
|
189 |
, int argc
|
|
|
190 |
, v8::Local<v8::Value> argv[]) {
|
|
|
191 |
return obj->CallAsFunction(GetCurrentContext(), recv, argc, argv);
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
inline MaybeLocal<v8::Value> CallAsConstructor(
|
|
|
195 |
v8::Local<v8::Object> obj
|
|
|
196 |
, int argc, v8::Local<v8::Value> argv[]) {
|
|
|
197 |
return obj->CallAsConstructor(GetCurrentContext(), argc, argv);
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
inline
|
|
|
201 |
MaybeLocal<v8::String> GetSourceLine(v8::Local<v8::Message> msg) {
|
|
|
202 |
return msg->GetSourceLine(GetCurrentContext());
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
inline Maybe<int> GetLineNumber(v8::Local<v8::Message> msg) {
|
|
|
206 |
return msg->GetLineNumber(GetCurrentContext());
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
inline Maybe<int> GetStartColumn(v8::Local<v8::Message> msg) {
|
|
|
210 |
return msg->GetStartColumn(GetCurrentContext());
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
inline Maybe<int> GetEndColumn(v8::Local<v8::Message> msg) {
|
|
|
214 |
return msg->GetEndColumn(GetCurrentContext());
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
inline MaybeLocal<v8::Object> CloneElementAt(
|
|
|
218 |
v8::Local<v8::Array> array
|
|
|
219 |
, uint32_t index) {
|
|
|
220 |
#if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION)
|
|
|
221 |
v8::EscapableHandleScope handle_scope(v8::Isolate::GetCurrent());
|
|
|
222 |
v8::Local<v8::Context> context = GetCurrentContext();
|
|
|
223 |
v8::Local<v8::Value> elem;
|
|
|
224 |
if (!array->Get(context, index).ToLocal(&elem)) {
|
|
|
225 |
return MaybeLocal<v8::Object>();
|
|
|
226 |
}
|
|
|
227 |
v8::Local<v8::Object> obj;
|
|
|
228 |
if (!elem->ToObject(context).ToLocal(&obj)) {
|
|
|
229 |
return MaybeLocal<v8::Object>();
|
|
|
230 |
}
|
|
|
231 |
return MaybeLocal<v8::Object>(handle_scope.Escape(obj->Clone()));
|
|
|
232 |
#else
|
|
|
233 |
return array->CloneElementAt(GetCurrentContext(), index);
|
|
|
234 |
#endif
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
inline MaybeLocal<v8::Value> Call(
|
|
|
238 |
v8::Local<v8::Function> fun
|
|
|
239 |
, v8::Local<v8::Object> recv
|
|
|
240 |
, int argc
|
|
|
241 |
, v8::Local<v8::Value> argv[]) {
|
|
|
242 |
return fun->Call(GetCurrentContext(), recv, argc, argv);
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
#endif // NAN_MAYBE_43_INL_H_
|