Merge pull request #9097 from electron/handle-setter-errors

Surface errors setting remote properties
This commit is contained in:
Kevin Sawicki 2017-04-03 13:30:39 -07:00 committed by GitHub
commit 7860ea0227
3 changed files with 29 additions and 1 deletions

View file

@ -139,7 +139,12 @@ const setObjectMembers = function (ref, object, metaId, members) {
// Only set setter when it is writable.
if (member.writable) {
descriptor.set = function (value) {
ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_SET', metaId, member.name, value)
const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_SET', metaId, member.name, value)
// Meta will be non-null when a setter error occurred so parse it
// to a value so it gets re-thrown.
if (meta != null) {
metaToValue(meta)
}
return value
}
}

View file

@ -187,6 +187,18 @@ describe('ipc module', function () {
property.property = 1127
})
it('rethrows errors getting/setting properties', function () {
const foo = remote.require(path.join(fixtures, 'module', 'error-properties.js'))
assert.throws(function () {
foo.bar
}, /getting error/)
assert.throws(function () {
foo.bar = 'test'
}, /setting error/)
})
it('can construct an object from its member', function () {
var call = remote.require(path.join(fixtures, 'module', 'call.js'))
var obj = new call.constructor()

View file

@ -0,0 +1,11 @@
class Foo {
set bar (value) {
throw new Error('setting error')
}
get bar () {
throw new Error('getting error')
}
}
module.exports = new Foo()