From 75b010ce6314c56ec083adfa1a9835e3cfa348ea Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 11 Oct 2016 10:40:05 +1100 Subject: [PATCH] Add sync executeJavaScript test --- lib/renderer/init.js | 2 +- spec/api-browser-window-spec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/renderer/init.js b/lib/renderer/init.js index de5bf35509ab..50250e16926a 100644 --- a/lib/renderer/init.js +++ b/lib/renderer/init.js @@ -48,7 +48,7 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev }) } args.push(responseCallback) - electron.webFrame[method].apply(electron.webFrame, args) + electron.webFrame[method](...args) }) // Process command line arguments. diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index e268af969d99..0ee01e9244bb 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1463,6 +1463,7 @@ describe('browser-window module', function () { describe('window.webContents.executeJavaScript', function () { var expected = 'hello, world!' var code = '(() => "' + expected + '")()' + var asyncCode = '(() => new Promise(r => setTimeout(() => r("' + expected + '"), 500)))()' it('doesnt throw when no calback is provided', function () { const result = ipcRenderer.sendSync('executeJavaScript', code, false) @@ -1477,6 +1478,14 @@ describe('browser-window module', function () { }) }) + it('returns result if the code returns an asyncronous promise', function (done) { + ipcRenderer.send('executeJavaScript', asyncCode, true) + ipcRenderer.once('executeJavaScript-response', function (event, result) { + assert.equal(result, expected) + done() + }) + }) + it('works after page load and during subframe load', function (done) { w.webContents.once('did-finish-load', function () { // initiate a sub-frame load, then try and execute script during it