nan_callbacks_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_CALLBACKS_12_INL_H_
00010 #define NAN_CALLBACKS_12_INL_H_
00011 
00012 template<typename T>
00013 class ReturnValue {
00014   v8::ReturnValue<T> value_;
00015 
00016  public:
00017   template <class S>
00018   explicit inline ReturnValue(const v8::ReturnValue<S> &value) :
00019       value_(value) {}
00020   template <class S>
00021   explicit inline ReturnValue(const ReturnValue<S>& that)
00022       : value_(that.value_) {
00023     TYPE_CHECK(T, S);
00024   }
00025 
00026   // Handle setters
00027   template <typename S> inline void Set(const v8::Local<S> &handle) {
00028     TYPE_CHECK(T, S);
00029     value_.Set(handle);
00030   }
00031 
00032   template <typename S> inline void Set(const Global<S> &handle) {
00033     TYPE_CHECK(T, S);
00034 #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 ||                      \
00035   (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) &&                       \
00036   (V8_MINOR_VERSION > 5 || (V8_MINOR_VERSION == 5 &&                           \
00037   defined(V8_BUILD_NUMBER) && V8_BUILD_NUMBER >= 8))))
00038     value_.Set(handle);
00039 #else
00040     value_.Set(*reinterpret_cast<const v8::Persistent<S>*>(&handle));
00041     const_cast<Global<S> &>(handle).Reset();
00042 #endif
00043   }
00044 
00045   // Fast primitive setters
00046   inline void Set(bool value) {
00047     TYPE_CHECK(T, v8::Boolean);
00048     value_.Set(value);
00049   }
00050 
00051   inline void Set(double i) {
00052     TYPE_CHECK(T, v8::Number);
00053     value_.Set(i);
00054   }
00055 
00056   inline void Set(int32_t i) {
00057     TYPE_CHECK(T, v8::Integer);
00058     value_.Set(i);
00059   }
00060 
00061   inline void Set(uint32_t i) {
00062     TYPE_CHECK(T, v8::Integer);
00063     value_.Set(i);
00064   }
00065 
00066   // Fast JS primitive setters
00067   inline void SetNull() {
00068     TYPE_CHECK(T, v8::Primitive);
00069     value_.SetNull();
00070   }
00071 
00072   inline void SetUndefined() {
00073     TYPE_CHECK(T, v8::Primitive);
00074     value_.SetUndefined();
00075   }
00076 
00077   inline void SetEmptyString() {
00078     TYPE_CHECK(T, v8::String);
00079     value_.SetEmptyString();
00080   }
00081 
00082   // Convenience getter for isolate
00083   inline v8::Isolate *GetIsolate() const {
00084     return value_.GetIsolate();
00085   }
00086 
00087   // Pointer setter: Uncompilable to prevent inadvertent misuse.
00088   template<typename S>
00089   inline void Set(S *whatever) { TYPE_CHECK(S*, v8::Primitive); }
00090 };
00091 
00092 template<typename T>
00093 class FunctionCallbackInfo {
00094   const v8::FunctionCallbackInfo<T> &info_;
00095   const v8::Local<v8::Value> data_;
00096 
00097  public:
00098   explicit inline FunctionCallbackInfo(
00099       const v8::FunctionCallbackInfo<T> &info
00100     , v8::Local<v8::Value> data) :
00101           info_(info)
00102         , data_(data) {}
00103 
00104   inline ReturnValue<T> GetReturnValue() const {
00105     return ReturnValue<T>(info_.GetReturnValue());
00106   }
00107 
00108   inline v8::Local<v8::Function> Callee() const { return info_.Callee(); }
00109   inline v8::Local<v8::Value> Data() const { return data_; }
00110   inline v8::Local<v8::Object> Holder() const { return info_.Holder(); }
00111   inline bool IsConstructCall() const { return info_.IsConstructCall(); }
00112   inline int Length() const { return info_.Length(); }
00113   inline v8::Local<v8::Value> operator[](int i) const { return info_[i]; }
00114   inline v8::Local<v8::Object> This() const { return info_.This(); }
00115   inline v8::Isolate *GetIsolate() const { return info_.GetIsolate(); }
00116 
00117 
00118  protected:
00119   static const int kHolderIndex = 0;
00120   static const int kIsolateIndex = 1;
00121   static const int kReturnValueDefaultValueIndex = 2;
00122   static const int kReturnValueIndex = 3;
00123   static const int kDataIndex = 4;
00124   static const int kCalleeIndex = 5;
00125   static const int kContextSaveIndex = 6;
00126   static const int kArgsLength = 7;
00127 
00128  private:
00129   NAN_DISALLOW_ASSIGN_COPY_MOVE(FunctionCallbackInfo)
00130 };
00131 
00132 template<typename T>
00133 class PropertyCallbackInfo {
00134   const v8::PropertyCallbackInfo<T> &info_;
00135   const v8::Local<v8::Value> data_;
00136 
00137  public:
00138   explicit inline PropertyCallbackInfo(
00139       const v8::PropertyCallbackInfo<T> &info
00140     , const v8::Local<v8::Value> data) :
00141           info_(info)
00142         , data_(data) {}
00143 
00144   inline v8::Isolate* GetIsolate() const { return info_.GetIsolate(); }
00145   inline v8::Local<v8::Value> Data() const { return data_; }
00146   inline v8::Local<v8::Object> This() const { return info_.This(); }
00147   inline v8::Local<v8::Object> Holder() const { return info_.Holder(); }
00148   inline ReturnValue<T> GetReturnValue() const {
00149     return ReturnValue<T>(info_.GetReturnValue());
00150   }
00151 
00152  protected:
00153   static const int kHolderIndex = 0;
00154   static const int kIsolateIndex = 1;
00155   static const int kReturnValueDefaultValueIndex = 2;
00156   static const int kReturnValueIndex = 3;
00157   static const int kDataIndex = 4;
00158   static const int kThisIndex = 5;
00159   static const int kArgsLength = 6;
00160 
00161  private:
00162   NAN_DISALLOW_ASSIGN_COPY_MOVE(PropertyCallbackInfo)
00163 };
00164 
00165 namespace imp {
00166 static
00167 void FunctionCallbackWrapper(const v8::FunctionCallbackInfo<v8::Value> &info) {
00168   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00169   FunctionCallback callback = reinterpret_cast<FunctionCallback>(
00170       reinterpret_cast<intptr_t>(
00171           obj->GetInternalField(kFunctionIndex).As<v8::External>()->Value()));
00172   FunctionCallbackInfo<v8::Value>
00173       cbinfo(info, obj->GetInternalField(kDataIndex));
00174   callback(cbinfo);
00175 }
00176 
00177 typedef void (*NativeFunction)(const v8::FunctionCallbackInfo<v8::Value> &);
00178 
00179 #if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION
00180 static
00181 void GetterCallbackWrapper(
00182     v8::Local<v8::Name> property
00183   , const v8::PropertyCallbackInfo<v8::Value> &info) {
00184   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00185   PropertyCallbackInfo<v8::Value>
00186       cbinfo(info, obj->GetInternalField(kDataIndex));
00187   GetterCallback callback = reinterpret_cast<GetterCallback>(
00188       reinterpret_cast<intptr_t>(
00189           obj->GetInternalField(kGetterIndex).As<v8::External>()->Value()));
00190   callback(property.As<v8::String>(), cbinfo);
00191 }
00192 
00193 typedef void (*NativeGetter)
00194     (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &);
00195 
00196 static
00197 void SetterCallbackWrapper(
00198     v8::Local<v8::Name> property
00199   , v8::Local<v8::Value> value
00200   , const v8::PropertyCallbackInfo<void> &info) {
00201   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00202   PropertyCallbackInfo<void>
00203       cbinfo(info, obj->GetInternalField(kDataIndex));
00204   SetterCallback callback = reinterpret_cast<SetterCallback>(
00205       reinterpret_cast<intptr_t>(
00206           obj->GetInternalField(kSetterIndex).As<v8::External>()->Value()));
00207   callback(property.As<v8::String>(), value, cbinfo);
00208 }
00209 
00210 typedef void (*NativeSetter)(
00211     v8::Local<v8::Name>
00212   , v8::Local<v8::Value>
00213   , const v8::PropertyCallbackInfo<void> &);
00214 #else
00215 static
00216 void GetterCallbackWrapper(
00217     v8::Local<v8::String> property
00218   , const v8::PropertyCallbackInfo<v8::Value> &info) {
00219   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00220   PropertyCallbackInfo<v8::Value>
00221       cbinfo(info, obj->GetInternalField(kDataIndex));
00222   GetterCallback callback = reinterpret_cast<GetterCallback>(
00223       reinterpret_cast<intptr_t>(
00224           obj->GetInternalField(kGetterIndex).As<v8::External>()->Value()));
00225   callback(property, cbinfo);
00226 }
00227 
00228 typedef void (*NativeGetter)
00229     (v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value> &);
00230 
00231 static
00232 void SetterCallbackWrapper(
00233     v8::Local<v8::String> property
00234   , v8::Local<v8::Value> value
00235   , const v8::PropertyCallbackInfo<void> &info) {
00236   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00237   PropertyCallbackInfo<void>
00238       cbinfo(info, obj->GetInternalField(kDataIndex));
00239   SetterCallback callback = reinterpret_cast<SetterCallback>(
00240       reinterpret_cast<intptr_t>(
00241           obj->GetInternalField(kSetterIndex).As<v8::External>()->Value()));
00242   callback(property, value, cbinfo);
00243 }
00244 
00245 typedef void (*NativeSetter)(
00246     v8::Local<v8::String>
00247   , v8::Local<v8::Value>
00248   , const v8::PropertyCallbackInfo<void> &);
00249 #endif
00250 
00251 #if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION
00252 static
00253 void PropertyGetterCallbackWrapper(
00254     v8::Local<v8::Name> property
00255   , const v8::PropertyCallbackInfo<v8::Value> &info) {
00256   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00257   PropertyCallbackInfo<v8::Value>
00258       cbinfo(info, obj->GetInternalField(kDataIndex));
00259   PropertyGetterCallback callback = reinterpret_cast<PropertyGetterCallback>(
00260       reinterpret_cast<intptr_t>(
00261           obj->GetInternalField(kPropertyGetterIndex)
00262               .As<v8::External>()->Value()));
00263   callback(property.As<v8::String>(), cbinfo);
00264 }
00265 
00266 typedef void (*NativePropertyGetter)
00267     (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &);
00268 
00269 static
00270 void PropertySetterCallbackWrapper(
00271     v8::Local<v8::Name> property
00272   , v8::Local<v8::Value> value
00273   , const v8::PropertyCallbackInfo<v8::Value> &info) {
00274   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00275   PropertyCallbackInfo<v8::Value>
00276       cbinfo(info, obj->GetInternalField(kDataIndex));
00277   PropertySetterCallback callback = reinterpret_cast<PropertySetterCallback>(
00278       reinterpret_cast<intptr_t>(
00279           obj->GetInternalField(kPropertySetterIndex)
00280               .As<v8::External>()->Value()));
00281   callback(property.As<v8::String>(), value, cbinfo);
00282 }
00283 
00284 typedef void (*NativePropertySetter)(
00285     v8::Local<v8::Name>
00286   , v8::Local<v8::Value>
00287   , const v8::PropertyCallbackInfo<v8::Value> &);
00288 
00289 static
00290 void PropertyEnumeratorCallbackWrapper(
00291     const v8::PropertyCallbackInfo<v8::Array> &info) {
00292   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00293   PropertyCallbackInfo<v8::Array>
00294       cbinfo(info, obj->GetInternalField(kDataIndex));
00295   PropertyEnumeratorCallback callback =
00296       reinterpret_cast<PropertyEnumeratorCallback>(reinterpret_cast<intptr_t>(
00297           obj->GetInternalField(kPropertyEnumeratorIndex)
00298               .As<v8::External>()->Value()));
00299   callback(cbinfo);
00300 }
00301 
00302 typedef void (*NativePropertyEnumerator)
00303     (const v8::PropertyCallbackInfo<v8::Array> &);
00304 
00305 static
00306 void PropertyDeleterCallbackWrapper(
00307     v8::Local<v8::Name> property
00308   , const v8::PropertyCallbackInfo<v8::Boolean> &info) {
00309   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00310   PropertyCallbackInfo<v8::Boolean>
00311       cbinfo(info, obj->GetInternalField(kDataIndex));
00312   PropertyDeleterCallback callback = reinterpret_cast<PropertyDeleterCallback>(
00313       reinterpret_cast<intptr_t>(
00314           obj->GetInternalField(kPropertyDeleterIndex)
00315               .As<v8::External>()->Value()));
00316   callback(property.As<v8::String>(), cbinfo);
00317 }
00318 
00319 typedef void (NativePropertyDeleter)
00320     (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Boolean> &);
00321 
00322 static
00323 void PropertyQueryCallbackWrapper(
00324     v8::Local<v8::Name> property
00325   , const v8::PropertyCallbackInfo<v8::Integer> &info) {
00326   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00327   PropertyCallbackInfo<v8::Integer>
00328       cbinfo(info, obj->GetInternalField(kDataIndex));
00329   PropertyQueryCallback callback = reinterpret_cast<PropertyQueryCallback>(
00330       reinterpret_cast<intptr_t>(
00331           obj->GetInternalField(kPropertyQueryIndex)
00332               .As<v8::External>()->Value()));
00333   callback(property.As<v8::String>(), cbinfo);
00334 }
00335 
00336 typedef void (*NativePropertyQuery)
00337     (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Integer> &);
00338 #else
00339 static
00340 void PropertyGetterCallbackWrapper(
00341     v8::Local<v8::String> property
00342   , const v8::PropertyCallbackInfo<v8::Value> &info) {
00343   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00344   PropertyCallbackInfo<v8::Value>
00345       cbinfo(info, obj->GetInternalField(kDataIndex));
00346   PropertyGetterCallback callback = reinterpret_cast<PropertyGetterCallback>(
00347       reinterpret_cast<intptr_t>(
00348           obj->GetInternalField(kPropertyGetterIndex)
00349               .As<v8::External>()->Value()));
00350   callback(property, cbinfo);
00351 }
00352 
00353 typedef void (*NativePropertyGetter)
00354     (v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value> &);
00355 
00356 static
00357 void PropertySetterCallbackWrapper(
00358     v8::Local<v8::String> property
00359   , v8::Local<v8::Value> value
00360   , const v8::PropertyCallbackInfo<v8::Value> &info) {
00361   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00362   PropertyCallbackInfo<v8::Value>
00363       cbinfo(info, obj->GetInternalField(kDataIndex));
00364   PropertySetterCallback callback = reinterpret_cast<PropertySetterCallback>(
00365       reinterpret_cast<intptr_t>(
00366           obj->GetInternalField(kPropertySetterIndex)
00367               .As<v8::External>()->Value()));
00368   callback(property, value, cbinfo);
00369 }
00370 
00371 typedef void (*NativePropertySetter)(
00372     v8::Local<v8::String>
00373   , v8::Local<v8::Value>
00374   , const v8::PropertyCallbackInfo<v8::Value> &);
00375 
00376 static
00377 void PropertyEnumeratorCallbackWrapper(
00378     const v8::PropertyCallbackInfo<v8::Array> &info) {
00379   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00380   PropertyCallbackInfo<v8::Array>
00381       cbinfo(info, obj->GetInternalField(kDataIndex));
00382   PropertyEnumeratorCallback callback =
00383       reinterpret_cast<PropertyEnumeratorCallback>(reinterpret_cast<intptr_t>(
00384           obj->GetInternalField(kPropertyEnumeratorIndex)
00385               .As<v8::External>()->Value()));
00386   callback(cbinfo);
00387 }
00388 
00389 typedef void (*NativePropertyEnumerator)
00390     (const v8::PropertyCallbackInfo<v8::Array> &);
00391 
00392 static
00393 void PropertyDeleterCallbackWrapper(
00394     v8::Local<v8::String> property
00395   , const v8::PropertyCallbackInfo<v8::Boolean> &info) {
00396   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00397   PropertyCallbackInfo<v8::Boolean>
00398       cbinfo(info, obj->GetInternalField(kDataIndex));
00399   PropertyDeleterCallback callback = reinterpret_cast<PropertyDeleterCallback>(
00400       reinterpret_cast<intptr_t>(
00401           obj->GetInternalField(kPropertyDeleterIndex)
00402               .As<v8::External>()->Value()));
00403   callback(property, cbinfo);
00404 }
00405 
00406 typedef void (NativePropertyDeleter)
00407     (v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Boolean> &);
00408 
00409 static
00410 void PropertyQueryCallbackWrapper(
00411     v8::Local<v8::String> property
00412   , const v8::PropertyCallbackInfo<v8::Integer> &info) {
00413   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00414   PropertyCallbackInfo<v8::Integer>
00415       cbinfo(info, obj->GetInternalField(kDataIndex));
00416   PropertyQueryCallback callback = reinterpret_cast<PropertyQueryCallback>(
00417       reinterpret_cast<intptr_t>(
00418           obj->GetInternalField(kPropertyQueryIndex)
00419               .As<v8::External>()->Value()));
00420   callback(property, cbinfo);
00421 }
00422 
00423 typedef void (*NativePropertyQuery)
00424     (v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Integer> &);
00425 #endif
00426 
00427 static
00428 void IndexGetterCallbackWrapper(
00429     uint32_t index, const v8::PropertyCallbackInfo<v8::Value> &info) {
00430   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00431   PropertyCallbackInfo<v8::Value>
00432       cbinfo(info, obj->GetInternalField(kDataIndex));
00433   IndexGetterCallback callback = reinterpret_cast<IndexGetterCallback>(
00434       reinterpret_cast<intptr_t>(
00435           obj->GetInternalField(kIndexPropertyGetterIndex)
00436               .As<v8::External>()->Value()));
00437   callback(index, cbinfo);
00438 }
00439 
00440 typedef void (*NativeIndexGetter)
00441     (uint32_t, const v8::PropertyCallbackInfo<v8::Value> &);
00442 
00443 static
00444 void IndexSetterCallbackWrapper(
00445     uint32_t index
00446   , v8::Local<v8::Value> value
00447   , const v8::PropertyCallbackInfo<v8::Value> &info) {
00448   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00449   PropertyCallbackInfo<v8::Value>
00450       cbinfo(info, obj->GetInternalField(kDataIndex));
00451   IndexSetterCallback callback = reinterpret_cast<IndexSetterCallback>(
00452       reinterpret_cast<intptr_t>(
00453           obj->GetInternalField(kIndexPropertySetterIndex)
00454               .As<v8::External>()->Value()));
00455   callback(index, value, cbinfo);
00456 }
00457 
00458 typedef void (*NativeIndexSetter)(
00459     uint32_t
00460   , v8::Local<v8::Value>
00461   , const v8::PropertyCallbackInfo<v8::Value> &);
00462 
00463 static
00464 void IndexEnumeratorCallbackWrapper(
00465     const v8::PropertyCallbackInfo<v8::Array> &info) {
00466   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00467   PropertyCallbackInfo<v8::Array>
00468       cbinfo(info, obj->GetInternalField(kDataIndex));
00469   IndexEnumeratorCallback callback = reinterpret_cast<IndexEnumeratorCallback>(
00470       reinterpret_cast<intptr_t>(
00471           obj->GetInternalField(
00472               kIndexPropertyEnumeratorIndex).As<v8::External>()->Value()));
00473   callback(cbinfo);
00474 }
00475 
00476 typedef void (*NativeIndexEnumerator)
00477     (const v8::PropertyCallbackInfo<v8::Array> &);
00478 
00479 static
00480 void IndexDeleterCallbackWrapper(
00481     uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean> &info) {
00482   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00483   PropertyCallbackInfo<v8::Boolean>
00484       cbinfo(info, obj->GetInternalField(kDataIndex));
00485   IndexDeleterCallback callback = reinterpret_cast<IndexDeleterCallback>(
00486       reinterpret_cast<intptr_t>(
00487           obj->GetInternalField(kIndexPropertyDeleterIndex)
00488               .As<v8::External>()->Value()));
00489   callback(index, cbinfo);
00490 }
00491 
00492 typedef void (*NativeIndexDeleter)
00493     (uint32_t, const v8::PropertyCallbackInfo<v8::Boolean> &);
00494 
00495 static
00496 void IndexQueryCallbackWrapper(
00497     uint32_t index, const v8::PropertyCallbackInfo<v8::Integer> &info) {
00498   v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
00499   PropertyCallbackInfo<v8::Integer>
00500       cbinfo(info, obj->GetInternalField(kDataIndex));
00501   IndexQueryCallback callback = reinterpret_cast<IndexQueryCallback>(
00502       reinterpret_cast<intptr_t>(
00503           obj->GetInternalField(kIndexPropertyQueryIndex)
00504               .As<v8::External>()->Value()));
00505   callback(index, cbinfo);
00506 }
00507 
00508 typedef void (*NativeIndexQuery)
00509     (uint32_t, const v8::PropertyCallbackInfo<v8::Integer> &);
00510 }  // end of namespace imp
00511 
00512 #endif  // NAN_CALLBACKS_12_INL_H_


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