Debian Codegraph @

node/node-addon-api/napi-inl.deprecated.h

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