Convert targetOrigin to string in render process
authorKevin Sawicki <kevinsawicki@gmail.com>
Tue, 25 Apr 2017 20:26:47 +0000 (13:26 -0700)
committerKevin Sawicki <kevinsawicki@gmail.com>
Wed, 26 Apr 2017 16:08:47 +0000 (09:08 -0700)
lib/renderer/window-setup.js
spec/chromium-spec.js

index 0bd43fb..87a31f0 100644 (file)
@@ -32,6 +32,9 @@ const resolveURL = function (url) {
   return a.href
 }
 
+// Use this method to ensure value expected as string in the main process
+// are convertible to string in the renderer process. This ensures exceptions
+// converting values to string are thrown in this process.
 const toString = (value) => {
   return value != null ? `${value}` : value
 }
@@ -86,7 +89,7 @@ function BrowserWindowProxy (ipcRenderer, guestId) {
   }
 
   this.postMessage = (message, targetOrigin) => {
-    ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', guestId, message, targetOrigin, window.location.origin)
+    ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', guestId, message, toString(targetOrigin), window.location.origin)
   }
 
   this.eval = (...args) => {
index dd992dc..b0ae69a 100644 (file)
@@ -548,6 +548,14 @@ describe('chromium feature', function () {
       })
       b = window.open('file://' + fixtures + '/pages/window-open-postMessage.html', '', 'show=no')
     })
+
+    it('throws an exception when the targetOrigin cannot be converted to a string', function () {
+      var b = window.open('')
+      assert.throws(function () {
+        b.postMessage('test', {toString: null})
+      }, /Cannot convert object to primitive value/)
+      b.close()
+    })
   })
 
   describe('window.opener.postMessage', function () {