From d4d26cde0c6e91fad9e499a8ac41d008893f41ee Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 1 Sep 2025 17:28:20 +0200 Subject: [PATCH] src: store `Local` for `CallbackScope` on stack This is a requirement of the V8 API, but requires a separate semver-major change (as it is ABI-breaking) to address. (There's also a similar requirement for `napi_open_callback_scope` that would not be easily addressable without breaking ABI compatibility there as well. In real-world situations, it seems extremely unlikely that the `CallbackScope` would be the only reference to the resource object.) --- src/api/callback.cc | 8 ++++---- src/node.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/callback.cc b/src/api/callback.cc index 3436bb4d798ecb..7c8a0434460956 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -26,10 +26,10 @@ CallbackScope::CallbackScope(Isolate* isolate, CallbackScope::CallbackScope(Environment* env, Local object, async_context asyncContext) - : private_(new InternalCallbackScope(env, - object, - asyncContext)), - try_catch_(env->isolate()) { + : resource_storage_(object), + private_( + new InternalCallbackScope(env, &resource_storage_, asyncContext)), + try_catch_(env->isolate()) { try_catch_.SetVerbose(true); } diff --git a/src/node.h b/src/node.h index b17131d6e6b766..c0a4f1331c1150 100644 --- a/src/node.h +++ b/src/node.h @@ -1452,6 +1452,8 @@ class NODE_EXTERN CallbackScope { CallbackScope(CallbackScope&&) = delete; private: + void* reserved_; + v8::Local resource_storage_; InternalCallbackScope* private_; v8::TryCatch try_catch_; };