Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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_IMPLEMENTATION_PRE_12_INL_H_
10
#define NAN_IMPLEMENTATION_PRE_12_INL_H_
11
 
12
//==============================================================================
13
// node v0.10 implementation
14
//==============================================================================
15
 
16
namespace imp {
17
 
18
//=== Array ====================================================================
19
 
20
Factory<v8::Array>::return_t
21
Factory<v8::Array>::New() {
22
  return v8::Array::New();
23
}
24
 
25
Factory<v8::Array>::return_t
26
Factory<v8::Array>::New(int length) {
27
  return v8::Array::New(length);
28
}
29
 
30
//=== Boolean ==================================================================
31
 
32
Factory<v8::Boolean>::return_t
33
Factory<v8::Boolean>::New(bool value) {
34
  return v8::Boolean::New(value)->ToBoolean();
35
}
36
 
37
//=== Boolean Object ===========================================================
38
 
39
Factory<v8::BooleanObject>::return_t
40
Factory<v8::BooleanObject>::New(bool value) {
41
  return v8::BooleanObject::New(value).As<v8::BooleanObject>();
42
}
43
 
44
//=== Context ==================================================================
45
 
46
Factory<v8::Context>::return_t
47
Factory<v8::Context>::New( v8::ExtensionConfiguration* extensions
48
                         , v8::Local<v8::ObjectTemplate> tmpl
49
                         , v8::Local<v8::Value> obj) {
50
  v8::Persistent<v8::Context> ctx = v8::Context::New(extensions, tmpl, obj);
51
  v8::Local<v8::Context> lctx = v8::Local<v8::Context>::New(ctx);
52
  ctx.Dispose();
53
  return lctx;
54
}
55
 
56
//=== Date =====================================================================
57
 
58
Factory<v8::Date>::return_t
59
Factory<v8::Date>::New(double value) {
60
  return Factory<v8::Date>::return_t(v8::Date::New(value).As<v8::Date>());
61
}
62
 
63
//=== External =================================================================
64
 
65
Factory<v8::External>::return_t
66
Factory<v8::External>::New(void * value) {
67
  return v8::External::New(value);
68
}
69
 
70
//=== Function =================================================================
71
 
72
Factory<v8::Function>::return_t
73
Factory<v8::Function>::New( FunctionCallback callback
74
                          , v8::Local<v8::Value> data) {
75
  return Factory<v8::FunctionTemplate>::New( callback
76
                                           , data
77
                                           , v8::Local<v8::Signature>()
78
                                           )->GetFunction();
79
}
80
 
81
 
82
//=== FunctionTemplate =========================================================
83
 
84
Factory<v8::FunctionTemplate>::return_t
85
Factory<v8::FunctionTemplate>::New( FunctionCallback callback
86
                                  , v8::Local<v8::Value> data
87
                                  , v8::Local<v8::Signature> signature) {
88
  if (callback) {
89
    v8::HandleScope scope;
90
 
91
    v8::Local<v8::ObjectTemplate> tpl = v8::ObjectTemplate::New();
92
    tpl->SetInternalFieldCount(imp::kFunctionFieldCount);
93
    v8::Local<v8::Object> obj = tpl->NewInstance();
94
 
95
    obj->SetInternalField(
96
        imp::kFunctionIndex
97
      , v8::External::New(reinterpret_cast<void *>(callback)));
98
 
99
    v8::Local<v8::Value> val = v8::Local<v8::Value>::New(data);
100
 
101
    if (!val.IsEmpty()) {
102
      obj->SetInternalField(imp::kDataIndex, val);
103
    }
104
 
105
    // Note(agnat): Emulate length argument here. Unfortunately, I couldn't find
106
    // a way. Have at it though...
107
    return scope.Close(
108
        v8::FunctionTemplate::New(imp::FunctionCallbackWrapper
109
                                 , obj
110
                                 , signature));
111
  } else {
112
    return v8::FunctionTemplate::New(0, data, signature);
113
  }
114
}
115
 
116
//=== Number ===================================================================
117
 
118
Factory<v8::Number>::return_t
119
Factory<v8::Number>::New(double value) {
120
  return v8::Number::New(value);
121
}
122
 
123
//=== Number Object ============================================================
124
 
125
Factory<v8::NumberObject>::return_t
126
Factory<v8::NumberObject>::New(double value) {
127
  return v8::NumberObject::New(value).As<v8::NumberObject>();
128
}
129
 
130
//=== Integer, Int32 and Uint32 ================================================
131
 
132
template <typename T>
133
typename IntegerFactory<T>::return_t
134
IntegerFactory<T>::New(int32_t value) {
135
  return To<T>(T::New(value));
136
}
137
 
138
template <typename T>
139
typename IntegerFactory<T>::return_t
140
IntegerFactory<T>::New(uint32_t value) {
141
  return To<T>(T::NewFromUnsigned(value));
142
}
143
 
144
Factory<v8::Uint32>::return_t
145
Factory<v8::Uint32>::New(int32_t value) {
146
  return To<v8::Uint32>(v8::Uint32::NewFromUnsigned(value));
147
}
148
 
149
Factory<v8::Uint32>::return_t
150
Factory<v8::Uint32>::New(uint32_t value) {
151
  return To<v8::Uint32>(v8::Uint32::NewFromUnsigned(value));
152
}
153
 
154
 
155
//=== Object ===================================================================
156
 
157
Factory<v8::Object>::return_t
158
Factory<v8::Object>::New() {
159
  return v8::Object::New();
160
}
161
 
162
//=== Object Template ==========================================================
163
 
164
Factory<v8::ObjectTemplate>::return_t
165
Factory<v8::ObjectTemplate>::New() {
166
  return v8::ObjectTemplate::New();
167
}
168
 
169
//=== RegExp ===================================================================
170
 
171
Factory<v8::RegExp>::return_t
172
Factory<v8::RegExp>::New(
173
    v8::Local<v8::String> pattern
174
  , v8::RegExp::Flags flags) {
175
  return Factory<v8::RegExp>::return_t(v8::RegExp::New(pattern, flags));
176
}
177
 
178
//=== Script ===================================================================
179
 
180
Factory<v8::Script>::return_t
181
Factory<v8::Script>::New( v8::Local<v8::String> source) {
182
  return Factory<v8::Script>::return_t(v8::Script::New(source));
183
}
184
Factory<v8::Script>::return_t
185
Factory<v8::Script>::New( v8::Local<v8::String> source
186
                        , v8::ScriptOrigin const& origin) {
187
  return Factory<v8::Script>::return_t(
188
      v8::Script::New(source, const_cast<v8::ScriptOrigin*>(&origin)));
189
}
190
 
191
//=== Signature ================================================================
192
 
193
Factory<v8::Signature>::return_t
194
Factory<v8::Signature>::New(Factory<v8::Signature>::FTH receiver) {
195
  return v8::Signature::New(receiver);
196
}
197
 
198
//=== String ===================================================================
199
 
200
Factory<v8::String>::return_t
201
Factory<v8::String>::New() {
202
  return Factory<v8::String>::return_t(v8::String::Empty());
203
}
204
 
205
Factory<v8::String>::return_t
206
Factory<v8::String>::New(const char * value, int length) {
207
  return Factory<v8::String>::return_t(v8::String::New(value, length));
208
}
209
 
210
Factory<v8::String>::return_t
211
Factory<v8::String>::New(
212
    std::string const& value) /* NOLINT(build/include_what_you_use) */ {
213
  assert(value.size() <= INT_MAX && "string too long");
214
  return Factory<v8::String>::return_t(
215
      v8::String::New( value.data(), static_cast<int>(value.size())));
216
}
217
 
218
Factory<v8::String>::return_t
219
Factory<v8::String>::New(const uint16_t * value, int length) {
220
  return Factory<v8::String>::return_t(v8::String::New(value, length));
221
}
222
 
223
Factory<v8::String>::return_t
224
Factory<v8::String>::New(v8::String::ExternalStringResource * value) {
225
  return Factory<v8::String>::return_t(v8::String::NewExternal(value));
226
}
227
 
228
Factory<v8::String>::return_t
229
Factory<v8::String>::New(v8::String::ExternalAsciiStringResource * value) {
230
  return Factory<v8::String>::return_t(v8::String::NewExternal(value));
231
}
232
 
233
//=== String Object ============================================================
234
 
235
Factory<v8::StringObject>::return_t
236
Factory<v8::StringObject>::New(v8::Local<v8::String> value) {
237
  return v8::StringObject::New(value).As<v8::StringObject>();
238
}
239
 
240
}  // end of namespace imp
241
 
242
//=== Presistents and Handles ==================================================
243
 
244
template <typename T>
245
inline v8::Local<T> New(v8::Handle<T> h) {
246
  return v8::Local<T>::New(h);
247
}
248
 
249
template <typename T>
250
inline v8::Local<T> New(v8::Persistent<T> const& p) {
251
  return v8::Local<T>::New(p);
252
}
253
 
254
template <typename T, typename M>
255
inline v8::Local<T> New(Persistent<T, M> const& p) {
256
  return v8::Local<T>::New(p.persistent);
257
}
258
 
259
template <typename T>
260
inline v8::Local<T> New(Global<T> const& p) {
261
  return v8::Local<T>::New(p.persistent);
262
}
263
 
264
#endif  // NAN_IMPLEMENTATION_PRE_12_INL_H_