Merge pull request #9252 from electron/convert-to-string-in-render-process

Convert alert/confirm arguments to strings in render process
This commit is contained in:
Kevin Sawicki 2017-04-24 09:26:00 -07:00 committed by GitHub
commit 2e223288d2
2 changed files with 26 additions and 2 deletions

View file

@ -121,11 +121,11 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => {
} }
window.alert = function (message, title) { 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) { 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(). // But we do not support prompt().

View file

@ -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/)
})
})
}) })