Skip to content

Commit 234c26c

Browse files
authored
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: #59705 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent d58343e commit 234c26c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/api/callback.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ CallbackScope::CallbackScope(Isolate* isolate,
2626
CallbackScope::CallbackScope(Environment* env,
2727
Local<Object> object,
2828
async_context asyncContext)
29-
: private_(new InternalCallbackScope(env,
30-
object,
31-
asyncContext)),
32-
try_catch_(env->isolate()) {
29+
: resource_storage_(object),
30+
private_(
31+
new InternalCallbackScope(env, &resource_storage_, asyncContext)),
32+
try_catch_(env->isolate()) {
3333
try_catch_.SetVerbose(true);
3434
}
3535

src/node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,8 @@ class NODE_EXTERN CallbackScope {
14521452
CallbackScope(CallbackScope&&) = delete;
14531453

14541454
private:
1455+
void* reserved_;
1456+
v8::Local<v8::Object> resource_storage_;
14551457
InternalCallbackScope* private_;
14561458
v8::TryCatch try_catch_;
14571459
};

0 commit comments

Comments
 (0)