Merge pull request #9097 from electron/handle-setter-errors
Surface errors setting remote properties
This commit is contained in:
commit
7860ea0227
3 changed files with 29 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
11
spec/fixtures/module/error-properties.js
vendored
Normal file
11
spec/fixtures/module/error-properties.js
vendored
Normal 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()
|
Loading…
Reference in a new issue