From a00d36fb071be1344396ee90279cb5bbadcf9e0e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 12:19:37 -0700 Subject: [PATCH 1/2] Add spec for alert/confirm toString errors --- spec/chromium-spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 6a5937bbce26..4c5b85521ac2 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -880,4 +880,28 @@ describe('chromium feature', function () { }) }) }) + + describe('window.alert(message, title)', function () { + it('throws an exception when the arguments cannot be converted to strings', function () { + assert.throws(function () { + window.alert({toString: null}) + }, /Cannot convert object to primitive value/) + + assert.throws(function () { + window.alert('message', {toString: 3}) + }, /Cannot convert object to primitive value/) + }) + }) + + describe('window.confirm(message, title)', function () { + it('throws an exception when the arguments cannot be converted to strings', function () { + assert.throws(function () { + window.confirm({toString: null}, 'title') + }, /Cannot convert object to primitive value/) + + assert.throws(function () { + window.confirm('message', {toString: 3}) + }, /Cannot convert object to primitive value/) + }) + }) }) From c90fd4dc888662599a2f13d60eb39849db926abc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 21 Apr 2017 12:21:05 -0700 Subject: [PATCH 2/2] Convert message/title to strings in render process --- lib/renderer/window-setup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/renderer/window-setup.js b/lib/renderer/window-setup.js index 21f0741a22aa..d29133c88f0b 100644 --- a/lib/renderer/window-setup.js +++ b/lib/renderer/window-setup.js @@ -121,11 +121,11 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { } window.alert = function (message, title) { - ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', message, title) + ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', `${message}`, `${title}`) } window.confirm = function (message, title) { - return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', message, title) + return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', `${message}`, `${title}`) } // But we do not support prompt().