diff --git a/browser/atom/rpc_server.coffee b/browser/atom/rpc_server.coffee index c1fd0d434795..aa492e7c9d4b 100644 --- a/browser/atom/rpc_server.coffee +++ b/browser/atom/rpc_server.coffee @@ -2,6 +2,15 @@ ipc = require 'ipc' path = require 'path' objectsRegistry = require './objects_registry.js' +metaToArgs = (metas) -> + metas.map (meta) -> + if meta.type is 'value' + meta.value + else if meta.type is 'remoteObject' + objectsRegistry.get meta.id + else + throw new TypeError("Unknown type: #{meta.type}") + # Convert a real value into a POD structure which carries information of this # value. class Meta @@ -58,6 +67,7 @@ ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, processId, routingId) -> ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, processId, routingId, id, args) -> try + args = metaToArgs args constructor = objectsRegistry.get id # Call new with array of arguments. # http://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible @@ -68,6 +78,7 @@ ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, processId, routingId, id, args) -> ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) -> try + args = metaToArgs args func = objectsRegistry.get id ret = func.apply global, args event.result = new Meta(processId, routingId, ret) @@ -76,6 +87,7 @@ ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) -> ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, args) -> try + args = metaToArgs args obj = objectsRegistry.get id ret = obj[method].apply(obj, args) event.result = new Meta(processId, routingId, ret) diff --git a/renderer/api/lib/remote.coffee b/renderer/api/lib/remote.coffee index 3cdcb3f3d72e..8fbccc4128a3 100644 --- a/renderer/api/lib/remote.coffee +++ b/renderer/api/lib/remote.coffee @@ -1,6 +1,19 @@ ipc = require 'ipc' v8_util = process.atomBinding 'v8_util' +# Transform the arguments passed to browser into list of descriptions. +# +# This function assumes an array is passed, and it only converts remote objects +# and functions, other types of values are passed as it is. +argsToMeta = (args) -> + args.map (value) -> + if typeof value is 'object' and v8_util.getHiddenValue value, 'isRemoteObject' + type: 'remoteObject', id: value.id + else if typeof value is 'function' + throw new TypeError('functions is not supported yet') + else + type: 'value', value: value + # Transform the description of value into a value or delegate object. metaToValue = (meta) -> switch meta.type @@ -51,6 +64,9 @@ metaToValue = (meta) -> v8_util.setDestructor ret, -> ipc.sendChannel 'ATOM_BROWSER_DEREFERENCE', meta.storeId + # Mark this is a remote object. + v8_util.setHiddenValue ret, 'isRemoteObject', true + ret # Release all resources of current render view when it's going to be unloaded.