napi-inl.deprecated.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #ifndef SRC_NAPI_INL_DEPRECATED_H_
  2. #define SRC_NAPI_INL_DEPRECATED_H_
  3. ////////////////////////////////////////////////////////////////////////////////
  4. // PropertyDescriptor class
  5. ////////////////////////////////////////////////////////////////////////////////
  6. template <typename Getter>
  7. inline PropertyDescriptor PropertyDescriptor::Accessor(
  8. const char* utf8name,
  9. Getter getter,
  10. napi_property_attributes attributes,
  11. void* /*data*/) {
  12. using CbData = details::CallbackData<Getter, Napi::Value>;
  13. // TODO: Delete when the function is destroyed
  14. auto callbackData = new CbData({getter, nullptr});
  15. return PropertyDescriptor({utf8name,
  16. nullptr,
  17. nullptr,
  18. CbData::Wrapper,
  19. nullptr,
  20. nullptr,
  21. attributes,
  22. callbackData});
  23. }
  24. template <typename Getter>
  25. inline PropertyDescriptor PropertyDescriptor::Accessor(
  26. const std::string& utf8name,
  27. Getter getter,
  28. napi_property_attributes attributes,
  29. void* data) {
  30. return Accessor(utf8name.c_str(), getter, attributes, data);
  31. }
  32. template <typename Getter>
  33. inline PropertyDescriptor PropertyDescriptor::Accessor(
  34. napi_value name,
  35. Getter getter,
  36. napi_property_attributes attributes,
  37. void* /*data*/) {
  38. using CbData = details::CallbackData<Getter, Napi::Value>;
  39. // TODO: Delete when the function is destroyed
  40. auto callbackData = new CbData({getter, nullptr});
  41. return PropertyDescriptor({nullptr,
  42. name,
  43. nullptr,
  44. CbData::Wrapper,
  45. nullptr,
  46. nullptr,
  47. attributes,
  48. callbackData});
  49. }
  50. template <typename Getter>
  51. inline PropertyDescriptor PropertyDescriptor::Accessor(
  52. Name name, Getter getter, napi_property_attributes attributes, void* data) {
  53. napi_value nameValue = name;
  54. return PropertyDescriptor::Accessor(nameValue, getter, attributes, data);
  55. }
  56. template <typename Getter, typename Setter>
  57. inline PropertyDescriptor PropertyDescriptor::Accessor(
  58. const char* utf8name,
  59. Getter getter,
  60. Setter setter,
  61. napi_property_attributes attributes,
  62. void* /*data*/) {
  63. using CbData = details::AccessorCallbackData<Getter, Setter>;
  64. // TODO: Delete when the function is destroyed
  65. auto callbackData = new CbData({getter, setter, nullptr});
  66. return PropertyDescriptor({utf8name,
  67. nullptr,
  68. nullptr,
  69. CbData::GetterWrapper,
  70. CbData::SetterWrapper,
  71. nullptr,
  72. attributes,
  73. callbackData});
  74. }
  75. template <typename Getter, typename Setter>
  76. inline PropertyDescriptor PropertyDescriptor::Accessor(
  77. const std::string& utf8name,
  78. Getter getter,
  79. Setter setter,
  80. napi_property_attributes attributes,
  81. void* data) {
  82. return Accessor(utf8name.c_str(), getter, setter, attributes, data);
  83. }
  84. template <typename Getter, typename Setter>
  85. inline PropertyDescriptor PropertyDescriptor::Accessor(
  86. napi_value name,
  87. Getter getter,
  88. Setter setter,
  89. napi_property_attributes attributes,
  90. void* /*data*/) {
  91. using CbData = details::AccessorCallbackData<Getter, Setter>;
  92. // TODO: Delete when the function is destroyed
  93. auto callbackData = new CbData({getter, setter, nullptr});
  94. return PropertyDescriptor({nullptr,
  95. name,
  96. nullptr,
  97. CbData::GetterWrapper,
  98. CbData::SetterWrapper,
  99. nullptr,
  100. attributes,
  101. callbackData});
  102. }
  103. template <typename Getter, typename Setter>
  104. inline PropertyDescriptor PropertyDescriptor::Accessor(
  105. Name name,
  106. Getter getter,
  107. Setter setter,
  108. napi_property_attributes attributes,
  109. void* data) {
  110. napi_value nameValue = name;
  111. return PropertyDescriptor::Accessor(
  112. nameValue, getter, setter, attributes, data);
  113. }
  114. template <typename Callable>
  115. inline PropertyDescriptor PropertyDescriptor::Function(
  116. const char* utf8name,
  117. Callable cb,
  118. napi_property_attributes attributes,
  119. void* /*data*/) {
  120. using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
  121. using CbData = details::CallbackData<Callable, ReturnType>;
  122. // TODO: Delete when the function is destroyed
  123. auto callbackData = new CbData({cb, nullptr});
  124. return PropertyDescriptor({utf8name,
  125. nullptr,
  126. CbData::Wrapper,
  127. nullptr,
  128. nullptr,
  129. nullptr,
  130. attributes,
  131. callbackData});
  132. }
  133. template <typename Callable>
  134. inline PropertyDescriptor PropertyDescriptor::Function(
  135. const std::string& utf8name,
  136. Callable cb,
  137. napi_property_attributes attributes,
  138. void* data) {
  139. return Function(utf8name.c_str(), cb, attributes, data);
  140. }
  141. template <typename Callable>
  142. inline PropertyDescriptor PropertyDescriptor::Function(
  143. napi_value name,
  144. Callable cb,
  145. napi_property_attributes attributes,
  146. void* /*data*/) {
  147. using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
  148. using CbData = details::CallbackData<Callable, ReturnType>;
  149. // TODO: Delete when the function is destroyed
  150. auto callbackData = new CbData({cb, nullptr});
  151. return PropertyDescriptor({nullptr,
  152. name,
  153. CbData::Wrapper,
  154. nullptr,
  155. nullptr,
  156. nullptr,
  157. attributes,
  158. callbackData});
  159. }
  160. template <typename Callable>
  161. inline PropertyDescriptor PropertyDescriptor::Function(
  162. Name name, Callable cb, napi_property_attributes attributes, void* data) {
  163. napi_value nameValue = name;
  164. return PropertyDescriptor::Function(nameValue, cb, attributes, data);
  165. }
  166. #endif // !SRC_NAPI_INL_DEPRECATED_H_