Merge pull request #7209 from electron/remote-function-missing-properties
Guard against missing remote function properties
This commit is contained in:
commit
ea244a5188
3 changed files with 25 additions and 1 deletions
|
@ -161,10 +161,17 @@ const proxyFunctionProperties = function (remoteMemberFunction, metaId, name) {
|
|||
if (loaded) return
|
||||
loaded = true
|
||||
const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_GET', metaId, name)
|
||||
setObjectMembers(remoteMemberFunction, remoteMemberFunction, meta.id, meta.members)
|
||||
if (Array.isArray(meta.members)) {
|
||||
setObjectMembers(remoteMemberFunction, remoteMemberFunction, meta.id, meta.members)
|
||||
}
|
||||
}
|
||||
|
||||
return new Proxy(remoteMemberFunction, {
|
||||
set: (target, property, value, receiver) => {
|
||||
if (property !== 'ref') loadRemoteProperties()
|
||||
target[property] = value
|
||||
return true
|
||||
},
|
||||
get: (target, property, receiver) => {
|
||||
if (!target.hasOwnProperty(property)) loadRemoteProperties()
|
||||
return target[property]
|
||||
|
|
|
@ -69,6 +69,10 @@ describe('ipc module', function () {
|
|||
assert.ok(Object.keys(a.foo).includes('bar'))
|
||||
assert.ok(Object.keys(a.foo).includes('nested'))
|
||||
assert.ok(Object.keys(a.foo).includes('method1'))
|
||||
|
||||
a = remote.require(path.join(fixtures, 'module', 'function-with-missing-properties.js')).setup()
|
||||
assert.equal(a.bar(), true)
|
||||
assert.equal(a.bar.baz, undefined)
|
||||
})
|
||||
|
||||
it('should work with static class members', function () {
|
||||
|
|
13
spec/fixtures/module/function-with-missing-properties.js
vendored
Normal file
13
spec/fixtures/module/function-with-missing-properties.js
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
exports.setup = function () {
|
||||
const foo = {}
|
||||
|
||||
foo.bar = function () {
|
||||
return delete foo.bar.baz && delete foo.bar
|
||||
}
|
||||
|
||||
foo.bar.baz = function () {
|
||||
return 3
|
||||
}
|
||||
|
||||
return foo
|
||||
}
|
Loading…
Reference in a new issue