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: optional postMessage transfer arg #32457

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
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_web_frame_main.cc
Expand Up @@ -210,7 +210,7 @@ void WebFrameMain::PostMessage(v8::Isolate* isolate,
}

std::vector<gin::Handle<MessagePort>> wrapped_ports;
if (transfer) {
if (transfer && !transfer.value()->IsUndefined()) {
if (!gin::ConvertFromV8(isolate, *transfer, &wrapped_ports)) {
isolate->ThrowException(v8::Exception::Error(
gin::StringToV8(isolate, "Invalid value for transfer")));
Expand Down
2 changes: 1 addition & 1 deletion shell/renderer/api/electron_api_ipc_renderer.cc
Expand Up @@ -146,7 +146,7 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
}

std::vector<v8::Local<v8::Object>> transferables;
if (transfer) {
if (transfer && !transfer.value()->IsUndefined()) {
if (!gin::ConvertFromV8(isolate, *transfer, &transferables)) {
thrower.ThrowTypeError("Invalid value for transfer");
return;
Expand Down
12 changes: 12 additions & 0 deletions spec-main/api-ipc-spec.ts
Expand Up @@ -216,6 +216,18 @@ describe('ipc module', () => {
expect(port).to.be.an.instanceOf(EventEmitter);
});

it('can sent a message without a transfer', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank');
const p = emittedOnce(ipcMain, 'port');
await w.webContents.executeJavaScript(`(${function () {
require('electron').ipcRenderer.postMessage('port', 'hi');
}})()`);
const [ev, msg] = await p;
expect(msg).to.equal('hi');
expect(ev.ports).to.deep.equal([]);
});

it('can communicate between main and renderer', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank');
Expand Down