Use ES6 template strings, fix docs and remove _ERROR_ IPC event
authorSamuel Attard <samuel.r.attard@gmail.com>
Mon, 24 Oct 2016 07:19:45 +0000 (18:19 +1100)
committerKevin Sawicki <kevinsawicki@gmail.com>
Thu, 3 Nov 2016 16:33:47 +0000 (09:33 -0700)
docs/api/web-contents.md
lib/browser/api/web-contents.js
lib/renderer/init.js
spec/api-browser-window-spec.js

index 367b6b4..4d86808 100644 (file)
@@ -621,7 +621,7 @@ Injects CSS into the current web page.
   * `result` Any
 
 Returns `Promise` - A promise that resolves with the result of the executed code
-or is rejected if the result of the code is a rejected promise
+or is rejected if the result of the code is a rejected promise.
 
 Evaluates `code` in page.
 
index 196f90b..695ec8a 100644 (file)
@@ -112,12 +112,10 @@ const webFrameMethodsWithResult = [
 const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
   return new Promise((resolve, reject) => {
     this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args)
-    ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
-      if (callback) callback(result)
-      resolve(result)
-    })
-    ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_ERROR_${requestId}`, (event, error) => {
-      reject(error)
+    ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, error, result) {
+      if (callback && !error) callback(result)
+      if (error) return reject(error)
+      return resolve(result)
     })
   })
 }
index 202c124..05733f6 100644 (file)
@@ -41,10 +41,10 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev
   const responseCallback = function (result) {
     Promise.resolve(result)
       .then((resolvedResult) => {
-        event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, resolvedResult)
+        event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, null, resolvedResult)
       })
       .catch((resolvedError) => {
-        event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_ERROR_${requestId}`, resolvedError)
+        event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, resolvedError)
       })
   }
   args.push(responseCallback)
index 0f5e168..9bfede2 100644 (file)
@@ -1463,9 +1463,9 @@ describe('browser-window module', function () {
   describe('window.webContents.executeJavaScript', function () {
     var expected = 'hello, world!'
     var expectedErrorMsg = 'woops!'
-    var code = '(() => "' + expected + '")()'
-    var asyncCode = '(() => new Promise(r => setTimeout(() => r("' + expected + '"), 500)))()'
-    var badAsyncCode = '(() => new Promise((r, e) => setTimeout(() => e("' + expectedErrorMsg + '"), 500)))()'
+    var code = `(() => "${expected}")()`
+    var asyncCode = `(() => new Promise(r => setTimeout(() => r("${expected}"), 500)))()`
+    var badAsyncCode = `(() => new Promise((r, e) => setTimeout(() => e("${expectedErrorMsg}"), 500)))()`
 
     it('doesnt throw when no calback is provided', function () {
       const result = ipcRenderer.sendSync('executeJavaScript', code, false)