fix: out-of-scope Local handle in node::CallbackScope (#43640)
refactor: use an EscapableHandleScope Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
12ce546ded
commit
511dece7ff
1 changed files with 11 additions and 13 deletions
|
@ -13,15 +13,14 @@ v8::Local<v8::Value> CallMethodWithArgs(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> obj,
|
v8::Local<v8::Object> obj,
|
||||||
const char* method,
|
const char* method,
|
||||||
ValueVector* args) {
|
ValueVector* args) {
|
||||||
// An active node::Environment is required for node::MakeCallback.
|
v8::EscapableHandleScope handle_scope{isolate};
|
||||||
std::unique_ptr<node::CallbackScope> callback_scope;
|
|
||||||
if (node::Environment::GetCurrent(isolate)) {
|
// CallbackScope and MakeCallback both require an active node::Environment
|
||||||
v8::HandleScope handle_scope(isolate);
|
if (!node::Environment::GetCurrent(isolate))
|
||||||
callback_scope = std::make_unique<node::CallbackScope>(
|
return handle_scope.Escape(v8::Boolean::New(isolate, false));
|
||||||
isolate, v8::Object::New(isolate), node::async_context{0, 0});
|
|
||||||
} else {
|
node::CallbackScope callback_scope{isolate, v8::Object::New(isolate),
|
||||||
return v8::Boolean::New(isolate, false);
|
node::async_context{0, 0}};
|
||||||
}
|
|
||||||
|
|
||||||
// Perform microtask checkpoint after running JavaScript.
|
// Perform microtask checkpoint after running JavaScript.
|
||||||
gin_helper::MicrotasksScope microtasks_scope{
|
gin_helper::MicrotasksScope microtasks_scope{
|
||||||
|
@ -36,11 +35,10 @@ v8::Local<v8::Value> CallMethodWithArgs(v8::Isolate* isolate,
|
||||||
// of MakeCallback will be empty and therefore ToLocal will be false, in this
|
// of MakeCallback will be empty and therefore ToLocal will be false, in this
|
||||||
// case we need to return "false" as that indicates that the event emitter did
|
// case we need to return "false" as that indicates that the event emitter did
|
||||||
// not handle the event
|
// not handle the event
|
||||||
v8::Local<v8::Value> localRet;
|
if (v8::Local<v8::Value> localRet; ret.ToLocal(&localRet))
|
||||||
if (ret.ToLocal(&localRet))
|
return handle_scope.Escape(localRet);
|
||||||
return localRet;
|
|
||||||
|
|
||||||
return v8::Boolean::New(isolate, false);
|
return handle_scope.Escape(v8::Boolean::New(isolate, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gin_helper::internal
|
} // namespace gin_helper::internal
|
||||||
|
|
Loading…
Reference in a new issue