@@ -54,8 +54,8 @@ class TSFNWrap : public base {
5454 }
5555
5656 static std::array<ClassPropertyDescriptor<TSFNWrap>, 2 > InstanceMethods () {
57- return {InstanceMethod (" release" , &TSFNWrap::Release),
58- InstanceMethod (" call" , &TSFNWrap::Call)};
57+ return {{ InstanceMethod (" release" , &TSFNWrap::Release),
58+ InstanceMethod (" call" , &TSFNWrap::Call)} };
5959 }
6060
6161 Napi::Value Call (const CallbackInfo &info) {
@@ -105,23 +105,23 @@ class TSFNWrap : public base {
105105
106106 ContextType *context = new ContextType (Persistent (info[0 ]));
107107
108- _tsfn = TSFN::New (
109- env, // napi_env env,
110- TSFN::DefaultFunctionFactory (env), // const Function& callback,
111- Value (), // const Object& resource,
112- " Test " , // ResourceString resourceName,
113- 0 , // size_t maxQueueSize,
114- 1 , // size_t initialThreadCount,
115- context, // ContextType* context,
116- base::Finalizer, // Finalizer finalizer
117- &_deferred // FinalizerDataType* data
118- );
108+ _tsfn =
109+ TSFN::New ( env, // napi_env env,
110+ TSFN::EmptyFunctionFactory (env), // const Function& callback,
111+ Value (), // const Object& resource,
112+ " Test " , // ResourceString resourceName,
113+ 0 , // size_t maxQueueSize,
114+ 1 , // size_t initialThreadCount,
115+ context, // ContextType* context,
116+ base::Finalizer, // Finalizer finalizer
117+ &_deferred // FinalizerDataType* data
118+ );
119119 }
120120
121121 static std::array<ClassPropertyDescriptor<TSFNWrap>, 3 > InstanceMethods () {
122- return {InstanceMethod (" call" , &TSFNWrap::Call),
123- InstanceMethod (" getContext" , &TSFNWrap::GetContext),
124- InstanceMethod (" release" , &TSFNWrap::Release)};
122+ return {{ InstanceMethod (" call" , &TSFNWrap::Call),
123+ InstanceMethod (" getContext" , &TSFNWrap::GetContext),
124+ InstanceMethod (" release" , &TSFNWrap::Release)} };
125125 }
126126
127127 Napi::Value Call (const CallbackInfo &info) {
@@ -187,8 +187,8 @@ class TSFNWrap : public base {
187187 }
188188
189189 static std::array<ClassPropertyDescriptor<TSFNWrap>, 2 > InstanceMethods () {
190- return {InstanceMethod (" release" , &TSFNWrap::Release),
191- InstanceMethod (" call" , &TSFNWrap::Call)};
190+ return {{ InstanceMethod (" release" , &TSFNWrap::Release),
191+ InstanceMethod (" call" , &TSFNWrap::Call)} };
192192 }
193193
194194 Napi::Value Call (const CallbackInfo &info) {
@@ -212,14 +212,17 @@ struct DataType {
212212// CallJs callback function provided to `napi_create_threadsafe_function`. It is
213213// _NOT_ used by `Napi::ThreadSafeFunctionEx<>`, which is why these arguments
214214// are napi_*.
215- static void CallJs (napi_env env, napi_value jsCallback, void * /* context*/ ,
215+ static void CallJs (napi_env env, napi_value /* jsCallback*/ , void * /* context*/ ,
216216 void *data) {
217217 DataType *casted = static_cast <DataType *>(data);
218218 if (env != nullptr ) {
219219 if (data != nullptr ) {
220220 napi_value undefined;
221221 napi_status status = napi_get_undefined (env, &undefined);
222- NAPI_THROW_IF_FAILED (env, status);
222+ if (status != napi_ok) {
223+ NAPI_THROW_VOID (
224+ Error::New (env, " Could not get undefined from environment" ));
225+ }
223226 if (casted->reject ) {
224227 casted->deferred .Reject (undefined);
225228 } else {
@@ -257,14 +260,14 @@ class TSFNWrap : public base {
257260 napi_threadsafe_function napi_tsfn;
258261
259262 // A threadsafe function on N-API 4 still requires a callback function, so
260- // this uses the `DefaultFunctionFactory ` helper method to return a no-op
263+ // this uses the `EmptyFunctionFactory ` helper method to return a no-op
261264 // Function.
262265 auto status = napi_create_threadsafe_function (
263- info.Env (), TSFN::DefaultFunctionFactory (env), nullptr ,
266+ info.Env (), TSFN::EmptyFunctionFactory (env), nullptr ,
264267 String::From (info.Env (), " Test" ), 0 , 1 , nullptr , nullptr , nullptr ,
265268 CallJs, &napi_tsfn);
266269 if (status != napi_ok) {
267- NAPI_THROW_IF_FAILED ( env, status );
270+ NAPI_THROW_VOID ( Error::New ( env, " Could not create TSFN. " ) );
268271 }
269272 _tsfn = TSFN (napi_tsfn);
270273#else
@@ -276,15 +279,16 @@ class TSFNWrap : public base {
276279 info.Env (), nullptr , nullptr , String::From (info.Env (), " Test" ), 0 , 1 ,
277280 nullptr , Finalizer, this , CallJs, &napi_tsfn);
278281 if (status != napi_ok) {
279- NAPI_THROW_IF_FAILED (env, status);
282+ NAPI_THROW_VOID (
283+ Error::New (env, " Could not get undefined from environment" ));
280284 }
281285 _tsfn = TSFN (napi_tsfn);
282286#endif
283287 }
284288
285289 static std::array<ClassPropertyDescriptor<TSFNWrap>, 2 > InstanceMethods () {
286- return {InstanceMethod (" release" , &TSFNWrap::Release),
287- InstanceMethod (" call" , &TSFNWrap::Call)};
290+ return {{ InstanceMethod (" release" , &TSFNWrap::Release),
291+ InstanceMethod (" call" , &TSFNWrap::Call)} };
288292 }
289293
290294 Napi::Value Call (const CallbackInfo &info) {
@@ -333,7 +337,7 @@ class TSFNWrap : public base {
333337 // A threadsafe function on N-API 4 still requires a callback function.
334338 _tsfn = TSFN::New (
335339 env, // napi_env env,
336- TSFN::DefaultFunctionFactory (
340+ TSFN::EmptyFunctionFactory (
337341 env), // N-API 5+: nullptr; else: const Function& callback,
338342 " Test" , // ResourceString resourceName,
339343 1 , // size_t maxQueueSize,
@@ -349,8 +353,8 @@ class TSFNWrap : public base {
349353 }
350354
351355 static std::array<ClassPropertyDescriptor<TSFNWrap>, 2 > InstanceMethods () {
352- return {InstanceMethod (" release" , &TSFNWrap::Release),
353- InstanceMethod (" call" , &TSFNWrap::Call)};
356+ return {{ InstanceMethod (" release" , &TSFNWrap::Release),
357+ InstanceMethod (" call" , &TSFNWrap::Call)} };
354358 }
355359
356360 // Since this test spec has no CALLBACK, CONTEXT, or FINALIZER. We have no way
0 commit comments