diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index d240561837e2..b49f152271f9 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -90,6 +90,15 @@ let valueToMeta = function (sender, value, optimizeSimpleObject = false) { meta.id = objectsRegistry.add(sender, value) meta.members = getObjectMembers(value) meta.proto = getObjectPrototype(value) + + // Include properties on member methods + meta.members.forEach((member) => { + if (member.type === 'method') { + const method = value[member.name] + member.id = objectsRegistry.add(sender, method) + member.members = getObjectMembers(method) + } + }) } else if (meta.type === 'buffer') { meta.value = Array.prototype.slice.call(value, 0) } else if (meta.type === 'promise') { diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index 20d8ea574cbf..008b796400fe 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -135,6 +135,12 @@ const setObjectMembers = function (ref, object, metaId, members) { } Object.defineProperty(object, member.name, descriptor) + + // Include properties on member methods + if (member.type === 'method' && member.members != null && member.members.length > 0) { + const method = object[member.name] + setObjectMembers(method, method, member.id, member.members) + } } } diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index 183adb01fc0c..b91e6db21db5 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -61,6 +61,7 @@ describe('ipc module', function () { assert.equal(typeof a, 'object') assert.equal(typeof a.foo, 'function') assert.equal(a.foo.bar, 'baz') + assert.equal(a.foo.nested.prop, 'yes') }) it('should work with static class members', function () { diff --git a/spec/fixtures/module/function-with-properties.js b/spec/fixtures/module/function-with-properties.js index 7623738f5b5d..6cfb5bc8e30c 100644 --- a/spec/fixtures/module/function-with-properties.js +++ b/spec/fixtures/module/function-with-properties.js @@ -1,5 +1,8 @@ function foo() {} foo.bar = 'baz' +foo.nested = { + prop: 'yes' +} module.exports = { foo: foo