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 2025-09-09 17:00:42 +02:00 committed by GitHub
parent d58343ec48
commit 234c26cca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -26,9 +26,9 @@ CallbackScope::CallbackScope(Isolate* isolate,
CallbackScope::CallbackScope(Environment* env,
Local<Object> object,
async_context asyncContext)
: private_(new InternalCallbackScope(env,
object,
asyncContext)),
: resource_storage_(object),
private_(
new InternalCallbackScope(env, &resource_storage_, asyncContext)),
try_catch_(env->isolate()) {
try_catch_.SetVerbose(true);
}

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_;
};