From aaca9011aeca080743ec6c65fcd68373102f3e16 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 29 Jul 2019 13:54:37 -0700 Subject: [PATCH] fix: [wc|bw]-created events do not emit an event object (#19465) * fix: emit real Event instead of empty object in [wc|bw] * chore: add ability to emit empty events --- lib/browser/api/browser-window.js | 3 ++- lib/browser/api/web-contents.js | 3 ++- shell/browser/api/atom_api_event.cc | 5 +++++ shell/browser/api/event_emitter.cc | 7 +++++++ shell/browser/api/event_emitter.h | 1 + 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index 05fe450786d1..939124633be7 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -82,7 +82,8 @@ BrowserWindow.prototype._init = function () { } // Notify the creation of the window. - app.emit('browser-window-created', {}, this) + const event = process.electronBinding('event').createEmpty() + app.emit('browser-window-created', event, this) Object.defineProperty(this, 'devToolsWebContents', { enumerable: true, diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index f7b8997a2098..8f1be8bfddd3 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -413,7 +413,8 @@ WebContents.prototype._init = function () { }) } - app.emit('web-contents-created', {}, this) + const event = process.electronBinding('event').createEmpty() + app.emit('web-contents-created', event, this) } // Deprecations diff --git a/shell/browser/api/atom_api_event.cc b/shell/browser/api/atom_api_event.cc index c2e871438613..966e6925112d 100644 --- a/shell/browser/api/atom_api_event.cc +++ b/shell/browser/api/atom_api_event.cc @@ -13,12 +13,17 @@ v8::Local CreateWithSender(v8::Isolate* isolate, return mate::internal::CreateJSEvent(isolate, sender, nullptr, base::nullopt); } +v8::Local CreateEmpty(v8::Isolate* isolate) { + return mate::internal::CreateEmptyJSEvent(isolate); +} + void Initialize(v8::Local exports, v8::Local unused, v8::Local context, void* priv) { mate::Dictionary dict(context->GetIsolate(), exports); dict.SetMethod("createWithSender", &CreateWithSender); + dict.SetMethod("createEmpty", &CreateEmpty); } } // namespace diff --git a/shell/browser/api/event_emitter.cc b/shell/browser/api/event_emitter.cc index c5ea6d04df73..50d3914fbbb2 100644 --- a/shell/browser/api/event_emitter.cc +++ b/shell/browser/api/event_emitter.cc @@ -67,6 +67,13 @@ v8::Local CreateJSEvent( return event; } +v8::Local CreateEmptyJSEvent(v8::Isolate* isolate) { + mate::Handle native_event = mate::Event::Create(isolate); + v8::Local event = + v8::Local::Cast(native_event.ToV8()); + return event; +} + v8::Local CreateCustomEvent(v8::Isolate* isolate, v8::Local object, v8::Local custom_event) { diff --git a/shell/browser/api/event_emitter.h b/shell/browser/api/event_emitter.h index ac39ee21c8bd..d548f7052c3c 100644 --- a/shell/browser/api/event_emitter.h +++ b/shell/browser/api/event_emitter.h @@ -28,6 +28,7 @@ v8::Local CreateJSEvent( content::RenderFrameHost* sender, base::Optional callback); +v8::Local CreateEmptyJSEvent(v8::Isolate* isolate); v8::Local CreateCustomEvent(v8::Isolate* isolate, v8::Local object, v8::Local event);