nan_callbacks.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_H_
  9. #define NAN_CALLBACKS_H_
  10. template<typename T> class FunctionCallbackInfo;
  11. template<typename T> class PropertyCallbackInfo;
  12. template<typename T> class Global;
  13. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
  14. (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
  15. namespace Intercepted {
  16. constexpr v8::Intercepted No() { return v8::Intercepted::kNo; }
  17. constexpr v8::Intercepted Yes() { return v8::Intercepted::kYes; }
  18. };
  19. #else
  20. namespace Intercepted {
  21. inline void No() {}
  22. inline void Yes() {}
  23. };
  24. #endif
  25. typedef void(*FunctionCallback)(const FunctionCallbackInfo<v8::Value>&);
  26. typedef void(*GetterCallback)
  27. (v8::Local<v8::String>, const PropertyCallbackInfo<v8::Value>&);
  28. typedef void(*SetterCallback)(
  29. v8::Local<v8::String>,
  30. v8::Local<v8::Value>,
  31. const PropertyCallbackInfo<void>&);
  32. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
  33. (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
  34. typedef v8::Intercepted(*PropertyGetterCallback)(
  35. v8::Local<v8::String>,
  36. const PropertyCallbackInfo<v8::Value>&);
  37. typedef v8::Intercepted(*PropertySetterCallback)(
  38. v8::Local<v8::String>,
  39. v8::Local<v8::Value>,
  40. const PropertyCallbackInfo<void>&);
  41. #else
  42. typedef void(*PropertyGetterCallback)(
  43. v8::Local<v8::String>,
  44. const PropertyCallbackInfo<v8::Value>&);
  45. typedef void(*PropertySetterCallback)(
  46. v8::Local<v8::String>,
  47. v8::Local<v8::Value>,
  48. const PropertyCallbackInfo<v8::Value>&);
  49. #endif
  50. typedef void(*PropertyEnumeratorCallback)
  51. (const PropertyCallbackInfo<v8::Array>&);
  52. #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \
  53. (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4))
  54. typedef v8::Intercepted(*PropertyDeleterCallback)(
  55. v8::Local<v8::String>,
  56. const PropertyCallbackInfo<v8::Boolean>&);
  57. typedef v8::Intercepted(*PropertyQueryCallback)(
  58. v8::Local<v8::String>,
  59. const PropertyCallbackInfo<v8::Integer>&);
  60. typedef v8::Intercepted(*IndexGetterCallback)(
  61. uint32_t,
  62. const PropertyCallbackInfo<v8::Value>&);
  63. typedef v8::Intercepted(*IndexSetterCallback)(
  64. uint32_t,
  65. v8::Local<v8::Value>,
  66. const PropertyCallbackInfo<void>&);
  67. typedef v8::Intercepted(*IndexEnumeratorCallback)
  68. (const PropertyCallbackInfo<v8::Array>&);
  69. typedef v8::Intercepted(*IndexDeleterCallback)(
  70. uint32_t,
  71. const PropertyCallbackInfo<v8::Boolean>&);
  72. typedef v8::Intercepted(*IndexQueryCallback)(
  73. uint32_t,
  74. const PropertyCallbackInfo<v8::Integer>&);
  75. #else
  76. typedef void(*PropertyDeleterCallback)(
  77. v8::Local<v8::String>,
  78. const PropertyCallbackInfo<v8::Boolean>&);
  79. typedef void(*PropertyQueryCallback)(
  80. v8::Local<v8::String>,
  81. const PropertyCallbackInfo<v8::Integer>&);
  82. typedef void(*IndexGetterCallback)(
  83. uint32_t,
  84. const PropertyCallbackInfo<v8::Value>&);
  85. typedef void(*IndexSetterCallback)(
  86. uint32_t,
  87. v8::Local<v8::Value>,
  88. const PropertyCallbackInfo<v8::Value>&);
  89. typedef void(*IndexEnumeratorCallback)
  90. (const PropertyCallbackInfo<v8::Array>&);
  91. typedef void(*IndexDeleterCallback)(
  92. uint32_t,
  93. const PropertyCallbackInfo<v8::Boolean>&);
  94. typedef void(*IndexQueryCallback)(
  95. uint32_t,
  96. const PropertyCallbackInfo<v8::Integer>&);
  97. #endif
  98. namespace imp {
  99. #if (NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION)
  100. typedef v8::Local<v8::AccessorSignature> Sig;
  101. #else
  102. typedef v8::Local<v8::Data> Sig;
  103. #endif
  104. static const int kDataIndex = 0;
  105. static const int kFunctionIndex = 1;
  106. static const int kFunctionFieldCount = 2;
  107. static const int kGetterIndex = 1;
  108. static const int kSetterIndex = 2;
  109. static const int kAccessorFieldCount = 3;
  110. static const int kPropertyGetterIndex = 1;
  111. static const int kPropertySetterIndex = 2;
  112. static const int kPropertyEnumeratorIndex = 3;
  113. static const int kPropertyDeleterIndex = 4;
  114. static const int kPropertyQueryIndex = 5;
  115. static const int kPropertyFieldCount = 6;
  116. static const int kIndexPropertyGetterIndex = 1;
  117. static const int kIndexPropertySetterIndex = 2;
  118. static const int kIndexPropertyEnumeratorIndex = 3;
  119. static const int kIndexPropertyDeleterIndex = 4;
  120. static const int kIndexPropertyQueryIndex = 5;
  121. static const int kIndexPropertyFieldCount = 6;
  122. } // end of namespace imp
  123. #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION
  124. # include "nan_callbacks_12_inl.h" // NOLINT(build/include)
  125. #else
  126. # include "nan_callbacks_pre_12_inl.h" // NOLINT(build/include)
  127. #endif
  128. #endif // NAN_CALLBACKS_H_