source: trip-planner-front/node_modules/node-addon-api/napi-inl.deprecated.h@ e29cc2e

Last change on this file since e29cc2e was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

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