@@ -6,13 +6,6 @@ namespace {
6
6
7
7
int testData = 1 ;
8
8
9
- Boolean EmptyConstructor (const CallbackInfo& info) {
10
- auto env = info.Env ();
11
- bool isEmpty = info[0 ].As <Boolean>();
12
- Function function = isEmpty ? Function () : Function (env, Object::New (env));
13
- return Boolean::New (env, function.IsEmpty ());
14
- }
15
-
16
9
void VoidCallback (const CallbackInfo& info) {
17
10
auto env = info.Env ();
18
11
Object obj = info[0 ].As <Object>();
@@ -52,9 +45,8 @@ Value ValueCallbackWithData(const CallbackInfo& info) {
52
45
}
53
46
54
47
Value CallWithArgs (const CallbackInfo& info) {
55
- Function func = info[0 ].As <Function>();
56
- return func.Call (
57
- std::initializer_list<napi_value>{info[1 ], info[2 ], info[3 ]});
48
+ Function func = info[0 ].As <Function>();
49
+ return func ({ info[1 ], info[2 ], info[3 ] });
58
50
}
59
51
60
52
Value CallWithVector (const CallbackInfo& info) {
@@ -67,27 +59,6 @@ Value CallWithVector(const CallbackInfo& info) {
67
59
return func.Call (args);
68
60
}
69
61
70
- Value CallWithCStyleArray (const CallbackInfo& info) {
71
- Function func = info[0 ].As <Function>();
72
- std::vector<napi_value> args;
73
- args.reserve (3 );
74
- args.push_back (info[1 ]);
75
- args.push_back (info[2 ]);
76
- args.push_back (info[3 ]);
77
- return func.Call (args.size (), args.data ());
78
- }
79
-
80
- Value CallWithReceiverAndCStyleArray (const CallbackInfo& info) {
81
- Function func = info[0 ].As <Function>();
82
- Value receiver = info[1 ];
83
- std::vector<napi_value> args;
84
- args.reserve (3 );
85
- args.push_back (info[2 ]);
86
- args.push_back (info[3 ]);
87
- args.push_back (info[4 ]);
88
- return func.Call (receiver, args.size (), args.data ());
89
- }
90
-
91
62
Value CallWithReceiverAndArgs (const CallbackInfo& info) {
92
63
Function func = info[0 ].As <Function>();
93
64
Value receiver = info[1 ];
@@ -125,81 +96,17 @@ Value CallConstructorWithVector(const CallbackInfo& info) {
125
96
return func.New (args);
126
97
}
127
98
128
- Value CallConstructorWithCStyleArray (const CallbackInfo& info) {
129
- Function func = info[0 ].As <Function>();
130
- std::vector<napi_value> args;
131
- args.reserve (3 );
132
- args.push_back (info[1 ]);
133
- args.push_back (info[2 ]);
134
- args.push_back (info[3 ]);
135
- return func.New (args.size (), args.data ());
136
- }
137
-
138
99
void IsConstructCall (const CallbackInfo& info) {
139
100
Function callback = info[0 ].As <Function>();
140
101
bool isConstructCall = info.IsConstructCall ();
141
102
callback ({Napi::Boolean::New (info.Env (), isConstructCall)});
142
103
}
143
104
144
- void MakeCallbackWithArgs (const CallbackInfo& info) {
145
- Env env = info.Env ();
146
- Function callback = info[0 ].As <Function>();
147
- Object resource = info[1 ].As <Object>();
148
-
149
- AsyncContext context (env, " async_context_test" , resource);
150
-
151
- callback.MakeCallback (
152
- resource,
153
- std::initializer_list<napi_value>{info[2 ], info[3 ], info[4 ]},
154
- context);
155
- }
156
-
157
- void MakeCallbackWithVector (const CallbackInfo& info) {
158
- Env env = info.Env ();
159
- Function callback = info[0 ].As <Function>();
160
- Object resource = info[1 ].As <Object>();
161
-
162
- AsyncContext context (env, " async_context_test" , resource);
163
-
164
- std::vector<napi_value> args;
165
- args.reserve (3 );
166
- args.push_back (info[2 ]);
167
- args.push_back (info[3 ]);
168
- args.push_back (info[4 ]);
169
- callback.MakeCallback (resource, args, context);
170
- }
171
-
172
- void MakeCallbackWithCStyleArray (const CallbackInfo& info) {
173
- Env env = info.Env ();
174
- Function callback = info[0 ].As <Function>();
175
- Object resource = info[1 ].As <Object>();
176
-
177
- AsyncContext context (env, " async_context_test" , resource);
178
-
179
- std::vector<napi_value> args;
180
- args.reserve (3 );
181
- args.push_back (info[2 ]);
182
- args.push_back (info[3 ]);
183
- args.push_back (info[4 ]);
184
- callback.MakeCallback (resource, args.size (), args.data (), context);
185
- }
186
-
187
- void MakeCallbackWithInvalidReceiver (const CallbackInfo& info) {
188
- Function callback = info[0 ].As <Function>();
189
- callback.MakeCallback (Value (), std::initializer_list<napi_value>{});
190
- }
191
-
192
- Value CallWithFunctionOperator (const CallbackInfo& info) {
193
- Function func = info[0 ].As <Function>();
194
- return func ({info[1 ], info[2 ], info[3 ]});
195
- }
196
-
197
105
} // end anonymous namespace
198
106
199
107
Object InitFunction (Env env) {
200
108
Object result = Object::New (env);
201
109
Object exports = Object::New (env);
202
- exports[" emptyConstructor" ] = Function::New (env, EmptyConstructor);
203
110
exports[" voidCallback" ] = Function::New (env, VoidCallback, " voidCallback" );
204
111
exports[" valueCallback" ] = Function::New (env, ValueCallback, std::string (" valueCallback" ));
205
112
exports[" voidCallbackWithData" ] =
@@ -208,30 +115,15 @@ Object InitFunction(Env env) {
208
115
Function::New (env, ValueCallbackWithData, nullptr , &testData);
209
116
exports[" callWithArgs" ] = Function::New (env, CallWithArgs);
210
117
exports[" callWithVector" ] = Function::New (env, CallWithVector);
211
- exports[" callWithCStyleArray" ] = Function::New (env, CallWithCStyleArray);
212
- exports[" callWithReceiverAndCStyleArray" ] =
213
- Function::New (env, CallWithReceiverAndCStyleArray);
214
118
exports[" callWithReceiverAndArgs" ] = Function::New (env, CallWithReceiverAndArgs);
215
119
exports[" callWithReceiverAndVector" ] = Function::New (env, CallWithReceiverAndVector);
216
120
exports[" callWithInvalidReceiver" ] = Function::New (env, CallWithInvalidReceiver);
217
121
exports[" callConstructorWithArgs" ] = Function::New (env, CallConstructorWithArgs);
218
122
exports[" callConstructorWithVector" ] = Function::New (env, CallConstructorWithVector);
219
- exports[" callConstructorWithCStyleArray" ] =
220
- Function::New (env, CallConstructorWithCStyleArray);
221
123
exports[" isConstructCall" ] = Function::New (env, IsConstructCall);
222
- exports[" makeCallbackWithArgs" ] = Function::New (env, MakeCallbackWithArgs);
223
- exports[" makeCallbackWithVector" ] =
224
- Function::New (env, MakeCallbackWithVector);
225
- exports[" makeCallbackWithCStyleArray" ] =
226
- Function::New (env, MakeCallbackWithCStyleArray);
227
- exports[" makeCallbackWithInvalidReceiver" ] =
228
- Function::New (env, MakeCallbackWithInvalidReceiver);
229
- exports[" callWithFunctionOperator" ] =
230
- Function::New (env, CallWithFunctionOperator);
231
124
result[" plain" ] = exports;
232
125
233
126
exports = Object::New (env);
234
- exports[" emptyConstructor" ] = Function::New (env, EmptyConstructor);
235
127
exports[" voidCallback" ] = Function::New<VoidCallback>(env, " voidCallback" );
236
128
exports[" valueCallback" ] =
237
129
Function::New<ValueCallback>(env, std::string (" valueCallback" ));
@@ -241,9 +133,6 @@ Object InitFunction(Env env) {
241
133
Function::New<ValueCallbackWithData>(env, nullptr , &testData);
242
134
exports[" callWithArgs" ] = Function::New<CallWithArgs>(env);
243
135
exports[" callWithVector" ] = Function::New<CallWithVector>(env);
244
- exports[" callWithCStyleArray" ] = Function::New<CallWithCStyleArray>(env);
245
- exports[" callWithReceiverAndCStyleArray" ] =
246
- Function::New<CallWithReceiverAndCStyleArray>(env);
247
136
exports[" callWithReceiverAndArgs" ] =
248
137
Function::New<CallWithReceiverAndArgs>(env);
249
138
exports[" callWithReceiverAndVector" ] =
@@ -254,18 +143,7 @@ Object InitFunction(Env env) {
254
143
Function::New<CallConstructorWithArgs>(env);
255
144
exports[" callConstructorWithVector" ] =
256
145
Function::New<CallConstructorWithVector>(env);
257
- exports[" callConstructorWithCStyleArray" ] =
258
- Function::New<CallConstructorWithCStyleArray>(env);
259
146
exports[" isConstructCall" ] = Function::New<IsConstructCall>(env);
260
- exports[" makeCallbackWithArgs" ] = Function::New<MakeCallbackWithArgs>(env);
261
- exports[" makeCallbackWithVector" ] =
262
- Function::New<MakeCallbackWithVector>(env);
263
- exports[" makeCallbackWithCStyleArray" ] =
264
- Function::New<MakeCallbackWithCStyleArray>(env);
265
- exports[" makeCallbackWithInvalidReceiver" ] =
266
- Function::New<MakeCallbackWithInvalidReceiver>(env);
267
- exports[" callWithFunctionOperator" ] =
268
- Function::New<CallWithFunctionOperator>(env);
269
147
result[" templated" ] = exports;
270
148
return result;
271
149
}
0 commit comments