Call JSC::VM::notifyNeedTermination on process.exit in a Web Worker (#21962)

### What does this PR do?

Calling `process.exit` inside a Web Worker now immediately notifies the
VM that it needs to terminate. Previously, `napi_call_function` would
return success in a Web Worker even if the JS code called
`process.exit`. Now it'll return `napi_pending_exception`.

### How did you verify your code works?

Ran Node's NAPI tests (`node-api/test_worker_terminate/test.js` now
passes) in addition to our own NAPI tests.
This commit is contained in:
Kai Tamkun
2025-08-18 20:32:46 -07:00
committed by GitHub
parent d1562a7670
commit 67e44e25e8
2 changed files with 5 additions and 1 deletions

View File

@@ -2763,6 +2763,10 @@ extern "C" napi_status napi_call_function(napi_env env, napi_value recv,
JSValue res = AsyncContextFrame::call(globalObject, funcValue, thisValue, args);
if (env->isVMTerminating()) {
return napi_set_last_error(env, napi_pending_exception);
}
if (result) {
if (res.isEmpty()) {
*result = toNapi(JSC::jsUndefined(), globalObject);

View File

@@ -555,7 +555,7 @@ pub fn notifyNeedTermination(this: *WebWorker) callconv(.c) void {
if (this.vm) |vm| {
vm.eventLoop().wakeup();
// TODO(@190n) notifyNeedTermination
vm.global.requestTermination();
}
// TODO(@190n) delete