From 0846294d707972608294b90c5eb9748d0e90b9c7 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:40:13 -0500 Subject: [PATCH] fix: in `Emit()`, don't leak converted Arg `Local` into caller's scope (#43748) fix: Emit() should not leak converted arg handles into caller's HandleScope Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/common/gin_helper/event_emitter_caller.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/shell/common/gin_helper/event_emitter_caller.h b/shell/common/gin_helper/event_emitter_caller.h index b8a0511a0b90..1dc4a2701f89 100644 --- a/shell/common/gin_helper/event_emitter_caller.h +++ b/shell/common/gin_helper/event_emitter_caller.h @@ -44,11 +44,13 @@ v8::Local EmitEvent(v8::Isolate* isolate, v8::Local obj, const StringType& name, Args&&... args) { + v8::EscapableHandleScope scope{isolate}; internal::ValueVector converted_args = { gin::StringToV8(isolate, name), gin::ConvertToV8(isolate, std::forward(args))..., }; - return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args); + return scope.Escape( + internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args)); } // obj.custom_emit(args...) @@ -57,11 +59,12 @@ v8::Local CustomEmit(v8::Isolate* isolate, v8::Local object, const char* custom_emit, Args&&... args) { + v8::EscapableHandleScope scope{isolate}; internal::ValueVector converted_args = { gin::ConvertToV8(isolate, std::forward(args))..., }; - return internal::CallMethodWithArgs(isolate, object, custom_emit, - &converted_args); + return scope.Escape(internal::CallMethodWithArgs(isolate, object, custom_emit, + &converted_args)); } template