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
|
catch e
|
||||||
event.result = errorToMeta 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) ->
|
ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, args) ->
|
||||||
try
|
try
|
||||||
args = unwrapArgs processId, routingId, args
|
args = unwrapArgs processId, routingId, args
|
||||||
|
|
|
@ -58,10 +58,17 @@ metaToValue = (meta) ->
|
||||||
for member in meta.members
|
for member in meta.members
|
||||||
do (member) ->
|
do (member) ->
|
||||||
if member.type is 'function'
|
if member.type is 'function'
|
||||||
ret[member.name] = ->
|
ret[member.name] =
|
||||||
# Call member function.
|
class RemoteMemberFunction
|
||||||
ret = ipc.sendChannelSync 'ATOM_BROWSER_MEMBER_CALL', meta.id, member.name, wrapArgs(arguments)
|
constructor: ->
|
||||||
metaToValue ret
|
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
|
else
|
||||||
ret.__defineSetter__ member.name, (value) ->
|
ret.__defineSetter__ member.name, (value) ->
|
||||||
# Set member data.
|
# Set member data.
|
||||||
|
|
|
@ -35,6 +35,11 @@ describe 'ipc', ->
|
||||||
# Restore.
|
# Restore.
|
||||||
property.property = 1127
|
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', ->
|
describe 'remote value in browser', ->
|
||||||
it 'keeps its constructor name for objects', ->
|
it 'keeps its constructor name for objects', ->
|
||||||
buf = new Buffer('test')
|
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) {
|
exports.call = function(func) {
|
||||||
return func();
|
return func();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.constructor = function() {
|
||||||
|
this.test = 'test';
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue