Support remote function properties
This commit is contained in:
Родитель
9e4665fbc4
Коммит
d333cc5e38
|
@ -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') {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
function foo() {}
|
||||
foo.bar = 'baz'
|
||||
foo.nested = {
|
||||
prop: 'yes'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
foo: foo
|
||||
|
|
Загрузка…
Ссылка в новой задаче