nan_implementation_12_inl.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * NAN - Native Abstractions for Node.js
00003  *
00004  * Copyright (c) 2016 NAN contributors
00005  *
00006  * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
00007  ********************************************************************/
00008 
00009 #ifndef NAN_IMPLEMENTATION_12_INL_H_
00010 #define NAN_IMPLEMENTATION_12_INL_H_
00011 //==============================================================================
00012 // node v0.11 implementation
00013 //==============================================================================
00014 
00015 namespace imp {
00016 
00017 //=== Array ====================================================================
00018 
00019 Factory<v8::Array>::return_t
00020 Factory<v8::Array>::New() {
00021   return v8::Array::New(v8::Isolate::GetCurrent());
00022 }
00023 
00024 Factory<v8::Array>::return_t
00025 Factory<v8::Array>::New(int length) {
00026   return v8::Array::New(v8::Isolate::GetCurrent(), length);
00027 }
00028 
00029 //=== Boolean ==================================================================
00030 
00031 Factory<v8::Boolean>::return_t
00032 Factory<v8::Boolean>::New(bool value) {
00033   return v8::Boolean::New(v8::Isolate::GetCurrent(), value);
00034 }
00035 
00036 //=== Boolean Object ===========================================================
00037 
00038 Factory<v8::BooleanObject>::return_t
00039 Factory<v8::BooleanObject>::New(bool value) {
00040 #if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION)
00041   return v8::BooleanObject::New(
00042     v8::Isolate::GetCurrent(), value).As<v8::BooleanObject>();
00043 #else
00044   return v8::BooleanObject::New(value).As<v8::BooleanObject>();
00045 #endif
00046 }
00047 
00048 //=== Context ==================================================================
00049 
00050 Factory<v8::Context>::return_t
00051 Factory<v8::Context>::New( v8::ExtensionConfiguration* extensions
00052                          , v8::Local<v8::ObjectTemplate> tmpl
00053                          , v8::Local<v8::Value> obj) {
00054   return v8::Context::New(v8::Isolate::GetCurrent(), extensions, tmpl, obj);
00055 }
00056 
00057 //=== Date =====================================================================
00058 
00059 #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 ||                      \
00060   (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
00061 Factory<v8::Date>::return_t
00062 Factory<v8::Date>::New(double value) {
00063   v8::Local<v8::Date> ret;
00064   if (v8::Date::New(GetCurrentContext(), value).
00065       ToLocal(reinterpret_cast<v8::Local<v8::Value>*>(&ret))) {
00066     return v8::MaybeLocal<v8::Date>(ret);
00067   } else {
00068     return v8::MaybeLocal<v8::Date>(ret);
00069   }
00070 }
00071 #else
00072 Factory<v8::Date>::return_t
00073 Factory<v8::Date>::New(double value) {
00074   return Factory<v8::Date>::return_t(
00075       v8::Date::New(v8::Isolate::GetCurrent(), value).As<v8::Date>());
00076 }
00077 #endif
00078 
00079 //=== External =================================================================
00080 
00081 Factory<v8::External>::return_t
00082 Factory<v8::External>::New(void * value) {
00083   return v8::External::New(v8::Isolate::GetCurrent(), value);
00084 }
00085 
00086 //=== Function =================================================================
00087 
00088 Factory<v8::Function>::return_t
00089 Factory<v8::Function>::New( FunctionCallback callback
00090                           , v8::Local<v8::Value> data) {
00091   v8::Isolate *isolate = v8::Isolate::GetCurrent();
00092   v8::EscapableHandleScope scope(isolate);
00093   v8::Local<v8::ObjectTemplate> tpl = v8::ObjectTemplate::New(isolate);
00094   tpl->SetInternalFieldCount(imp::kFunctionFieldCount);
00095   v8::Local<v8::Object> obj = NewInstance(tpl).ToLocalChecked();
00096 
00097   obj->SetInternalField(
00098       imp::kFunctionIndex
00099     , v8::External::New(isolate, reinterpret_cast<void *>(callback)));
00100 
00101   v8::Local<v8::Value> val = v8::Local<v8::Value>::New(isolate, data);
00102 
00103   if (!val.IsEmpty()) {
00104     obj->SetInternalField(imp::kDataIndex, val);
00105   }
00106 
00107   return scope.Escape(v8::Function::New( isolate
00108                           , imp::FunctionCallbackWrapper
00109                           , obj));
00110 }
00111 
00112 //=== Function Template ========================================================
00113 
00114 Factory<v8::FunctionTemplate>::return_t
00115 Factory<v8::FunctionTemplate>::New( FunctionCallback callback
00116                                   , v8::Local<v8::Value> data
00117                                   , v8::Local<v8::Signature> signature) {
00118   v8::Isolate *isolate = v8::Isolate::GetCurrent();
00119   if (callback) {
00120     v8::EscapableHandleScope scope(isolate);
00121     v8::Local<v8::ObjectTemplate> tpl = v8::ObjectTemplate::New(isolate);
00122     tpl->SetInternalFieldCount(imp::kFunctionFieldCount);
00123     v8::Local<v8::Object> obj = NewInstance(tpl).ToLocalChecked();
00124 
00125     obj->SetInternalField(
00126         imp::kFunctionIndex
00127       , v8::External::New(isolate, reinterpret_cast<void *>(callback)));
00128     v8::Local<v8::Value> val = v8::Local<v8::Value>::New(isolate, data);
00129 
00130     if (!val.IsEmpty()) {
00131       obj->SetInternalField(imp::kDataIndex, val);
00132     }
00133 
00134     return scope.Escape(v8::FunctionTemplate::New( isolate
00135                                     , imp::FunctionCallbackWrapper
00136                                     , obj
00137                                     , signature));
00138   } else {
00139     return v8::FunctionTemplate::New(isolate, 0, data, signature);
00140   }
00141 }
00142 
00143 //=== Number ===================================================================
00144 
00145 Factory<v8::Number>::return_t
00146 Factory<v8::Number>::New(double value) {
00147   return v8::Number::New(v8::Isolate::GetCurrent(), value);
00148 }
00149 
00150 //=== Number Object ============================================================
00151 
00152 Factory<v8::NumberObject>::return_t
00153 Factory<v8::NumberObject>::New(double value) {
00154   return v8::NumberObject::New( v8::Isolate::GetCurrent()
00155                               , value).As<v8::NumberObject>();
00156 }
00157 
00158 //=== Integer, Int32 and Uint32 ================================================
00159 
00160 template <typename T>
00161 typename IntegerFactory<T>::return_t
00162 IntegerFactory<T>::New(int32_t value) {
00163   return To<T>(T::New(v8::Isolate::GetCurrent(), value));
00164 }
00165 
00166 template <typename T>
00167 typename IntegerFactory<T>::return_t
00168 IntegerFactory<T>::New(uint32_t value) {
00169   return To<T>(T::NewFromUnsigned(v8::Isolate::GetCurrent(), value));
00170 }
00171 
00172 Factory<v8::Uint32>::return_t
00173 Factory<v8::Uint32>::New(int32_t value) {
00174   return To<v8::Uint32>(
00175       v8::Uint32::NewFromUnsigned(v8::Isolate::GetCurrent(), value));
00176 }
00177 
00178 Factory<v8::Uint32>::return_t
00179 Factory<v8::Uint32>::New(uint32_t value) {
00180   return To<v8::Uint32>(
00181       v8::Uint32::NewFromUnsigned(v8::Isolate::GetCurrent(), value));
00182 }
00183 
00184 //=== Object ===================================================================
00185 
00186 Factory<v8::Object>::return_t
00187 Factory<v8::Object>::New() {
00188   return v8::Object::New(v8::Isolate::GetCurrent());
00189 }
00190 
00191 //=== Object Template ==========================================================
00192 
00193 Factory<v8::ObjectTemplate>::return_t
00194 Factory<v8::ObjectTemplate>::New() {
00195   return v8::ObjectTemplate::New(v8::Isolate::GetCurrent());
00196 }
00197 
00198 //=== RegExp ===================================================================
00199 
00200 #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 ||                      \
00201   (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
00202 Factory<v8::RegExp>::return_t
00203 Factory<v8::RegExp>::New(
00204     v8::Local<v8::String> pattern
00205   , v8::RegExp::Flags flags) {
00206   return v8::RegExp::New(GetCurrentContext(), pattern, flags);
00207 }
00208 #else
00209 Factory<v8::RegExp>::return_t
00210 Factory<v8::RegExp>::New(
00211     v8::Local<v8::String> pattern
00212   , v8::RegExp::Flags flags) {
00213   return Factory<v8::RegExp>::return_t(v8::RegExp::New(pattern, flags));
00214 }
00215 #endif
00216 
00217 //=== Script ===================================================================
00218 
00219 #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 ||                      \
00220   (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
00221 Factory<v8::Script>::return_t
00222 Factory<v8::Script>::New( v8::Local<v8::String> source) {
00223   v8::ScriptCompiler::Source src(source);
00224   return v8::ScriptCompiler::Compile(GetCurrentContext(), &src);
00225 }
00226 
00227 Factory<v8::Script>::return_t
00228 Factory<v8::Script>::New( v8::Local<v8::String> source
00229                         , v8::ScriptOrigin const& origin) {
00230   v8::ScriptCompiler::Source src(source, origin);
00231   return v8::ScriptCompiler::Compile(GetCurrentContext(), &src);
00232 }
00233 #else
00234 Factory<v8::Script>::return_t
00235 Factory<v8::Script>::New( v8::Local<v8::String> source) {
00236   v8::ScriptCompiler::Source src(source);
00237   return Factory<v8::Script>::return_t(
00238       v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src));
00239 }
00240 
00241 Factory<v8::Script>::return_t
00242 Factory<v8::Script>::New( v8::Local<v8::String> source
00243                         , v8::ScriptOrigin const& origin) {
00244   v8::ScriptCompiler::Source src(source, origin);
00245   return Factory<v8::Script>::return_t(
00246       v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src));
00247 }
00248 #endif
00249 
00250 //=== Signature ================================================================
00251 
00252 Factory<v8::Signature>::return_t
00253 Factory<v8::Signature>::New(Factory<v8::Signature>::FTH receiver) {
00254   return v8::Signature::New(v8::Isolate::GetCurrent(), receiver);
00255 }
00256 
00257 //=== String ===================================================================
00258 
00259 Factory<v8::String>::return_t
00260 Factory<v8::String>::New() {
00261   return Factory<v8::String>::return_t(
00262       v8::String::Empty(v8::Isolate::GetCurrent()));
00263 }
00264 
00265 #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 ||                      \
00266   (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
00267 Factory<v8::String>::return_t
00268 Factory<v8::String>::New(const char * value, int length) {
00269   return v8::String::NewFromUtf8(
00270       v8::Isolate::GetCurrent(), value, v8::NewStringType::kNormal, length);
00271 }
00272 
00273 Factory<v8::String>::return_t
00274 Factory<v8::String>::New(std::string const& value) {
00275   assert(value.size() <= INT_MAX && "string too long");
00276   return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(),
00277       value.data(), v8::NewStringType::kNormal, static_cast<int>(value.size()));
00278 }
00279 
00280 Factory<v8::String>::return_t
00281 Factory<v8::String>::New(const uint16_t * value, int length) {
00282   return v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), value,
00283         v8::NewStringType::kNormal, length);
00284 }
00285 
00286 Factory<v8::String>::return_t
00287 Factory<v8::String>::New(v8::String::ExternalStringResource * value) {
00288   return v8::String::NewExternalTwoByte(v8::Isolate::GetCurrent(), value);
00289 }
00290 
00291 Factory<v8::String>::return_t
00292 Factory<v8::String>::New(ExternalOneByteStringResource * value) {
00293   return v8::String::NewExternalOneByte(v8::Isolate::GetCurrent(), value);
00294 }
00295 #else
00296 Factory<v8::String>::return_t
00297 Factory<v8::String>::New(const char * value, int length) {
00298   return Factory<v8::String>::return_t(
00299       v8::String::NewFromUtf8(
00300           v8::Isolate::GetCurrent()
00301         , value
00302         , v8::String::kNormalString
00303         , length));
00304 }
00305 
00306 Factory<v8::String>::return_t
00307 Factory<v8::String>::New(
00308     std::string const& value) /* NOLINT(build/include_what_you_use) */ {
00309   assert(value.size() <= INT_MAX && "string too long");
00310   return Factory<v8::String>::return_t(
00311       v8::String::NewFromUtf8(
00312           v8::Isolate::GetCurrent()
00313         , value.data()
00314         , v8::String::kNormalString
00315         , static_cast<int>(value.size())));
00316 }
00317 
00318 Factory<v8::String>::return_t
00319 Factory<v8::String>::New(const uint16_t * value, int length) {
00320   return Factory<v8::String>::return_t(
00321       v8::String::NewFromTwoByte(
00322           v8::Isolate::GetCurrent()
00323         , value
00324         , v8::String::kNormalString
00325         , length));
00326 }
00327 
00328 Factory<v8::String>::return_t
00329 Factory<v8::String>::New(v8::String::ExternalStringResource * value) {
00330   return Factory<v8::String>::return_t(
00331       v8::String::NewExternal(v8::Isolate::GetCurrent(), value));
00332 }
00333 
00334 Factory<v8::String>::return_t
00335 Factory<v8::String>::New(ExternalOneByteStringResource * value) {
00336   return Factory<v8::String>::return_t(
00337       v8::String::NewExternal(v8::Isolate::GetCurrent(), value));
00338 }
00339 #endif
00340 
00341 //=== String Object ============================================================
00342 
00343 Factory<v8::StringObject>::return_t
00344 Factory<v8::StringObject>::New(v8::Local<v8::String> value) {
00345   return v8::StringObject::New(value).As<v8::StringObject>();
00346 }
00347 
00348 //=== Unbound Script ===========================================================
00349 
00350 #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 ||                      \
00351   (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
00352 Factory<v8::UnboundScript>::return_t
00353 Factory<v8::UnboundScript>::New(v8::Local<v8::String> source) {
00354   v8::ScriptCompiler::Source src(source);
00355   return v8::ScriptCompiler::CompileUnboundScript(
00356       v8::Isolate::GetCurrent(), &src);
00357 }
00358 
00359 Factory<v8::UnboundScript>::return_t
00360 Factory<v8::UnboundScript>::New( v8::Local<v8::String> source
00361                                , v8::ScriptOrigin const& origin) {
00362   v8::ScriptCompiler::Source src(source, origin);
00363   return v8::ScriptCompiler::CompileUnboundScript(
00364       v8::Isolate::GetCurrent(), &src);
00365 }
00366 #else
00367 Factory<v8::UnboundScript>::return_t
00368 Factory<v8::UnboundScript>::New(v8::Local<v8::String> source) {
00369   v8::ScriptCompiler::Source src(source);
00370   return Factory<v8::UnboundScript>::return_t(
00371       v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src));
00372 }
00373 
00374 Factory<v8::UnboundScript>::return_t
00375 Factory<v8::UnboundScript>::New( v8::Local<v8::String> source
00376                                , v8::ScriptOrigin const& origin) {
00377   v8::ScriptCompiler::Source src(source, origin);
00378   return Factory<v8::UnboundScript>::return_t(
00379       v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src));
00380 }
00381 #endif
00382 
00383 }  // end of namespace imp
00384 
00385 //=== Presistents and Handles ==================================================
00386 
00387 #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
00388 template <typename T>
00389 inline v8::Local<T> New(v8::Handle<T> h) {
00390   return v8::Local<T>::New(v8::Isolate::GetCurrent(), h);
00391 }
00392 #endif
00393 
00394 template <typename T, typename M>
00395 inline v8::Local<T> New(v8::Persistent<T, M> const& p) {
00396   return v8::Local<T>::New(v8::Isolate::GetCurrent(), p);
00397 }
00398 
00399 template <typename T, typename M>
00400 inline v8::Local<T> New(Persistent<T, M> const& p) {
00401   return v8::Local<T>::New(v8::Isolate::GetCurrent(), p);
00402 }
00403 
00404 template <typename T>
00405 inline v8::Local<T> New(Global<T> const& p) {
00406   return v8::Local<T>::New(v8::Isolate::GetCurrent(), p);
00407 }
00408 
00409 #endif  // NAN_IMPLEMENTATION_12_INL_H_


dji_ronin
Author(s):
autogenerated on Sat Jun 8 2019 20:15:31