44
55namespace {
66
7- // the test needs to fake out the async structure, so we need to use
8- // the raw structure here and then cast as done behind the scenes
9- // in napi calls.
10- struct async_context {
11- double async_id;
12- double trigger_async_id;
13- };
14-
15-
167napi_value RunInCallbackScope (napi_env env, napi_callback_info info) {
178 size_t argc;
18- napi_value args[4 ];
9+ napi_value args[3 ];
1910
2011 NAPI_CALL (env, napi_get_cb_info (env, info, &argc, nullptr , nullptr , nullptr ));
21- NAPI_ASSERT (env, argc == 4 , " Wrong number of arguments" );
12+ NAPI_ASSERT (env, argc == 3 , " Wrong number of arguments" );
2213
2314 NAPI_CALL (env, napi_get_cb_info (env, info, &argc, args, nullptr , nullptr ));
2415
@@ -28,35 +19,29 @@ napi_value RunInCallbackScope(napi_env env, napi_callback_info info) {
2819 " Wrong type of arguments. Expects an object as first argument." );
2920
3021 NAPI_CALL (env, napi_typeof (env, args[1 ], &valuetype));
31- NAPI_ASSERT (env, valuetype == napi_number ,
32- " Wrong type of arguments. Expects a number as second argument." );
22+ NAPI_ASSERT (env, valuetype == napi_string ,
23+ " Wrong type of arguments. Expects a string as second argument." );
3324
3425 NAPI_CALL (env, napi_typeof (env, args[2 ], &valuetype));
35- NAPI_ASSERT (env, valuetype == napi_number,
36- " Wrong type of arguments. Expects a number as third argument." );
37-
38- NAPI_CALL (env, napi_typeof (env, args[3 ], &valuetype));
3926 NAPI_ASSERT (env, valuetype == napi_function,
4027 " Wrong type of arguments. Expects a function as third argument." );
4128
42- struct async_context context;
43- NAPI_CALL (env, napi_get_value_double (env, args[1 ], &context.async_id ));
44- NAPI_CALL (env,
45- napi_get_value_double (env, args[2 ], &context.trigger_async_id ));
29+ napi_async_context context;
30+ NAPI_CALL (env, napi_async_init (env, args[0 ], args[1 ], &context));
4631
4732 napi_callback_scope scope = nullptr ;
4833 NAPI_CALL (
4934 env,
5035 napi_open_callback_scope (env,
5136 args[0 ],
52- reinterpret_cast <napi_async_context>(& context) ,
37+ context,
5338 &scope));
5439
5540 // if the function has an exception pending after the call that is ok
5641 // so we don't use NAPI_CALL as we must close the callback scope regardless
5742 napi_value result = nullptr ;
5843 napi_status function_call_result =
59- napi_call_function (env, args[0 ], args[3 ], 0 , nullptr , &result);
44+ napi_call_function (env, args[0 ], args[2 ], 0 , nullptr , &result);
6045 if (function_call_result != napi_ok) {
6146 GET_AND_THROW_LAST_ERROR ((env));
6247 }
0 commit comments