refactor: avoid deprecated v8::Context::GetIsolate() calls (pt 2) (#47896)

* refactor: add a v8::Isolate* arg to Constructible::GetConstructor()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add a v8::Isolate* arg to NodeBindings::Initialize()

This is needed for the GetConstructor() call

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: avoid v8::Context::GetIsolate() call in GetIpcObject() by taking it as an arg

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: avoid v8::Context::GetIsolate() call in ipc_native::EmitIPCEvent() by taking it as an arg

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

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:
trop[bot] 2025-07-29 10:34:18 -04:00 committed by GitHub
commit e1e12318e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 42 additions and 36 deletions

View file

@ -19,8 +19,8 @@ namespace {
constexpr std::string_view kIpcKey = "ipcNative";
// Gets the private object under kIpcKey
v8::Local<v8::Object> GetIpcObject(const v8::Local<v8::Context>& context) {
auto* isolate = context->GetIsolate();
v8::Local<v8::Object> GetIpcObject(v8::Isolate* const isolate,
const v8::Local<v8::Context>& context) {
auto binding_key = gin::StringToV8(isolate, kIpcKey);
auto private_binding_key = v8::Private::ForApi(isolate, binding_key);
auto global_object = context->Global();
@ -33,13 +33,13 @@ v8::Local<v8::Object> GetIpcObject(const v8::Local<v8::Context>& context) {
return value->ToObject(context).ToLocalChecked();
}
void InvokeIpcCallback(const v8::Local<v8::Context>& context,
void InvokeIpcCallback(v8::Isolate* const isolate,
const v8::Local<v8::Context>& context,
const std::string& callback_name,
std::vector<v8::Local<v8::Value>> args) {
TRACE_EVENT0("devtools.timeline", "FunctionCall");
auto* isolate = context->GetIsolate();
auto ipcNative = GetIpcObject(context);
auto ipcNative = GetIpcObject(isolate, context);
if (ipcNative.IsEmpty())
return;
@ -62,13 +62,12 @@ void InvokeIpcCallback(const v8::Local<v8::Context>& context,
} // namespace
void EmitIPCEvent(const v8::Local<v8::Context>& context,
void EmitIPCEvent(v8::Isolate* const isolate,
const v8::Local<v8::Context>& context,
bool internal,
const std::string& channel,
std::vector<v8::Local<v8::Value>> ports,
v8::Local<v8::Value> args) {
auto* isolate = context->GetIsolate();
v8::HandleScope handle_scope(isolate);
v8::Context::Scope context_scope(context);
v8::MicrotasksScope script_scope(isolate, context->GetMicrotaskQueue(),
@ -78,7 +77,7 @@ void EmitIPCEvent(const v8::Local<v8::Context>& context,
gin::ConvertToV8(isolate, internal), gin::ConvertToV8(isolate, channel),
gin::ConvertToV8(isolate, ports), args};
InvokeIpcCallback(context, "onMessage", argv);
InvokeIpcCallback(isolate, context, "onMessage", argv);
}
} // namespace electron::ipc_native