mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user