nan_callbacks_12_inl.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*********************************************************************
  2. * NAN - Native Abstractions for Node.js
  3. *
  4. * Copyright (c) 2018 NAN contributors
  5. *
  6. * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
  7. ********************************************************************/
  8. #ifndef NAN_CALLBACKS_12_INL_H_
  9. #define NAN_CALLBACKS_12_INL_H_
  10. template<typename T>
  11. class ReturnValue {
  12. v8::ReturnValue<T> value_;
  13. public:
  14. template <class S>
  15. explicit inline ReturnValue(const v8::ReturnValue<S> &value) :
  16. value_(value) {}
  17. template <class S>
  18. explicit inline ReturnValue(const ReturnValue<S>& that)
  19. : value_(that.value_) {
  20. TYPE_CHECK(T, S);
  21. }
  22. // Handle setters
  23. template <typename S> inline void Set(const v8::Local<S> &handle) {
  24. TYPE_CHECK(T, S);
  25. value_.Set(handle);
  26. }
  27. template <typename S> inline void Set(const Global<S> &handle) {
  28. TYPE_CHECK(T, S);
  29. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \
  30. (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \
  31. (V8_MINOR_VERSION > 5 || (V8_MINOR_VERSION == 5 && \
  32. defined(V8_BUILD_NUMBER) && V8_BUILD_NUMBER >= 8))))
  33. value_.Set(handle);
  34. #else
  35. value_.Set(*reinterpret_cast<const v8::Persistent<S>*>(&handle));
  36. const_cast<Global<S> &>(handle).Reset();
  37. #endif
  38. }
  39. // Fast primitive setters
  40. inline void Set(bool value) {
  41. TYPE_CHECK(T, v8::Boolean);
  42. value_.Set(value);
  43. }
  44. inline void Set(double i) {
  45. TYPE_CHECK(T, v8::Number);
  46. value_.Set(i);
  47. }
  48. inline void Set(int32_t i) {
  49. TYPE_CHECK(T, v8::Integer);
  50. value_.Set(i);
  51. }
  52. inline void Set(uint32_t i) {
  53. TYPE_CHECK(T, v8::Integer);
  54. value_.Set(i);
  55. }
  56. // Fast JS primitive setters
  57. inline void SetNull() {
  58. TYPE_CHECK(T, v8::Primitive);
  59. value_.SetNull();
  60. }
  61. inline void SetUndefined() {
  62. TYPE_CHECK(T, v8::Primitive);
  63. value_.SetUndefined();
  64. }
  65. inline void SetEmptyString() {
  66. TYPE_CHECK(T, v8::String);
  67. value_.SetEmptyString();
  68. }
  69. // Convenience getter for isolate
  70. inline v8::Isolate *GetIsolate() const {
  71. return value_.GetIsolate();
  72. }
  73. // Pointer setter: Uncompilable to prevent inadvertent misuse.
  74. template<typename S>
  75. inline void Set(S *whatever) { TYPE_CHECK(S*, v8::Primitive); }
  76. };
  77. template<typename T>
  78. class FunctionCallbackInfo {
  79. const v8::FunctionCallbackInfo<T> &info_;
  80. const v8::Local<v8::Value> data_;
  81. public:
  82. explicit inline FunctionCallbackInfo(
  83. const v8::FunctionCallbackInfo<T> &info
  84. , v8::Local<v8::Value> data) :
  85. info_(info)
  86. , data_(data) {}
  87. inline ReturnValue<T> GetReturnValue() const {
  88. return ReturnValue<T>(info_.GetReturnValue());
  89. }
  90. #if NODE_MAJOR_VERSION < 10
  91. NAN_DEPRECATED inline v8::Local<v8::Function> Callee() const {
  92. return info_.Callee();
  93. }
  94. #endif
  95. inline v8::Local<v8::Value> Data() const { return data_; }
  96. inline v8::Local<v8::Object> Holder() const {
  97. #if defined(V8_MAJOR_VERSION) && \
  98. (V8_MAJOR_VERSION > 12 || \
  99. (V8_MAJOR_VERSION == 12 && \
  100. (defined(V8_MINOR_VERSION) && \
  101. (V8_MINOR_VERSION > 5 || \
  102. (V8_MINOR_VERSION == 5 && defined(V8_BUILD_NUMBER) && \
  103. V8_BUILD_NUMBER >= 214)))))
  104. return info_.This();
  105. #else
  106. return info_.Holder();
  107. #endif
  108. }
  109. inline bool IsConstructCall() const { return info_.IsConstructCall(); }
  110. inline int Length() const { return info_.Length(); }
  111. inline v8::Local<v8::Value> operator[](int i) const { return info_[i]; }
  112. inline v8::Local<v8::Object> This() const { return info_.This(); }
  113. inline v8::Isolate *GetIsolate() const { return info_.GetIsolate(); }
  114. protected:
  115. static const int kHolderIndex = 0;
  116. static const int kIsolateIndex = 1;
  117. static const int kReturnValueDefaultValueIndex = 2;
  118. static const int kReturnValueIndex = 3;
  119. static const int kDataIndex = 4;
  120. static const int kCalleeIndex = 5;
  121. static const int kContextSaveIndex = 6;
  122. static const int kArgsLength = 7;
  123. private:
  124. NAN_DISALLOW_ASSIGN_COPY_MOVE(FunctionCallbackInfo)
  125. };
  126. template<typename T>
  127. class PropertyCallbackInfo {
  128. const v8::PropertyCallbackInfo<T> &info_;
  129. const v8::Local<v8::Value> data_;
  130. public:
  131. explicit inline PropertyCallbackInfo(
  132. const v8::PropertyCallbackInfo<T> &info
  133. , const v8::Local<v8::Value> data) :
  134. info_(info)
  135. , data_(data) {}
  136. inline v8::Isolate* GetIsolate() const { return info_.GetIsolate(); }
  137. inline v8::Local<v8::Value> Data() const { return data_; }
  138. inline v8::Local<v8::Object> This() const { return info_.This(); }
  139. inline v8::Local<v8::Object> Holder() const { return info_.Holder(); }
  140. inline ReturnValue<T> GetReturnValue() const {
  141. return ReturnValue<T>(info_.GetReturnValue());
  142. }
  143. protected:
  144. static const int kHolderIndex = 0;
  145. static const int kIsolateIndex = 1;
  146. static const int kReturnValueDefaultValueIndex = 2;
  147. static const int kReturnValueIndex = 3;
  148. static const int kDataIndex = 4;
  149. static const int kThisIndex = 5;
  150. static const int kArgsLength = 6;
  151. private:
  152. NAN_DISALLOW_ASSIGN_COPY_MOVE(PropertyCallbackInfo)
  153. };
  154. namespace imp {
  155. static
  156. void FunctionCallbackWrapper(const v8::FunctionCallbackInfo<v8::Value> &info) {
  157. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  158. FunctionCallback callback = reinterpret_cast<FunctionCallback>(
  159. reinterpret_cast<intptr_t>(
  160. obj->GetInternalField(kFunctionIndex)
  161. .As<v8::Value>().As<v8::External>()->Value()));
  162. FunctionCallbackInfo<v8::Value>
  163. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  164. callback(cbinfo);
  165. }
  166. typedef void (*NativeFunction)(const v8::FunctionCallbackInfo<v8::Value> &);
  167. #if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION
  168. static
  169. void GetterCallbackWrapper(
  170. v8::Local<v8::Name> property
  171. , const v8::PropertyCallbackInfo<v8::Value> &info) {
  172. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  173. PropertyCallbackInfo<v8::Value>
  174. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  175. GetterCallback callback = reinterpret_cast<GetterCallback>(
  176. reinterpret_cast<intptr_t>(
  177. obj->GetInternalField(kGetterIndex)
  178. .As<v8::Value>().As<v8::External>()->Value()));
  179. callback(property.As<v8::String>(), cbinfo);
  180. }
  181. typedef void (*NativeGetter)
  182. (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &);
  183. static
  184. void SetterCallbackWrapper(
  185. v8::Local<v8::Name> property
  186. , v8::Local<v8::Value> value
  187. , const v8::PropertyCallbackInfo<void> &info) {
  188. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  189. PropertyCallbackInfo<void>
  190. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  191. SetterCallback callback = reinterpret_cast<SetterCallback>(
  192. reinterpret_cast<intptr_t>(
  193. obj->GetInternalField(kSetterIndex)
  194. .As<v8::Value>().As<v8::External>()->Value()));
  195. callback(property.As<v8::String>(), value, cbinfo);
  196. }
  197. typedef void (*NativeSetter)(
  198. v8::Local<v8::Name>
  199. , v8::Local<v8::Value>
  200. , const v8::PropertyCallbackInfo<void> &);
  201. #else
  202. static
  203. void GetterCallbackWrapper(
  204. v8::Local<v8::String> property
  205. , const v8::PropertyCallbackInfo<v8::Value> &info) {
  206. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  207. PropertyCallbackInfo<v8::Value>
  208. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  209. GetterCallback callback = reinterpret_cast<GetterCallback>(
  210. reinterpret_cast<intptr_t>(
  211. obj->GetInternalField(kGetterIndex)
  212. .As<v8::Value>().As<v8::External>()->Value()));
  213. callback(property, cbinfo);
  214. }
  215. typedef void (*NativeGetter)
  216. (v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value> &);
  217. static
  218. void SetterCallbackWrapper(
  219. v8::Local<v8::String> property
  220. , v8::Local<v8::Value> value
  221. , const v8::PropertyCallbackInfo<void> &info) {
  222. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  223. PropertyCallbackInfo<void>
  224. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  225. SetterCallback callback = reinterpret_cast<SetterCallback>(
  226. reinterpret_cast<intptr_t>(
  227. obj->GetInternalField(kSetterIndex)
  228. .As<v8::Value>().As<v8::External>()->Value()));
  229. callback(property, value, cbinfo);
  230. }
  231. typedef void (*NativeSetter)(
  232. v8::Local<v8::String>
  233. , v8::Local<v8::Value>
  234. , const v8::PropertyCallbackInfo<void> &);
  235. #endif
  236. #if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION
  237. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
  238. (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
  239. static
  240. v8::Intercepted PropertyGetterCallbackWrapper(
  241. v8::Local<v8::Name> property
  242. , const v8::PropertyCallbackInfo<v8::Value> &info) {
  243. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  244. PropertyCallbackInfo<v8::Value>
  245. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  246. PropertyGetterCallback callback = reinterpret_cast<PropertyGetterCallback>(
  247. reinterpret_cast<intptr_t>(
  248. obj->GetInternalField(kPropertyGetterIndex)
  249. .As<v8::Value>().As<v8::External>()->Value()));
  250. return callback(property.As<v8::String>(), cbinfo);
  251. }
  252. typedef v8::Intercepted (*NativePropertyGetter)
  253. (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &);
  254. static
  255. v8::Intercepted PropertySetterCallbackWrapper(
  256. v8::Local<v8::Name> property
  257. , v8::Local<v8::Value> value
  258. , const v8::PropertyCallbackInfo<void> &info) {
  259. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  260. PropertyCallbackInfo<void>
  261. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  262. PropertySetterCallback callback = reinterpret_cast<PropertySetterCallback>(
  263. reinterpret_cast<intptr_t>(
  264. obj->GetInternalField(kPropertySetterIndex)
  265. .As<v8::Value>().As<v8::External>()->Value()));
  266. return callback(property.As<v8::String>(), value, cbinfo);
  267. }
  268. typedef v8::Intercepted (*NativePropertySetter)(
  269. v8::Local<v8::Name>
  270. , v8::Local<v8::Value>
  271. , const v8::PropertyCallbackInfo<void> &);
  272. #else
  273. static
  274. void PropertyGetterCallbackWrapper(
  275. v8::Local<v8::Name> property
  276. , const v8::PropertyCallbackInfo<v8::Value> &info) {
  277. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  278. PropertyCallbackInfo<v8::Value>
  279. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  280. PropertyGetterCallback callback = reinterpret_cast<PropertyGetterCallback>(
  281. reinterpret_cast<intptr_t>(
  282. obj->GetInternalField(kPropertyGetterIndex)
  283. .As<v8::Value>().As<v8::External>()->Value()));
  284. callback(property.As<v8::String>(), cbinfo);
  285. }
  286. typedef void (*NativePropertyGetter)
  287. (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &);
  288. static
  289. void PropertySetterCallbackWrapper(
  290. v8::Local<v8::Name> property
  291. , v8::Local<v8::Value> value
  292. , const v8::PropertyCallbackInfo<v8::Value> &info) {
  293. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  294. PropertyCallbackInfo<v8::Value>
  295. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  296. PropertySetterCallback callback = reinterpret_cast<PropertySetterCallback>(
  297. reinterpret_cast<intptr_t>(
  298. obj->GetInternalField(kPropertySetterIndex)
  299. .As<v8::Value>().As<v8::External>()->Value()));
  300. callback(property.As<v8::String>(), value, cbinfo);
  301. }
  302. typedef void (*NativePropertySetter)(
  303. v8::Local<v8::Name>
  304. , v8::Local<v8::Value>
  305. , const v8::PropertyCallbackInfo<v8::Value> &);
  306. #endif
  307. static
  308. void PropertyEnumeratorCallbackWrapper(
  309. const v8::PropertyCallbackInfo<v8::Array> &info) {
  310. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  311. PropertyCallbackInfo<v8::Array>
  312. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  313. PropertyEnumeratorCallback callback =
  314. reinterpret_cast<PropertyEnumeratorCallback>(reinterpret_cast<intptr_t>(
  315. obj->GetInternalField(kPropertyEnumeratorIndex)
  316. .As<v8::Value>().As<v8::External>()->Value()));
  317. callback(cbinfo);
  318. }
  319. typedef void (*NativePropertyEnumerator)
  320. (const v8::PropertyCallbackInfo<v8::Array> &);
  321. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
  322. (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
  323. static
  324. v8::Intercepted PropertyDeleterCallbackWrapper(
  325. v8::Local<v8::Name> property
  326. , const v8::PropertyCallbackInfo<v8::Boolean> &info) {
  327. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  328. PropertyCallbackInfo<v8::Boolean>
  329. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  330. PropertyDeleterCallback callback = reinterpret_cast<PropertyDeleterCallback>(
  331. reinterpret_cast<intptr_t>(
  332. obj->GetInternalField(kPropertyDeleterIndex)
  333. .As<v8::Value>().As<v8::External>()->Value()));
  334. return callback(property.As<v8::String>(), cbinfo);
  335. }
  336. typedef v8::Intercepted (NativePropertyDeleter)
  337. (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Boolean> &);
  338. static
  339. v8::Intercepted PropertyQueryCallbackWrapper(
  340. v8::Local<v8::Name> property
  341. , const v8::PropertyCallbackInfo<v8::Integer> &info) {
  342. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  343. PropertyCallbackInfo<v8::Integer>
  344. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  345. PropertyQueryCallback callback = reinterpret_cast<PropertyQueryCallback>(
  346. reinterpret_cast<intptr_t>(
  347. obj->GetInternalField(kPropertyQueryIndex)
  348. .As<v8::Value>().As<v8::External>()->Value()));
  349. return callback(property.As<v8::String>(), cbinfo);
  350. }
  351. typedef v8::Intercepted (*NativePropertyQuery)
  352. (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Integer> &);
  353. #else
  354. static
  355. void PropertyDeleterCallbackWrapper(
  356. v8::Local<v8::Name> property
  357. , const v8::PropertyCallbackInfo<v8::Boolean> &info) {
  358. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  359. PropertyCallbackInfo<v8::Boolean>
  360. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  361. PropertyDeleterCallback callback = reinterpret_cast<PropertyDeleterCallback>(
  362. reinterpret_cast<intptr_t>(
  363. obj->GetInternalField(kPropertyDeleterIndex)
  364. .As<v8::Value>().As<v8::External>()->Value()));
  365. callback(property.As<v8::String>(), cbinfo);
  366. }
  367. typedef void (NativePropertyDeleter)
  368. (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Boolean> &);
  369. static
  370. void PropertyQueryCallbackWrapper(
  371. v8::Local<v8::Name> property
  372. , const v8::PropertyCallbackInfo<v8::Integer> &info) {
  373. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  374. PropertyCallbackInfo<v8::Integer>
  375. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  376. PropertyQueryCallback callback = reinterpret_cast<PropertyQueryCallback>(
  377. reinterpret_cast<intptr_t>(
  378. obj->GetInternalField(kPropertyQueryIndex)
  379. .As<v8::Value>().As<v8::External>()->Value()));
  380. callback(property.As<v8::String>(), cbinfo);
  381. }
  382. typedef void (*NativePropertyQuery)
  383. (v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Integer> &);
  384. #endif
  385. #else
  386. static
  387. void PropertyGetterCallbackWrapper(
  388. v8::Local<v8::String> property
  389. , const v8::PropertyCallbackInfo<v8::Value> &info) {
  390. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  391. PropertyCallbackInfo<v8::Value>
  392. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  393. PropertyGetterCallback callback = reinterpret_cast<PropertyGetterCallback>(
  394. reinterpret_cast<intptr_t>(
  395. obj->GetInternalField(kPropertyGetterIndex)
  396. .As<v8::Value>().As<v8::External>()->Value()));
  397. callback(property, cbinfo);
  398. }
  399. typedef void (*NativePropertyGetter)
  400. (v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value> &);
  401. static
  402. void PropertySetterCallbackWrapper(
  403. v8::Local<v8::String> property
  404. , v8::Local<v8::Value> value
  405. , const v8::PropertyCallbackInfo<v8::Value> &info) {
  406. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  407. PropertyCallbackInfo<v8::Value>
  408. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  409. PropertySetterCallback callback = reinterpret_cast<PropertySetterCallback>(
  410. reinterpret_cast<intptr_t>(
  411. obj->GetInternalField(kPropertySetterIndex)
  412. .As<v8::Value>().As<v8::External>()->Value()));
  413. callback(property, value, cbinfo);
  414. }
  415. typedef void (*NativePropertySetter)(
  416. v8::Local<v8::String>
  417. , v8::Local<v8::Value>
  418. , const v8::PropertyCallbackInfo<v8::Value> &);
  419. static
  420. void PropertyEnumeratorCallbackWrapper(
  421. const v8::PropertyCallbackInfo<v8::Array> &info) {
  422. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  423. PropertyCallbackInfo<v8::Array>
  424. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  425. PropertyEnumeratorCallback callback =
  426. reinterpret_cast<PropertyEnumeratorCallback>(reinterpret_cast<intptr_t>(
  427. obj->GetInternalField(kPropertyEnumeratorIndex)
  428. .As<v8::Value>().As<v8::External>()->Value()));
  429. callback(cbinfo);
  430. }
  431. typedef void (*NativePropertyEnumerator)
  432. (const v8::PropertyCallbackInfo<v8::Array> &);
  433. static
  434. void PropertyDeleterCallbackWrapper(
  435. v8::Local<v8::String> property
  436. , const v8::PropertyCallbackInfo<v8::Boolean> &info) {
  437. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  438. PropertyCallbackInfo<v8::Boolean>
  439. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  440. PropertyDeleterCallback callback = reinterpret_cast<PropertyDeleterCallback>(
  441. reinterpret_cast<intptr_t>(
  442. obj->GetInternalField(kPropertyDeleterIndex)
  443. .As<v8::Value>().As<v8::External>()->Value()));
  444. callback(property, cbinfo);
  445. }
  446. typedef void (NativePropertyDeleter)
  447. (v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Boolean> &);
  448. static
  449. void PropertyQueryCallbackWrapper(
  450. v8::Local<v8::String> property
  451. , const v8::PropertyCallbackInfo<v8::Integer> &info) {
  452. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  453. PropertyCallbackInfo<v8::Integer>
  454. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  455. PropertyQueryCallback callback = reinterpret_cast<PropertyQueryCallback>(
  456. reinterpret_cast<intptr_t>(
  457. obj->GetInternalField(kPropertyQueryIndex)
  458. .As<v8::Value>().As<v8::External>()->Value()));
  459. callback(property, cbinfo);
  460. }
  461. typedef void (*NativePropertyQuery)
  462. (v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Integer> &);
  463. #endif
  464. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
  465. (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
  466. static
  467. v8::Intercepted IndexGetterCallbackWrapper(
  468. uint32_t index, const v8::PropertyCallbackInfo<v8::Value> &info) {
  469. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  470. PropertyCallbackInfo<v8::Value>
  471. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  472. IndexGetterCallback callback = reinterpret_cast<IndexGetterCallback>(
  473. reinterpret_cast<intptr_t>(
  474. obj->GetInternalField(kIndexPropertyGetterIndex)
  475. .As<v8::Value>().As<v8::External>()->Value()));
  476. return callback(index, cbinfo);
  477. }
  478. typedef v8::Intercepted (*NativeIndexGetter)
  479. (uint32_t, const v8::PropertyCallbackInfo<v8::Value> &);
  480. static
  481. v8::Intercepted IndexSetterCallbackWrapper(
  482. uint32_t index
  483. , v8::Local<v8::Value> value
  484. , const v8::PropertyCallbackInfo<void> &info) {
  485. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  486. PropertyCallbackInfo<void>
  487. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  488. IndexSetterCallback callback = reinterpret_cast<IndexSetterCallback>(
  489. reinterpret_cast<intptr_t>(
  490. obj->GetInternalField(kIndexPropertySetterIndex)
  491. .As<v8::Value>().As<v8::External>()->Value()));
  492. return callback(index, value, cbinfo);
  493. }
  494. typedef v8::Intercepted (*NativeIndexSetter)(
  495. uint32_t
  496. , v8::Local<v8::Value>
  497. , const v8::PropertyCallbackInfo<void> &);
  498. #else
  499. static
  500. void IndexGetterCallbackWrapper(
  501. uint32_t index, const v8::PropertyCallbackInfo<v8::Value> &info) {
  502. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  503. PropertyCallbackInfo<v8::Value>
  504. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  505. IndexGetterCallback callback = reinterpret_cast<IndexGetterCallback>(
  506. reinterpret_cast<intptr_t>(
  507. obj->GetInternalField(kIndexPropertyGetterIndex)
  508. .As<v8::Value>().As<v8::External>()->Value()));
  509. callback(index, cbinfo);
  510. }
  511. typedef void (*NativeIndexGetter)
  512. (uint32_t, const v8::PropertyCallbackInfo<v8::Value> &);
  513. static
  514. void IndexSetterCallbackWrapper(
  515. uint32_t index
  516. , v8::Local<v8::Value> value
  517. , const v8::PropertyCallbackInfo<v8::Value> &info) {
  518. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  519. PropertyCallbackInfo<v8::Value>
  520. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  521. IndexSetterCallback callback = reinterpret_cast<IndexSetterCallback>(
  522. reinterpret_cast<intptr_t>(
  523. obj->GetInternalField(kIndexPropertySetterIndex)
  524. .As<v8::Value>().As<v8::External>()->Value()));
  525. callback(index, value, cbinfo);
  526. }
  527. typedef void (*NativeIndexSetter)(
  528. uint32_t
  529. , v8::Local<v8::Value>
  530. , const v8::PropertyCallbackInfo<v8::Value> &);
  531. #endif
  532. static
  533. void IndexEnumeratorCallbackWrapper(
  534. const v8::PropertyCallbackInfo<v8::Array> &info) {
  535. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  536. PropertyCallbackInfo<v8::Array>
  537. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  538. IndexEnumeratorCallback callback = reinterpret_cast<IndexEnumeratorCallback>(
  539. reinterpret_cast<intptr_t>(
  540. obj->GetInternalField(
  541. kIndexPropertyEnumeratorIndex)
  542. .As<v8::Value>().As<v8::External>()->Value()));
  543. callback(cbinfo);
  544. }
  545. typedef void (*NativeIndexEnumerator)
  546. (const v8::PropertyCallbackInfo<v8::Array> &);
  547. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
  548. (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
  549. static
  550. v8::Intercepted IndexDeleterCallbackWrapper(
  551. uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean> &info) {
  552. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  553. PropertyCallbackInfo<v8::Boolean>
  554. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  555. IndexDeleterCallback callback = reinterpret_cast<IndexDeleterCallback>(
  556. reinterpret_cast<intptr_t>(
  557. obj->GetInternalField(kIndexPropertyDeleterIndex)
  558. .As<v8::Value>().As<v8::External>()->Value()));
  559. return callback(index, cbinfo);
  560. }
  561. typedef v8::Intercepted (*NativeIndexDeleter)
  562. (uint32_t, const v8::PropertyCallbackInfo<v8::Boolean> &);
  563. static
  564. v8::Intercepted IndexQueryCallbackWrapper(
  565. uint32_t index, const v8::PropertyCallbackInfo<v8::Integer> &info) {
  566. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  567. PropertyCallbackInfo<v8::Integer>
  568. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  569. IndexQueryCallback callback = reinterpret_cast<IndexQueryCallback>(
  570. reinterpret_cast<intptr_t>(
  571. obj->GetInternalField(kIndexPropertyQueryIndex)
  572. .As<v8::Value>().As<v8::External>()->Value()));
  573. return callback(index, cbinfo);
  574. }
  575. typedef v8::Intercepted (*NativeIndexQuery)
  576. (uint32_t, const v8::PropertyCallbackInfo<v8::Integer> &);
  577. #else
  578. static
  579. void IndexDeleterCallbackWrapper(
  580. uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean> &info) {
  581. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  582. PropertyCallbackInfo<v8::Boolean>
  583. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  584. IndexDeleterCallback callback = reinterpret_cast<IndexDeleterCallback>(
  585. reinterpret_cast<intptr_t>(
  586. obj->GetInternalField(kIndexPropertyDeleterIndex)
  587. .As<v8::Value>().As<v8::External>()->Value()));
  588. callback(index, cbinfo);
  589. }
  590. typedef void (*NativeIndexDeleter)
  591. (uint32_t, const v8::PropertyCallbackInfo<v8::Boolean> &);
  592. static
  593. void IndexQueryCallbackWrapper(
  594. uint32_t index, const v8::PropertyCallbackInfo<v8::Integer> &info) {
  595. v8::Local<v8::Object> obj = info.Data().As<v8::Object>();
  596. PropertyCallbackInfo<v8::Integer>
  597. cbinfo(info, obj->GetInternalField(kDataIndex).As<v8::Value>());
  598. IndexQueryCallback callback = reinterpret_cast<IndexQueryCallback>(
  599. reinterpret_cast<intptr_t>(
  600. obj->GetInternalField(kIndexPropertyQueryIndex)
  601. .As<v8::Value>().As<v8::External>()->Value()));
  602. callback(index, cbinfo);
  603. }
  604. typedef void (*NativeIndexQuery)
  605. (uint32_t, const v8::PropertyCallbackInfo<v8::Integer> &);
  606. #endif
  607. } // end of namespace imp
  608. #endif // NAN_CALLBACKS_12_INL_H_