fix: DCHECK in MessageSync in rare cases (#37439)
This commit is contained in:
parent
9b20b3a722
commit
c3f06ef037
1 changed files with 20 additions and 13 deletions
|
@ -1857,22 +1857,23 @@ class ReplyChannel : public gin::Wrappable<ReplyChannel> {
|
||||||
}
|
}
|
||||||
const char* GetTypeName() override { return "ReplyChannel"; }
|
const char* GetTypeName() override { return "ReplyChannel"; }
|
||||||
|
|
||||||
private:
|
void SendError(const std::string& msg) {
|
||||||
explicit ReplyChannel(InvokeCallback callback)
|
|
||||||
: callback_(std::move(callback)) {}
|
|
||||||
~ReplyChannel() override {
|
|
||||||
if (callback_) {
|
|
||||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
// If there's no current context, it means we're shutting down, so we
|
// If there's no current context, it means we're shutting down, so we
|
||||||
// don't need to send an event.
|
// don't need to send an event.
|
||||||
if (!isolate->GetCurrentContext().IsEmpty()) {
|
if (!isolate->GetCurrentContext().IsEmpty()) {
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
auto message = gin::DataObjectBuilder(isolate)
|
auto message = gin::DataObjectBuilder(isolate).Set("error", msg).Build();
|
||||||
.Set("error", "reply was never sent")
|
|
||||||
.Build();
|
|
||||||
SendReply(isolate, message);
|
SendReply(isolate, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit ReplyChannel(InvokeCallback callback)
|
||||||
|
: callback_(std::move(callback)) {}
|
||||||
|
~ReplyChannel() override {
|
||||||
|
if (callback_)
|
||||||
|
SendError("reply was never sent");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SendReply(v8::Isolate* isolate, v8::Local<v8::Value> arg) {
|
bool SendReply(v8::Isolate* isolate, v8::Local<v8::Value> arg) {
|
||||||
|
@ -1897,8 +1898,14 @@ gin::Handle<gin_helper::internal::Event> WebContents::MakeEventWithSender(
|
||||||
content::RenderFrameHost* frame,
|
content::RenderFrameHost* frame,
|
||||||
electron::mojom::ElectronApiIPC::InvokeCallback callback) {
|
electron::mojom::ElectronApiIPC::InvokeCallback callback) {
|
||||||
v8::Local<v8::Object> wrapper;
|
v8::Local<v8::Object> wrapper;
|
||||||
if (!GetWrapper(isolate).ToLocal(&wrapper))
|
if (!GetWrapper(isolate).ToLocal(&wrapper)) {
|
||||||
|
if (callback) {
|
||||||
|
// We must always invoke the callback if present.
|
||||||
|
ReplyChannel::Create(isolate, std::move(callback))
|
||||||
|
->SendError("WebContents was destroyed");
|
||||||
|
}
|
||||||
return gin::Handle<gin_helper::internal::Event>();
|
return gin::Handle<gin_helper::internal::Event>();
|
||||||
|
}
|
||||||
gin::Handle<gin_helper::internal::Event> event =
|
gin::Handle<gin_helper::internal::Event> event =
|
||||||
gin_helper::internal::Event::New(isolate);
|
gin_helper::internal::Event::New(isolate);
|
||||||
gin_helper::Dictionary dict(isolate, event.ToV8().As<v8::Object>());
|
gin_helper::Dictionary dict(isolate, event.ToV8().As<v8::Object>());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue