mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
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:
@@ -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().
|
||||
|
||||
@@ -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/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user