napi-inl.deprecated.h 7.1 KB

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