Merge pull request #7209 from electron/remote-function-missing-properties

Guard against missing remote function properties
This commit is contained in:
Cheng Zhao 2016-09-16 21:11:12 +09:00 коммит произвёл GitHub
Родитель 69d4cac760 eef42770c6
Коммит ea244a5188
3 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@ -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 поставляемый 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
}