| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent af32d43 commit 17ab5ae
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,17 +6,33 @@ | |||
| 6 | 6 | static void Finalize(napi_env env, void* data, void* hint) { | |
| 7 | 7 | napi_value global, set_timeout; | |
| 8 | 8 | napi_ref* ref = data; | |
| 9 | + | ||
| 10 | + NODE_API_NOGC_ASSERT_RETURN_VOID( | ||
| 11 | + napi_delete_reference(env, *ref) == napi_ok, | ||
| 12 | + "deleting reference in finalizer should succeed"); | ||
| 13 | + NODE_API_NOGC_ASSERT_RETURN_VOID( | ||
| 14 | + napi_get_global(env, &global) == napi_ok, | ||
| 15 | + "getting global reference in finalizer should succeed"); | ||
| 16 | + napi_status result = | ||
| 17 | + napi_get_named_property(env, global, "setTimeout", &set_timeout); | ||
| 18 | + | ||
| 19 | + // The finalizer could be invoked either from check callbacks (as native | ||
| 20 | + // immediates) if the event loop is still running (where napi_ok is returned) | ||
| 21 | + // or during environment shutdown (where napi_cannot_run_js or | ||
| 22 | + // napi_pending_exception is returned). This is not deterministic from | ||
| 23 | + // the point of view of the addon. | ||
| 24 | + | ||
| 9 | 25 | #ifdef NAPI_EXPERIMENTAL | |
| 10 | - napi_status expected_status = napi_cannot_run_js; | ||
| 26 | + NODE_API_NOGC_ASSERT_RETURN_VOID( | ||
| 27 | + result == napi_cannot_run_js || result == napi_ok, | ||
| 28 | + "getting named property from global in finalizer should succeed " | ||
| 29 | + "or return napi_cannot_run_js"); | ||
| 11 | 30 | #else | |
| 12 | - napi_status expected_status = napi_pending_exception; | ||
| 31 | + NODE_API_NOGC_ASSERT_RETURN_VOID( | ||
| 32 | + result == napi_pending_exception || result == napi_ok, | ||
| 33 | + "getting named property from global in finalizer should succeed " | ||
| 34 | + "or return napi_pending_exception"); | ||
| 13 | 35 | #endif // NAPI_EXPERIMENTAL | |
| 14 | - | ||
| 15 | - if (napi_delete_reference(env, *ref) != napi_ok) abort(); | ||
| 16 | - if (napi_get_global(env, &global) != napi_ok) abort(); | ||
| 17 | - if (napi_get_named_property(env, global, "setTimeout", &set_timeout) != | ||
| 18 | - expected_status) | ||
| 19 | - abort(); | ||
| 20 | 36 | free(ref); | |
| 21 | 37 | } | |
| 22 | 38 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,4 @@ | |||
| 1 | 1 | [true] | |
| 2 | - js-native-api/test_cannot_run_js/test: PASS,FLAKY | ||
| 3 | 2 | ||
| 4 | 3 | [$mode==debug] | |
| 5 | 4 | async-hooks/test-callback-error: SLOW | |
| Back | FazBrowse Home | New Git URL |
0 commit comments