From: Cheng Zhao Date: Sat, 30 Jan 2016 04:20:28 +0000 (+0800) Subject: Fix "Object has been destroyed" error in "page-title-updated" event X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d16257c2d2ed70b74583bd9bbf9f05e73ef994d;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Fix "Object has been destroyed" error in "page-title-updated" event Close #4249. --- diff --git a/atom/browser/api/lib/browser-window.js b/atom/browser/api/lib/browser-window.js index b71c85a..a9649f8 100644 --- a/atom/browser/api/lib/browser-window.js +++ b/atom/browser/api/lib/browser-window.js @@ -55,14 +55,16 @@ BrowserWindow.prototype._init = function() { })(this)); // Change window title to page title. - this.webContents.on('page-title-updated', (function(_this) { - return function(event, title) { - _this.emit('page-title-updated', event, title); - if (!event.defaultPrevented) { - return _this.setTitle(title); - } - }; - })(this)); + this.webContents.on('page-title-updated', (event, title) => { + // The page-title-updated event is not emitted immediately (see #3645), so + // when the callback is called the BrowserWindow might have been closed. + if (this.isDestroyed()) + return; + // Route the event to BrowserWindow. + this.emit('page-title-updated', event, title); + if (!event.defaultPrevented) + this.setTitle(title); + }); // Sometimes the webContents doesn't get focus when window is shown, so we have // to force focusing on webContents in this case. The safest way is to focus it