Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81145 views
1
/*********************************************************************
2
* NAN - Native Abstractions for Node.js
3
*
4
* Copyright (c) 2015 NAN contributors
5
*
6
* MIT License <https://github.com/rvagg/nan/blob/master/LICENSE.md>
7
********************************************************************/
8
9
#ifndef NAN_IMPLEMENTATION_12_INL_H_
10
#define NAN_IMPLEMENTATION_12_INL_H_
11
//==============================================================================
12
// node v0.11 implementation
13
//==============================================================================
14
15
#if defined(_MSC_VER)
16
# pragma warning( push )
17
# pragma warning( disable : 4530 )
18
# include <string>
19
# pragma warning( pop )
20
#else
21
# include <string>
22
#endif
23
24
namespace NanIntern {
25
26
//=== Array ====================================================================
27
28
Factory<v8::Array>::return_t
29
Factory<v8::Array>::New() {
30
return v8::Array::New(v8::Isolate::GetCurrent());
31
}
32
33
Factory<v8::Array>::return_t
34
Factory<v8::Array>::New(int length) {
35
return v8::Array::New(v8::Isolate::GetCurrent(), length);
36
}
37
38
//=== Boolean ==================================================================
39
40
Factory<v8::Boolean>::return_t
41
Factory<v8::Boolean>::New(bool value) {
42
return v8::Boolean::New(v8::Isolate::GetCurrent(), value);
43
}
44
45
//=== Boolean Object ===========================================================
46
47
Factory<v8::BooleanObject>::return_t
48
Factory<v8::BooleanObject>::New(bool value) {
49
return v8::BooleanObject::New(value).As<v8::BooleanObject>();
50
}
51
52
//=== Context ==================================================================
53
54
Factory<v8::Context>::return_t
55
Factory<v8::Context>::New( v8::ExtensionConfiguration* extensions
56
, v8::Handle<v8::ObjectTemplate> tmpl
57
, v8::Handle<v8::Value> obj) {
58
return v8::Context::New(v8::Isolate::GetCurrent(), extensions, tmpl, obj);
59
}
60
61
//=== Date =====================================================================
62
63
Factory<v8::Date>::return_t
64
Factory<v8::Date>::New(double value) {
65
return v8::Date::New(v8::Isolate::GetCurrent(), value).As<v8::Date>();
66
}
67
68
//=== External =================================================================
69
70
Factory<v8::External>::return_t
71
Factory<v8::External>::New(void * value) {
72
return v8::External::New(v8::Isolate::GetCurrent(), value);
73
}
74
75
//=== Function =================================================================
76
77
Factory<v8::Function>::return_t
78
Factory<v8::Function>::New( NanFunctionCallback callback
79
, v8::Handle<v8::Value> data) {
80
return v8::Function::New( v8::Isolate::GetCurrent()
81
, callback
82
, data);
83
}
84
85
//=== Function Template ========================================================
86
87
Factory<v8::FunctionTemplate>::return_t
88
Factory<v8::FunctionTemplate>::New( NanFunctionCallback callback
89
, v8::Handle<v8::Value> data
90
, v8::Handle<v8::Signature> signature) {
91
return v8::FunctionTemplate::New( v8::Isolate::GetCurrent()
92
, callback
93
, data
94
, signature);
95
}
96
97
//=== Number ===================================================================
98
99
Factory<v8::Number>::return_t
100
Factory<v8::Number>::New(double value) {
101
return v8::Number::New(v8::Isolate::GetCurrent(), value);
102
}
103
104
//=== Number Object ============================================================
105
106
Factory<v8::NumberObject>::return_t
107
Factory<v8::NumberObject>::New(double value) {
108
return v8::NumberObject::New( v8::Isolate::GetCurrent()
109
, value).As<v8::NumberObject>();
110
}
111
112
//=== Integer, Int32 and Uint32 ================================================
113
114
template <typename T>
115
typename IntegerFactory<T>::return_t
116
IntegerFactory<T>::New(int32_t value) {
117
return To<T>(T::New(v8::Isolate::GetCurrent(), value));
118
}
119
120
template <typename T>
121
typename IntegerFactory<T>::return_t
122
IntegerFactory<T>::New(uint32_t value) {
123
return To<T>(T::NewFromUnsigned(v8::Isolate::GetCurrent(), value));
124
}
125
126
Factory<v8::Uint32>::return_t
127
Factory<v8::Uint32>::New(int32_t value) {
128
return To<v8::Uint32>(
129
v8::Uint32::NewFromUnsigned(v8::Isolate::GetCurrent(), value));
130
}
131
132
Factory<v8::Uint32>::return_t
133
Factory<v8::Uint32>::New(uint32_t value) {
134
return To<v8::Uint32>(
135
v8::Uint32::NewFromUnsigned(v8::Isolate::GetCurrent(), value));
136
}
137
138
//=== Object ===================================================================
139
140
Factory<v8::Object>::return_t
141
Factory<v8::Object>::New() {
142
return v8::Object::New(v8::Isolate::GetCurrent());
143
}
144
145
//=== Object Template ==========================================================
146
147
Factory<v8::ObjectTemplate>::return_t
148
Factory<v8::ObjectTemplate>::New() {
149
return v8::ObjectTemplate::New(v8::Isolate::GetCurrent());
150
}
151
152
//=== RegExp ===================================================================
153
154
Factory<v8::RegExp>::return_t
155
Factory<v8::RegExp>::New(
156
v8::Handle<v8::String> pattern
157
, v8::RegExp::Flags flags) {
158
return v8::RegExp::New(pattern, flags);
159
}
160
161
//=== Script ===================================================================
162
163
Factory<v8::Script>::return_t
164
Factory<v8::Script>::New( v8::Local<v8::String> source) {
165
v8::ScriptCompiler::Source src(source);
166
return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src);
167
}
168
169
Factory<v8::Script>::return_t
170
Factory<v8::Script>::New( v8::Local<v8::String> source
171
, v8::ScriptOrigin const& origin) {
172
v8::ScriptCompiler::Source src(source, origin);
173
return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src);
174
}
175
176
//=== Signature ================================================================
177
178
Factory<v8::Signature>::return_t
179
Factory<v8::Signature>::New(Factory<v8::Signature>::FTH receiver) {
180
return v8::Signature::New(v8::Isolate::GetCurrent(), receiver);
181
}
182
183
//=== String ===================================================================
184
185
Factory<v8::String>::return_t
186
Factory<v8::String>::New() {
187
return v8::String::Empty(v8::Isolate::GetCurrent());
188
}
189
190
Factory<v8::String>::return_t
191
Factory<v8::String>::New(const char * value, int length) {
192
return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), value,
193
v8::String::kNormalString, length);
194
}
195
196
Factory<v8::String>::return_t
197
Factory<v8::String>::New(std::string const& value) {
198
assert(value.size() <= INT_MAX && "string too long");
199
return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(),
200
value.data(), v8::String::kNormalString, static_cast<int>(value.size()));
201
}
202
203
Factory<v8::String>::return_t
204
Factory<v8::String>::New(const uint8_t * value, int length) {
205
return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), value,
206
v8::String::kNormalString, length);
207
}
208
209
Factory<v8::String>::return_t
210
Factory<v8::String>::New(const uint16_t * value, int length) {
211
return v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), value,
212
v8::String::kNormalString, length);
213
}
214
215
Factory<v8::String>::return_t
216
Factory<v8::String>::New(v8::String::ExternalStringResource * value) {
217
return v8::String::NewExternal(v8::Isolate::GetCurrent(), value);
218
}
219
220
Factory<v8::String>::return_t
221
Factory<v8::String>::New(NanExternalOneByteStringResource * value) {
222
return v8::String::NewExternal(v8::Isolate::GetCurrent(), value);
223
}
224
225
//=== String Object ============================================================
226
227
Factory<v8::StringObject>::return_t
228
Factory<v8::StringObject>::New(v8::Handle<v8::String> value) {
229
return v8::StringObject::New(value).As<v8::StringObject>();
230
}
231
232
//=== Unbound Script ===========================================================
233
234
Factory<v8::UnboundScript>::return_t
235
Factory<v8::UnboundScript>::New(v8::Local<v8::String> source) {
236
v8::ScriptCompiler::Source src(source);
237
return v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src);
238
}
239
240
Factory<v8::UnboundScript>::return_t
241
Factory<v8::UnboundScript>::New( v8::Local<v8::String> source
242
, v8::ScriptOrigin const& origin) {
243
v8::ScriptCompiler::Source src(source, origin);
244
return v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src);
245
}
246
247
} // end of namespace NanIntern
248
249
//=== Presistents and Handles ==================================================
250
251
template <typename T>
252
inline v8::Local<T> NanNew(v8::Handle<T> h) {
253
return v8::Local<T>::New(v8::Isolate::GetCurrent(), h);
254
}
255
256
template <typename T>
257
inline v8::Local<T> NanNew(v8::Persistent<T> const& p) {
258
return v8::Local<T>::New(v8::Isolate::GetCurrent(), p);
259
}
260
261
#endif // NAN_IMPLEMENTATION_12_INL_H_
262
263