зеркало из https://github.com/electron/electron.git
fix: in `Emit()`, don't leak converted Arg `Local<Values>` into caller's scope (#43747)
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 <charles@charleskerr.com>
This commit is contained in:
Родитель
42048ddc57
Коммит
3b29efb232
|
@ -44,11 +44,13 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> obj,
|
v8::Local<v8::Object> obj,
|
||||||
const StringType& name,
|
const StringType& name,
|
||||||
Args&&... args) {
|
Args&&... args) {
|
||||||
|
v8::EscapableHandleScope scope{isolate};
|
||||||
internal::ValueVector converted_args = {
|
internal::ValueVector converted_args = {
|
||||||
gin::StringToV8(isolate, name),
|
gin::StringToV8(isolate, name),
|
||||||
gin::ConvertToV8(isolate, std::forward<Args>(args))...,
|
gin::ConvertToV8(isolate, std::forward<Args>(args))...,
|
||||||
};
|
};
|
||||||
return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args);
|
return scope.Escape(
|
||||||
|
internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args));
|
||||||
}
|
}
|
||||||
|
|
||||||
// obj.custom_emit(args...)
|
// obj.custom_emit(args...)
|
||||||
|
@ -57,11 +59,12 @@ v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> object,
|
v8::Local<v8::Object> object,
|
||||||
const char* custom_emit,
|
const char* custom_emit,
|
||||||
Args&&... args) {
|
Args&&... args) {
|
||||||
|
v8::EscapableHandleScope scope{isolate};
|
||||||
internal::ValueVector converted_args = {
|
internal::ValueVector converted_args = {
|
||||||
gin::ConvertToV8(isolate, std::forward<Args>(args))...,
|
gin::ConvertToV8(isolate, std::forward<Args>(args))...,
|
||||||
};
|
};
|
||||||
return internal::CallMethodWithArgs(isolate, object, custom_emit,
|
return scope.Escape(internal::CallMethodWithArgs(isolate, object, custom_emit,
|
||||||
&converted_args);
|
&converted_args));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче