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.
|
# Convert array of meta data from renderer into array of real values.
|
||||||
unwrapArgs = (processId, routingId, args) ->
|
unwrapArgs = (processId, routingId, args) ->
|
||||||
args.map (meta) ->
|
metaToValue = (meta) ->
|
||||||
switch meta.type
|
switch meta.type
|
||||||
when 'value' then meta.value
|
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'
|
when 'function'
|
||||||
ret = ->
|
ret = ->
|
||||||
ipc.sendChannel processId, routingId, 'ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(processId, routingId, arguments)
|
ipc.sendChannel processId, routingId, 'ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(processId, routingId, arguments)
|
||||||
|
@ -50,6 +56,8 @@ unwrapArgs = (processId, routingId, args) ->
|
||||||
ret
|
ret
|
||||||
else throw new TypeError("Unknown type: #{meta.type}")
|
else throw new TypeError("Unknown type: #{meta.type}")
|
||||||
|
|
||||||
|
args.map metaToValue
|
||||||
|
|
||||||
ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) ->
|
ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) ->
|
||||||
try
|
try
|
||||||
event.result = valueToMeta processId, routingId, require(module)
|
event.result = valueToMeta processId, routingId, require(module)
|
||||||
|
|
|
@ -7,14 +7,22 @@ callbacksRegistry = new CallbacksRegistry
|
||||||
|
|
||||||
# Convert the arguments object into an array of meta data.
|
# Convert the arguments object into an array of meta data.
|
||||||
wrapArgs = (args) ->
|
wrapArgs = (args) ->
|
||||||
Array::slice.call(args).map (value) ->
|
valueToMeta = (value) ->
|
||||||
if value? and typeof value is 'object' and v8Util.getHiddenValue value, 'atomId'
|
if Array.isArray value
|
||||||
type: 'object', id: v8Util.getHiddenValue value, 'atomId'
|
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'
|
else if typeof value is 'function'
|
||||||
type: 'function', id: callbacksRegistry.add(value)
|
type: 'function', id: callbacksRegistry.add(value)
|
||||||
else
|
else
|
||||||
type: 'value', value: value
|
type: 'value', value: value
|
||||||
|
|
||||||
|
Array::slice.call(args).map valueToMeta
|
||||||
|
|
||||||
# Convert meta data from browser into real value.
|
# Convert meta data from browser into real value.
|
||||||
metaToValue = (meta) ->
|
metaToValue = (meta) ->
|
||||||
switch meta.type
|
switch meta.type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue