Handle exceptions in NAPI finalizers as uncaught exceptions

This commit is contained in:
Kai Tamkun
2024-11-01 16:36:01 -07:00
parent a1c4240940
commit f15059face
2 changed files with 5 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ void NapiFinalizer::call(napi_env env, void* data)
{
if (m_callback) {
NAPI_LOG_CURRENT_FUNCTION;
napi_enqueue_finalizer(env, this->m_callback, data, this->m_hint);
napi_enqueue_finalizer(env, m_callback, data, m_hint);
}
}

View File

@@ -1434,11 +1434,14 @@ pub const Finalizer = struct {
pub const Queue = std.fifo.LinearFifo(Finalizer, .Dynamic);
pub fn drain(this: *Finalizer.Queue) void {
while (this.readItem()) |*finalizer| {
while (this.readItem()) |finalizer| {
const env = finalizer.env.?;
const handle_scope = NapiHandleScope.open(env, false);
defer if (handle_scope) |scope| scope.close(env);
finalizer.fun.?(env, finalizer.data, finalizer.hint);
if (env.toJS().tryTakeException()) |exception| {
_ = env.toJS().bunVM().uncaughtException(env.toJS(), exception, false);
}
}
}