Support remote function properties

This commit is contained in:
Kevin Sawicki 2016-08-16 10:37:51 -07:00
parent 9e4665fbc4
commit d333cc5e38
4 changed files with 19 additions and 0 deletions

View file

@ -90,6 +90,15 @@ let valueToMeta = function (sender, value, optimizeSimpleObject = false) {
meta.id = objectsRegistry.add(sender, value) meta.id = objectsRegistry.add(sender, value)
meta.members = getObjectMembers(value) meta.members = getObjectMembers(value)
meta.proto = getObjectPrototype(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') { } else if (meta.type === 'buffer') {
meta.value = Array.prototype.slice.call(value, 0) meta.value = Array.prototype.slice.call(value, 0)
} else if (meta.type === 'promise') { } else if (meta.type === 'promise') {

View file

@ -135,6 +135,12 @@ const setObjectMembers = function (ref, object, metaId, members) {
} }
Object.defineProperty(object, member.name, descriptor) 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)
}
} }
} }

View file

@ -61,6 +61,7 @@ describe('ipc module', function () {
assert.equal(typeof a, 'object') assert.equal(typeof a, 'object')
assert.equal(typeof a.foo, 'function') assert.equal(typeof a.foo, 'function')
assert.equal(a.foo.bar, 'baz') assert.equal(a.foo.bar, 'baz')
assert.equal(a.foo.nested.prop, 'yes')
}) })
it('should work with static class members', function () { it('should work with static class members', function () {

View file

@ -1,5 +1,8 @@
function foo() {} function foo() {}
foo.bar = 'baz' foo.bar = 'baz'
foo.nested = {
prop: 'yes'
}
module.exports = { module.exports = {
foo: foo foo: foo