Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not mutate ipc instances across contexts #23239

Merged
merged 1 commit into from Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 28 additions & 26 deletions lib/renderer/api/ipc-renderer.js
Expand Up @@ -7,31 +7,33 @@ 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);
};

ipcRenderer.invoke = function (channel, ...args) {
return ipc.invoke(channel, args).then(({ error, result }) => {
if (error) { throw new Error(`Error invoking remote method '${channel}': ${error}`); }
return result;
});
};
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);
};

ipcRenderer.invoke = function (channel, ...args) {
return ipc.invoke(channel, args).then(({ error, result }) => {
if (error) { throw new Error(`Error invoking remote method '${channel}': ${error}`); }
return result;
});
};
}

module.exports = ipcRenderer;
26 changes: 14 additions & 12 deletions lib/renderer/ipc-renderer-internal.ts
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);
};
}