fix: throw instead of crash when using ipcRenderer after context released (#23917)

This commit is contained in:
Jeremy Apthorp 2020-06-04 16:25:25 -07:00 committed by GitHub
parent 491caf59c1
commit a1c55a13e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 1 deletions

View file

@ -9,7 +9,7 @@ describe('ipcRenderer module', () => {
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, nativeWindowOpen: true } });
await w.loadURL('about:blank');
});
after(async () => {
@ -182,4 +182,25 @@ describe('ipcRenderer module', () => {
expect(result).to.deep.equal([]);
});
});
describe('after context is released', () => {
it('throws an exception', async () => {
const error = await w.webContents.executeJavaScript(`(${() => {
const child = window.open('', 'child', 'show=no,nodeIntegration=yes')! as any;
const childIpc = child.require('electron').ipcRenderer;
child.close();
return new Promise(resolve => {
setTimeout(() => {
try {
childIpc.send('hello');
} catch (e) {
resolve(e);
}
resolve(false);
}, 100);
});
}})()`);
expect(error).to.have.property('message', 'IPC method called after context was released');
});
});
});