refactor: add static ReplyChannel::SendError() helper (#49338)

* refactor: add static void ReplyChannel::SendError()

* refactor: use static SendError() instead of instantiating a temporary

* refactor: remove non-static version of SendError()

* refactor: remove redundant callback-is-non-null checks
This commit is contained in:
Charles Kerr
2026-01-12 17:02:58 -06:00
committed by GitHub
parent 409c29b12b
commit ae94cefdba
4 changed files with 55 additions and 40 deletions

View File

@@ -140,31 +140,25 @@ gin_helper::internal::Event* ElectronApiIPCHandlerImpl::MakeIPCEvent(
bool internal,
electron::mojom::ElectronApiIPC::InvokeCallback callback) {
if (!session) {
if (callback) {
// We must always invoke the callback if present.
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
->SendError("Session does not exist");
}
// We must always invoke the callback if present.
gin_helper::internal::ReplyChannel::SendError(isolate, std::move(callback),
"Session does not exist");
return {};
}
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
if (!api_web_contents) {
if (callback) {
// We must always invoke the callback if present.
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
->SendError("WebContents does not exist");
}
// We must always invoke the callback if present.
gin_helper::internal::ReplyChannel::SendError(isolate, std::move(callback),
"WebContents does not exist");
return {};
}
v8::Local<v8::Object> wrapper;
if (!api_web_contents->GetWrapper(isolate).ToLocal(&wrapper)) {
if (callback) {
// We must always invoke the callback if present.
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
->SendError("WebContents was destroyed");
}
// We must always invoke the callback if present.
gin_helper::internal::ReplyChannel::SendError(isolate, std::move(callback),
"WebContents was destroyed");
return {};
}

View File

@@ -159,11 +159,9 @@ gin_helper::internal::Event* ElectronApiSWIPCHandlerImpl::MakeIPCEvent(
bool internal,
electron::mojom::ElectronApiIPC::InvokeCallback callback) {
if (!session) {
if (callback) {
// We must always invoke the callback if present.
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
->SendError("Session does not exist");
}
// We must always invoke the callback if present.
gin_helper::internal::ReplyChannel::SendError(isolate, std::move(callback),
"Session does not exist");
return {};
}