Skip to content

Commit

Permalink
fix: do not mutate ipc instances across contexts (#23241)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Apr 23, 2020
1 parent dac2137 commit d0a326c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
38 changes: 20 additions & 18 deletions lib/renderer/api/ipc-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ const v8Util = process.electronBinding('v8_util')
const ipcRenderer = v8Util.getHiddenValue(global, 'ipc')
const internal = false

ipcRenderer.send = function (channel, ...args) {
return ipc.send(internal, channel, args)
}

ipcRenderer.sendSync = function (channel, ...args) {
return ipc.sendSync(internal, channel, args)[0]
}

ipcRenderer.sendToHost = function (channel, ...args) {
return ipc.sendToHost(channel, args)
}

ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
return ipc.sendTo(internal, false, webContentsId, channel, args)
}

ipcRenderer.sendToAll = function (webContentsId, channel, ...args) {
return ipc.sendTo(internal, true, webContentsId, channel, args)
if (!ipcRenderer.send) {
ipcRenderer.send = function (channel, ...args) {
return ipc.send(internal, channel, args)
}

ipcRenderer.sendSync = function (channel, ...args) {
return ipc.sendSync(internal, channel, args)[0]
}

ipcRenderer.sendToHost = function (channel, ...args) {
return ipc.sendToHost(channel, args)
}

ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
return ipc.sendTo(internal, false, webContentsId, channel, args)
}

ipcRenderer.sendToAll = function (webContentsId, channel, ...args) {
return ipc.sendTo(internal, true, webContentsId, channel, args)
}
}

module.exports = ipcRenderer
24 changes: 13 additions & 11 deletions lib/renderer/ipc-renderer-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ const v8Util = process.electronBinding('v8_util')
export const ipcRendererInternal: Electron.IpcRendererInternal = v8Util.getHiddenValue(global, 'ipc-internal')
const internal = true

ipcRendererInternal.send = function (channel, ...args) {
return binding.ipc.send(internal, channel, args)
}
if (!ipcRendererInternal.send) {
ipcRendererInternal.send = function (channel, ...args) {
return binding.ipc.send(internal, channel, args)
}

ipcRendererInternal.sendSync = function (channel, ...args) {
return binding.ipc.sendSync(internal, channel, args)[0]
}
ipcRendererInternal.sendSync = function (channel, ...args) {
return binding.ipc.sendSync(internal, channel, args)[0]
}

ipcRendererInternal.sendTo = function (webContentsId, channel, ...args) {
return binding.ipc.sendTo(internal, false, webContentsId, channel, args)
}
ipcRendererInternal.sendTo = function (webContentsId, channel, ...args) {
return binding.ipc.sendTo(internal, false, webContentsId, channel, args)
}

ipcRendererInternal.sendToAll = function (webContentsId, channel, ...args) {
return binding.ipc.sendTo(internal, true, webContentsId, channel, args)
ipcRendererInternal.sendToAll = function (webContentsId, channel, ...args) {
return binding.ipc.sendTo(internal, true, webContentsId, channel, args)
}
}

0 comments on commit d0a326c

Please sign in to comment.