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.)

PR-URL: https://github.com/nodejs/node/pull/59705
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
Anna Henningsen authored and GitHub committed 2025-09-09 15:00:42 +00:00
1 parent d58343ec48
commit 234c26cca3
2 files changed
+6 -4

No files matched your search

+4 -4
View File
@@ -26,10 +26,10 @@ CallbackScope::CallbackScope(Isolate* isolate,
CallbackScope::CallbackScope(Environment* env,
Local<Object> 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);
}
+2
View File
@@ -1452,6 +1452,8 @@ class NODE_EXTERN CallbackScope {
CallbackScope(CallbackScope&&) = delete;
private:
void* reserved_;
v8::Local<v8::Object> resource_storage_;
InternalCallbackScope* private_;
v8::TryCatch try_catch_;
};