Merge pull request #4281 from atom/fix-object-destroyed
Fix the occasional `Object has been destroyed` exception in the main process
This commit is contained in:
commit
11e2058136
2 changed files with 12 additions and 10 deletions
|
@ -55,14 +55,16 @@ BrowserWindow.prototype._init = function() {
|
||||||
})(this));
|
})(this));
|
||||||
|
|
||||||
// Change window title to page title.
|
// Change window title to page title.
|
||||||
this.webContents.on('page-title-updated', (function(_this) {
|
this.webContents.on('page-title-updated', (event, title) => {
|
||||||
return function(event, title) {
|
// The page-title-updated event is not emitted immediately (see #3645), so
|
||||||
_this.emit('page-title-updated', event, title);
|
// when the callback is called the BrowserWindow might have been closed.
|
||||||
if (!event.defaultPrevented) {
|
if (this.isDestroyed())
|
||||||
return _this.setTitle(title);
|
return;
|
||||||
}
|
// Route the event to BrowserWindow.
|
||||||
};
|
this.emit('page-title-updated', event, title);
|
||||||
})(this));
|
if (!event.defaultPrevented)
|
||||||
|
this.setTitle(title);
|
||||||
|
});
|
||||||
|
|
||||||
// Sometimes the webContents doesn't get focus when window is shown, so we have
|
// 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
|
// to force focusing on webContents in this case. The safest way is to focus it
|
||||||
|
|
|
@ -162,12 +162,12 @@ var unwrapArgs = function(sender, args) {
|
||||||
});
|
});
|
||||||
|
|
||||||
let callIntoRenderer = function(...args) {
|
let callIntoRenderer = function(...args) {
|
||||||
if (rendererReleased)
|
if (rendererReleased || sender.isDestroyed())
|
||||||
throw new Error(`Attempting to call a function in a renderer window that has been closed or released. Function provided here: ${meta.location}.`);
|
throw new Error(`Attempting to call a function in a renderer window that has been closed or released. Function provided here: ${meta.location}.`);
|
||||||
sender.send('ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(sender, args));
|
sender.send('ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(sender, args));
|
||||||
};
|
};
|
||||||
v8Util.setDestructor(callIntoRenderer, function() {
|
v8Util.setDestructor(callIntoRenderer, function() {
|
||||||
if (!rendererReleased)
|
if (!rendererReleased && !sender.isDestroyed())
|
||||||
sender.send('ATOM_RENDERER_RELEASE_CALLBACK', meta.id);
|
sender.send('ATOM_RENDERER_RELEASE_CALLBACK', meta.id);
|
||||||
});
|
});
|
||||||
sender.callbacks.set(meta.id, callIntoRenderer);
|
sender.callbacks.set(meta.id, callIntoRenderer);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue