diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index a3a4443413d3..3cb99e5b9d65 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -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] diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index b13600160abb..eedab2b24b99 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -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 () { diff --git a/spec/fixtures/module/function-with-missing-properties.js b/spec/fixtures/module/function-with-missing-properties.js new file mode 100644 index 000000000000..d247485a17b6 --- /dev/null +++ b/spec/fixtures/module/function-with-missing-properties.js @@ -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 +}