Enable creating object from remote object's member.
This commit is contained in:
parent
c86acc4cd7
commit
9e16e41bb3
4 changed files with 30 additions and 4 deletions
|
@ -104,6 +104,16 @@ ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) ->
|
|||
catch e
|
||||
event.result = errorToMeta e
|
||||
|
||||
ipc.on 'ATOM_BROWSER_MEMBER_CONSTRUCTOR', (event, processId, routingId, id, method, args) ->
|
||||
try
|
||||
args = unwrapArgs processId, routingId, args
|
||||
constructor = objectsRegistry.get(id)[method]
|
||||
# Call new with array of arguments.
|
||||
obj = new (Function::bind.apply(constructor, [null].concat(args)))
|
||||
event.result = valueToMeta processId, routingId, obj
|
||||
catch e
|
||||
event.result = errorToMeta e
|
||||
|
||||
ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, args) ->
|
||||
try
|
||||
args = unwrapArgs processId, routingId, args
|
||||
|
|
|
@ -58,10 +58,17 @@ metaToValue = (meta) ->
|
|||
for member in meta.members
|
||||
do (member) ->
|
||||
if member.type is 'function'
|
||||
ret[member.name] = ->
|
||||
# Call member function.
|
||||
ret = ipc.sendChannelSync 'ATOM_BROWSER_MEMBER_CALL', meta.id, member.name, wrapArgs(arguments)
|
||||
metaToValue ret
|
||||
ret[member.name] =
|
||||
class RemoteMemberFunction
|
||||
constructor: ->
|
||||
if @constructor is RemoteMemberFunction
|
||||
# Constructor call.
|
||||
obj = ipc.sendChannelSync 'ATOM_BROWSER_MEMBER_CONSTRUCTOR', meta.id, member.name, wrapArgs(arguments)
|
||||
return metaToValue obj
|
||||
else
|
||||
# Call member function.
|
||||
ret = ipc.sendChannelSync 'ATOM_BROWSER_MEMBER_CALL', meta.id, member.name, wrapArgs(arguments)
|
||||
return metaToValue ret
|
||||
else
|
||||
ret.__defineSetter__ member.name, (value) ->
|
||||
# Set member data.
|
||||
|
|
|
@ -35,6 +35,11 @@ describe 'ipc', ->
|
|||
# Restore.
|
||||
property.property = 1127
|
||||
|
||||
it 'can construct an object from its member', ->
|
||||
call = remote.require path.join(fixtures, 'module', 'call.js')
|
||||
obj = new call.constructor
|
||||
assert.equal obj.test, 'test'
|
||||
|
||||
describe 'remote value in browser', ->
|
||||
it 'keeps its constructor name for objects', ->
|
||||
buf = new Buffer('test')
|
||||
|
|
4
spec/fixtures/module/call.js
vendored
4
spec/fixtures/module/call.js
vendored
|
@ -1,3 +1,7 @@
|
|||
exports.call = function(func) {
|
||||
return func();
|
||||
}
|
||||
|
||||
exports.constructor = function() {
|
||||
this.test = 'test';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue