Merge pull request #8049 from electron/prevent-remove-all-ipc
Throw an error when users attempt to remove all listeners from the IPC modules
This commit is contained in:
commit
bbaab755e3
2 changed files with 16 additions and 0 deletions
|
@ -2,5 +2,13 @@ const EventEmitter = require('events').EventEmitter
|
|||
|
||||
module.exports = new EventEmitter()
|
||||
|
||||
const removeAllListeners = module.exports.removeAllListeners
|
||||
module.exports.removeAllListeners = function (...args) {
|
||||
if (args.length === 0) {
|
||||
throw new Error('Removing all listeners from ipcMain will make Electron internals stop working. Please specify a event name')
|
||||
}
|
||||
removeAllListeners.apply(this, args)
|
||||
}
|
||||
|
||||
// Do not throw exception when channel name is "error".
|
||||
module.exports.on('error', () => {})
|
||||
|
|
|
@ -29,4 +29,12 @@ module.exports = function (ipcRenderer, binding) {
|
|||
|
||||
ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', true, webContentsId, channel, ...args)
|
||||
}
|
||||
|
||||
const removeAllListeners = ipcRenderer.removeAllListeners
|
||||
ipcRenderer.removeAllListeners = function (...args) {
|
||||
if (args.length === 0) {
|
||||
throw new Error('Removing all listeners from ipcRenderer will make Electron internals stop working. Please specify a event name')
|
||||
}
|
||||
removeAllListeners.apply(this, args)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue