Guard against destroyed window or web contents

This commit is contained in:
Kevin Sawicki 2017-01-26 09:56:40 -08:00
parent 515f689814
commit e2e33a8cf0

View file

@ -1668,15 +1668,22 @@ describe('BrowserWindow module', function () {
const showLastDevToolsPanel = () => { const showLastDevToolsPanel = () => {
w.webContents.once('devtools-opened', function () { w.webContents.once('devtools-opened', function () {
showPanelIntervalId = setInterval(function () { showPanelIntervalId = setInterval(function () {
if (w && w.devToolsWebContents) { if (w == null || w.isDestroyed()) {
var showLastPanel = function () { clearInterval(showLastDevToolsPanel)
var lastPanelId = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id return
WebInspector.inspectorView.showPanel(lastPanelId)
}
w.devToolsWebContents.executeJavaScript(`(${showLastPanel})()`)
} else {
clearInterval(showPanelIntervalId)
} }
const {devToolsWebContents} = w
if (devToolsWebContents == null || devToolsWebContents.isDestroyed()) {
clearInterval(showLastDevToolsPanel)
return
}
var showLastPanel = function () {
var lastPanelId = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id
WebInspector.inspectorView.showPanel(lastPanelId)
}
devToolsWebContents.executeJavaScript(`(${showLastPanel})()`)
}, 100) }, 100)
}) })
} }
@ -1770,7 +1777,6 @@ describe('BrowserWindow module', function () {
w.webContents.openDevTools({mode: 'bottom'}) w.webContents.openDevTools({mode: 'bottom'})
ipcMain.once('answer', function (event, message) { ipcMain.once('answer', function (event, message) {
clearInterval(showPanelIntervalId)
assert.equal(message.runtimeId, 'foo') assert.equal(message.runtimeId, 'foo')
done() done()
}) })