Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix unreliable assumption in js-native-api/test_cannot_run_js #111

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions packages/test/runjs/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ void free(void* p);
static void Finalize(napi_env env, void* data, void* hint) {
napi_value global, set_timeout;
napi_ref* ref = data;

NODE_API_NOGC_ASSERT_RETURN_VOID(
napi_delete_reference(env, *ref) == napi_ok,
"deleting reference in finalizer should succeed");
NODE_API_NOGC_ASSERT_RETURN_VOID(
napi_get_global(env, &global) == napi_ok,
"getting global reference in finalizer should succeed");
napi_status result =
napi_get_named_property(env, global, "setTimeout", &set_timeout);

// The finalizer could be invoked either from check callbacks (as native
// immediates) if the event loop is still running (where napi_ok is returned)
// or during environment shutdown (where napi_cannot_run_js or
// napi_pending_exception is returned). This is not deterministic from
// the point of view of the addon.
#ifdef NAPI_EXPERIMENTAL
napi_status expected_status = napi_cannot_run_js;
NODE_API_NOGC_ASSERT_RETURN_VOID(
result == napi_cannot_run_js || result == napi_ok,
"getting named property from global in finalizer should succeed "
"or return napi_cannot_run_js");
#else
napi_status expected_status = napi_pending_exception;
NODE_API_NOGC_ASSERT_RETURN_VOID(
result == napi_pending_exception || result == napi_ok,
"getting named property from global in finalizer should succeed "
"or return napi_pending_exception");
#endif // NAPI_EXPERIMENTAL

if (napi_delete_reference(env, *ref) != napi_ok) abort();
if (napi_get_global(env, &global) != napi_ok) abort();
if (napi_get_named_property(env, global, "setTimeout", &set_timeout) !=
expected_status)
abort();
free(ref);
}

Expand Down
Loading