Enable passing objects and arrays when calling remote function.
This commit is contained in:
parent
b39df5ea87
commit
2fd91e8c96
2 changed files with 21 additions and 5 deletions
|
@ -38,10 +38,16 @@ errorToMeta = (error) ->
|
|||
|
||||
# Convert array of meta data from renderer into array of real values.
|
||||
unwrapArgs = (processId, routingId, args) ->
|
||||
args.map (meta) ->
|
||||
metaToValue = (meta) ->
|
||||
switch meta.type
|
||||
when 'value' then meta.value
|
||||
when 'object' then objectsRegistry.get meta.id
|
||||
when 'remote-object' then objectsRegistry.get meta.id
|
||||
when 'array' then unwrapArgs processId, routingId, meta.value
|
||||
when 'object'
|
||||
ret = {}
|
||||
for member in meta.members
|
||||
ret[member.name] = metaToValue(member.value)
|
||||
ret
|
||||
when 'function'
|
||||
ret = ->
|
||||
ipc.sendChannel processId, routingId, 'ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(processId, routingId, arguments)
|
||||
|
@ -50,6 +56,8 @@ unwrapArgs = (processId, routingId, args) ->
|
|||
ret
|
||||
else throw new TypeError("Unknown type: #{meta.type}")
|
||||
|
||||
args.map metaToValue
|
||||
|
||||
ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) ->
|
||||
try
|
||||
event.result = valueToMeta processId, routingId, require(module)
|
||||
|
|
|
@ -7,14 +7,22 @@ callbacksRegistry = new CallbacksRegistry
|
|||
|
||||
# Convert the arguments object into an array of meta data.
|
||||
wrapArgs = (args) ->
|
||||
Array::slice.call(args).map (value) ->
|
||||
if value? and typeof value is 'object' and v8Util.getHiddenValue value, 'atomId'
|
||||
type: 'object', id: v8Util.getHiddenValue value, 'atomId'
|
||||
valueToMeta = (value) ->
|
||||
if Array.isArray value
|
||||
type: 'array', value: wrapArgs(value)
|
||||
else if value? and typeof value is 'object' and v8Util.getHiddenValue value, 'atomId'
|
||||
type: 'remote-object', id: v8Util.getHiddenValue value, 'atomId'
|
||||
else if value? and typeof value is 'object'
|
||||
ret = type: 'object', members: []
|
||||
ret.members.push(name: prop, value: valueToMeta(field)) for prop, field of value
|
||||
ret
|
||||
else if typeof value is 'function'
|
||||
type: 'function', id: callbacksRegistry.add(value)
|
||||
else
|
||||
type: 'value', value: value
|
||||
|
||||
Array::slice.call(args).map valueToMeta
|
||||
|
||||
# Convert meta data from browser into real value.
|
||||
metaToValue = (meta) ->
|
||||
switch meta.type
|
||||
|
|
Loading…
Add table
Reference in a new issue