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

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

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]
2026-01-14 09:34:28 +01:00
committed by GitHub
parent 8cc201e02c
commit c897602202
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 {};
}