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

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

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

This is needed for the GetConstructor() call

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

* refactor: avoid v8::Context::GetIsolate() call in ipc_native::EmitIPCEvent() by taking it as an arg
This commit is contained in:
Charles Kerr
2025-07-28 10:22:27 -05:00
committed by GitHub
parent 084c6ef549
commit 2255bb620a
18 changed files with 42 additions and 36 deletions

View File

@@ -98,7 +98,7 @@ void ElectronApiServiceImpl::Message(bool internal,
v8::Local<v8::Value> args = gin::ConvertToV8(isolate, arguments);
ipc_native::EmitIPCEvent(context, internal, channel, {}, args);
ipc_native::EmitIPCEvent(isolate, context, internal, channel, {}, args);
}
void ElectronApiServiceImpl::ReceivePostMessage(
@@ -125,7 +125,7 @@ void ElectronApiServiceImpl::ReceivePostMessage(
std::vector<v8::Local<v8::Value>> args = {message_value};
ipc_native::EmitIPCEvent(context, false, channel, ports,
ipc_native::EmitIPCEvent(isolate, context, false, channel, ports,
gin::ConvertToV8(isolate, args));
}

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

View File

@@ -11,7 +11,8 @@
namespace electron::ipc_native {
void EmitIPCEvent(const v8::Local<v8::Context>& context,
void EmitIPCEvent(v8::Isolate* isolate,
const v8::Local<v8::Context>& context,
bool internal,
const std::string& channel,
std::vector<v8::Local<v8::Value>> ports,

View File

@@ -105,7 +105,7 @@ void ElectronRendererClient::DidCreateScriptContext(
if (!node_integration_initialized_) {
node_integration_initialized_ = true;
node_bindings_->Initialize(renderer_context);
node_bindings_->Initialize(isolate, renderer_context);
node_bindings_->PrepareEmbedThread();
}

View File

@@ -56,7 +56,8 @@ void ServiceWorkerData::Message(bool internal,
v8::Local<v8::Value> args = gin::ConvertToV8(isolate, arguments);
ipc_native::EmitIPCEvent(preload_context, internal, channel, {}, args);
ipc_native::EmitIPCEvent(isolate, preload_context, internal, channel, {},
args);
}
void ServiceWorkerData::ReceivePostMessage(const std::string& channel,