Reference the remote object in its prototype chain's methods
This commit is contained in:
parent
b9ead472a5
commit
39d2b95a33
1 changed files with 8 additions and 7 deletions
|
@ -91,8 +91,9 @@ var wrapArgs = function (args, visited) {
|
|||
}
|
||||
|
||||
// Populate object's members from descriptors.
|
||||
// The |ref| will be kept referenced by |members|.
|
||||
// This matches |getObjectMemebers| in rpc-server.
|
||||
let setObjectMembers = function (object, metaId, members) {
|
||||
let setObjectMembers = function (ref, object, metaId, members) {
|
||||
for (let member of members) {
|
||||
if (object.hasOwnProperty(member.name)) continue
|
||||
|
||||
|
@ -110,7 +111,7 @@ let setObjectMembers = function (object, metaId, members) {
|
|||
}
|
||||
}
|
||||
descriptor.get = function () {
|
||||
remoteMemberFunction.ref = object // The member should reference its object.
|
||||
remoteMemberFunction.ref = ref // The member should reference its object.
|
||||
return remoteMemberFunction
|
||||
}
|
||||
// Enable monkey-patch the method
|
||||
|
@ -139,11 +140,11 @@ let setObjectMembers = function (object, metaId, members) {
|
|||
|
||||
// Populate object's prototype from descriptor.
|
||||
// This matches |getObjectPrototype| in rpc-server.
|
||||
let setObjectPrototype = function (object, metaId, descriptor) {
|
||||
let setObjectPrototype = function (ref, object, metaId, descriptor) {
|
||||
if (descriptor === null) return
|
||||
let proto = {}
|
||||
setObjectMembers(proto, metaId, descriptor.members)
|
||||
setObjectPrototype(proto, metaId, descriptor.proto)
|
||||
setObjectMembers(ref, proto, metaId, descriptor.members)
|
||||
setObjectPrototype(ref, proto, metaId, descriptor.proto)
|
||||
Object.setPrototypeOf(object, proto)
|
||||
}
|
||||
|
||||
|
@ -198,9 +199,9 @@ let metaToValue = function (meta) {
|
|||
}
|
||||
|
||||
// Populate delegate members.
|
||||
setObjectMembers(ret, meta.id, meta.members)
|
||||
setObjectMembers(ret, ret, meta.id, meta.members)
|
||||
// Populate delegate prototype.
|
||||
setObjectPrototype(ret, meta.id, meta.proto)
|
||||
setObjectPrototype(ret, ret, meta.id, meta.proto)
|
||||
|
||||
// Set constructor.name to object's name.
|
||||
Object.defineProperty(ret.constructor, 'name', { value: meta.name })
|
||||
|
|
Loading…
Reference in a new issue