nan_new.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_NEW_H_
00010 #define NAN_NEW_H_
00011 
00012 namespace imp {  // scnr
00013 
00014 // TODO(agnat): Generalize
00015 template <typename T> v8::Local<T> To(v8::Local<v8::Integer> i);
00016 
00017 template <>
00018 inline
00019 v8::Local<v8::Integer>
00020 To<v8::Integer>(v8::Local<v8::Integer> i) {
00021   return Nan::To<v8::Integer>(i).ToLocalChecked();
00022 }
00023 
00024 template <>
00025 inline
00026 v8::Local<v8::Int32>
00027 To<v8::Int32>(v8::Local<v8::Integer> i) {
00028   return Nan::To<v8::Int32>(i).ToLocalChecked();
00029 }
00030 
00031 template <>
00032 inline
00033 v8::Local<v8::Uint32>
00034 To<v8::Uint32>(v8::Local<v8::Integer> i) {
00035   return Nan::To<v8::Uint32>(i).ToLocalChecked();
00036 }
00037 
00038 template <typename T> struct FactoryBase {
00039   typedef v8::Local<T> return_t;
00040 };
00041 
00042 template <typename T> struct MaybeFactoryBase {
00043   typedef MaybeLocal<T> return_t;
00044 };
00045 
00046 template <typename T> struct Factory;
00047 
00048 template <>
00049 struct Factory<v8::Array> : FactoryBase<v8::Array> {
00050   static inline return_t New();
00051   static inline return_t New(int length);
00052 };
00053 
00054 template <>
00055 struct Factory<v8::Boolean> : FactoryBase<v8::Boolean> {
00056   static inline return_t New(bool value);
00057 };
00058 
00059 template <>
00060 struct Factory<v8::BooleanObject> : FactoryBase<v8::BooleanObject> {
00061   static inline return_t New(bool value);
00062 };
00063 
00064 template <>
00065 struct Factory<v8::Context> : FactoryBase<v8::Context> {
00066   static inline
00067   return_t
00068   New( v8::ExtensionConfiguration* extensions = NULL
00069      , v8::Local<v8::ObjectTemplate> tmpl = v8::Local<v8::ObjectTemplate>()
00070      , v8::Local<v8::Value> obj = v8::Local<v8::Value>());
00071 };
00072 
00073 template <>
00074 struct Factory<v8::Date> : MaybeFactoryBase<v8::Date> {
00075   static inline return_t New(double value);
00076 };
00077 
00078 template <>
00079 struct Factory<v8::External> : FactoryBase<v8::External> {
00080   static inline return_t New(void *value);
00081 };
00082 
00083 template <>
00084 struct Factory<v8::Function> : FactoryBase<v8::Function> {
00085   static inline
00086   return_t
00087   New( FunctionCallback callback
00088      , v8::Local<v8::Value> data = v8::Local<v8::Value>());
00089 };
00090 
00091 template <>
00092 struct Factory<v8::FunctionTemplate> : FactoryBase<v8::FunctionTemplate> {
00093   static inline
00094   return_t
00095   New( FunctionCallback callback = NULL
00096      , v8::Local<v8::Value> data = v8::Local<v8::Value>()
00097      , v8::Local<v8::Signature> signature = v8::Local<v8::Signature>());
00098 };
00099 
00100 template <>
00101 struct Factory<v8::Number> : FactoryBase<v8::Number> {
00102   static inline return_t New(double value);
00103 };
00104 
00105 template <>
00106 struct Factory<v8::NumberObject> : FactoryBase<v8::NumberObject> {
00107   static inline return_t New(double value);
00108 };
00109 
00110 template <typename T>
00111 struct IntegerFactory : FactoryBase<T> {
00112   typedef typename FactoryBase<T>::return_t return_t;
00113   static inline return_t New(int32_t value);
00114   static inline return_t New(uint32_t value);
00115 };
00116 
00117 template <>
00118 struct Factory<v8::Integer> : IntegerFactory<v8::Integer> {};
00119 
00120 template <>
00121 struct Factory<v8::Int32> : IntegerFactory<v8::Int32> {};
00122 
00123 template <>
00124 struct Factory<v8::Uint32> : FactoryBase<v8::Uint32> {
00125   static inline return_t New(int32_t value);
00126   static inline return_t New(uint32_t value);
00127 };
00128 
00129 template <>
00130 struct Factory<v8::Object> : FactoryBase<v8::Object> {
00131   static inline return_t New();
00132 };
00133 
00134 template <>
00135 struct Factory<v8::ObjectTemplate> : FactoryBase<v8::ObjectTemplate> {
00136   static inline return_t New();
00137 };
00138 
00139 template <>
00140 struct Factory<v8::RegExp> : MaybeFactoryBase<v8::RegExp> {
00141   static inline return_t New(
00142       v8::Local<v8::String> pattern, v8::RegExp::Flags flags);
00143 };
00144 
00145 template <>
00146 struct Factory<v8::Script> : MaybeFactoryBase<v8::Script> {
00147   static inline return_t New( v8::Local<v8::String> source);
00148   static inline return_t New( v8::Local<v8::String> source
00149                             , v8::ScriptOrigin const& origin);
00150 };
00151 
00152 template <>
00153 struct Factory<v8::Signature> : FactoryBase<v8::Signature> {
00154   typedef v8::Local<v8::FunctionTemplate> FTH;
00155   static inline return_t New(FTH receiver = FTH());
00156 };
00157 
00158 template <>
00159 struct Factory<v8::String> : MaybeFactoryBase<v8::String> {
00160   static inline return_t New();
00161   static inline return_t New(const char *value, int length = -1);
00162   static inline return_t New(const uint16_t *value, int length = -1);
00163   static inline return_t New(std::string const& value);
00164 
00165   static inline return_t New(v8::String::ExternalStringResource * value);
00166   static inline return_t New(ExternalOneByteStringResource * value);
00167 };
00168 
00169 template <>
00170 struct Factory<v8::StringObject> : FactoryBase<v8::StringObject> {
00171   static inline return_t New(v8::Local<v8::String> value);
00172 };
00173 
00174 }  // end of namespace imp
00175 
00176 #if (NODE_MODULE_VERSION >= 12)
00177 
00178 namespace imp {
00179 
00180 template <>
00181 struct Factory<v8::UnboundScript> : MaybeFactoryBase<v8::UnboundScript> {
00182   static inline return_t New( v8::Local<v8::String> source);
00183   static inline return_t New( v8::Local<v8::String> source
00184                             , v8::ScriptOrigin const& origin);
00185 };
00186 
00187 }  // end of namespace imp
00188 
00189 # include "nan_implementation_12_inl.h"
00190 
00191 #else  // NODE_MODULE_VERSION >= 12
00192 
00193 # include "nan_implementation_pre_12_inl.h"
00194 
00195 #endif
00196 
00197 //=== API ======================================================================
00198 
00199 template <typename T>
00200 typename imp::Factory<T>::return_t
00201 New() {
00202   return imp::Factory<T>::New();
00203 }
00204 
00205 template <typename T, typename A0>
00206 typename imp::Factory<T>::return_t
00207 New(A0 arg0) {
00208   return imp::Factory<T>::New(arg0);
00209 }
00210 
00211 template <typename T, typename A0, typename A1>
00212 typename imp::Factory<T>::return_t
00213 New(A0 arg0, A1 arg1) {
00214   return imp::Factory<T>::New(arg0, arg1);
00215 }
00216 
00217 template <typename T, typename A0, typename A1, typename A2>
00218 typename imp::Factory<T>::return_t
00219 New(A0 arg0, A1 arg1, A2 arg2) {
00220   return imp::Factory<T>::New(arg0, arg1, arg2);
00221 }
00222 
00223 template <typename T, typename A0, typename A1, typename A2, typename A3>
00224 typename imp::Factory<T>::return_t
00225 New(A0 arg0, A1 arg1, A2 arg2, A3 arg3) {
00226   return imp::Factory<T>::New(arg0, arg1, arg2, arg3);
00227 }
00228 
00229 // Note(agnat): When passing overloaded function pointers to template functions
00230 // as generic arguments the compiler needs help in picking the right overload.
00231 // These two functions handle New<Function> and New<FunctionTemplate> with
00232 // all argument variations.
00233 
00234 // v8::Function and v8::FunctionTemplate with one or two arguments
00235 template <typename T>
00236 typename imp::Factory<T>::return_t
00237 New( FunctionCallback callback
00238       , v8::Local<v8::Value> data = v8::Local<v8::Value>()) {
00239     return imp::Factory<T>::New(callback, data);
00240 }
00241 
00242 // v8::Function and v8::FunctionTemplate with three arguments
00243 template <typename T, typename A2>
00244 typename imp::Factory<T>::return_t
00245 New( FunctionCallback callback
00246       , v8::Local<v8::Value> data = v8::Local<v8::Value>()
00247       , A2 a2 = A2()) {
00248     return imp::Factory<T>::New(callback, data, a2);
00249 }
00250 
00251 // Convenience
00252 
00253 #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
00254 template <typename T> inline v8::Local<T> New(v8::Handle<T> h);
00255 #endif
00256 
00257 #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION
00258 template <typename T, typename M>
00259     inline v8::Local<T> New(v8::Persistent<T, M> const& p);
00260 #else
00261 template <typename T> inline v8::Local<T> New(v8::Persistent<T> const& p);
00262 #endif
00263 template <typename T, typename M>
00264 inline v8::Local<T> New(Persistent<T, M> const& p);
00265 template <typename T>
00266 inline v8::Local<T> New(Global<T> const& p);
00267 
00268 inline
00269 imp::Factory<v8::Boolean>::return_t
00270 New(bool value) {
00271   return New<v8::Boolean>(value);
00272 }
00273 
00274 inline
00275 imp::Factory<v8::Int32>::return_t
00276 New(int32_t value) {
00277   return New<v8::Int32>(value);
00278 }
00279 
00280 inline
00281 imp::Factory<v8::Uint32>::return_t
00282 New(uint32_t value) {
00283   return New<v8::Uint32>(value);
00284 }
00285 
00286 inline
00287 imp::Factory<v8::Number>::return_t
00288 New(double value) {
00289   return New<v8::Number>(value);
00290 }
00291 
00292 inline
00293 imp::Factory<v8::String>::return_t
00294 New(std::string const& value) {  // NOLINT(build/include_what_you_use)
00295   return New<v8::String>(value);
00296 }
00297 
00298 inline
00299 imp::Factory<v8::String>::return_t
00300 New(const char * value, int length) {
00301   return New<v8::String>(value, length);
00302 }
00303 
00304 inline
00305 imp::Factory<v8::String>::return_t
00306 New(const uint16_t * value, int length) {
00307   return New<v8::String>(value, length);
00308 }
00309 
00310 inline
00311 imp::Factory<v8::String>::return_t
00312 New(const char * value) {
00313   return New<v8::String>(value);
00314 }
00315 
00316 inline
00317 imp::Factory<v8::String>::return_t
00318 New(const uint16_t * value) {
00319   return New<v8::String>(value);
00320 }
00321 
00322 inline
00323 imp::Factory<v8::String>::return_t
00324 New(v8::String::ExternalStringResource * value) {
00325   return New<v8::String>(value);
00326 }
00327 
00328 inline
00329 imp::Factory<v8::String>::return_t
00330 New(ExternalOneByteStringResource * value) {
00331   return New<v8::String>(value);
00332 }
00333 
00334 inline
00335 imp::Factory<v8::RegExp>::return_t
00336 New(v8::Local<v8::String> pattern, v8::RegExp::Flags flags) {
00337   return New<v8::RegExp>(pattern, flags);
00338 }
00339 
00340 #endif  // NAN_NEW_H_


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