Add remote.getObject API to get object in browser by it's ID.
This commit is contained in:
parent
d4d1230107
commit
cc921fed1e
4 changed files with 38 additions and 16 deletions
|
@ -14,7 +14,6 @@ class PlainObject
|
|||
else if @type is 'object' or @type is 'function'
|
||||
@name = value.constructor.name
|
||||
@id = objectsRegistry.add process_id, routing_id, value
|
||||
value.id = @id
|
||||
|
||||
@members = []
|
||||
@members.push { name: prop, type: typeof field } for prop, field of value
|
||||
|
@ -23,11 +22,14 @@ class PlainObject
|
|||
@value = value
|
||||
|
||||
ipc.on 'ATOM_INTERNAL_REQUIRE', (event, process_id, routing_id, module) ->
|
||||
event.result = new PlainObject(process_id, routing_id, require(module))
|
||||
try
|
||||
event.result = new PlainObject(process_id, routing_id, require(module))
|
||||
catch e
|
||||
event.result = type: 'error', value: e.message
|
||||
|
||||
ipc.on 'ATOM_INTERNAL_CONSTRUCTOR', (event, process_id, routing_id, id, args) ->
|
||||
try
|
||||
constructor = objectsRegistry.get process_id, routing_id, id
|
||||
constructor = objectsRegistry.get id
|
||||
# Call new with array of arguments.
|
||||
# http://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible
|
||||
obj = new (Function::bind.apply(constructor, [null].concat(args)))
|
||||
|
@ -37,7 +39,7 @@ ipc.on 'ATOM_INTERNAL_CONSTRUCTOR', (event, process_id, routing_id, id, args) ->
|
|||
|
||||
ipc.on 'ATOM_INTERNAL_FUNCTION_CALL', (event, process_id, routing_id, id, args) ->
|
||||
try
|
||||
func = objectsRegistry.get process_id, routing_id, id
|
||||
func = objectsRegistry.get id
|
||||
ret = func.apply global, args
|
||||
event.result = new PlainObject(process_id, routing_id, ret)
|
||||
catch e
|
||||
|
@ -45,7 +47,7 @@ ipc.on 'ATOM_INTERNAL_FUNCTION_CALL', (event, process_id, routing_id, id, args)
|
|||
|
||||
ipc.on 'ATOM_INTERNAL_MEMBER_CALL', (event, process_id, routing_id, id, method, args) ->
|
||||
try
|
||||
obj = objectsRegistry.get process_id, routing_id, id
|
||||
obj = objectsRegistry.get id
|
||||
ret = obj[method].apply(obj, args)
|
||||
event.result = new PlainObject(process_id, routing_id, ret)
|
||||
catch e
|
||||
|
@ -53,17 +55,24 @@ ipc.on 'ATOM_INTERNAL_MEMBER_CALL', (event, process_id, routing_id, id, method,
|
|||
|
||||
ipc.on 'ATOM_INTERNAL_MEMBER_SET', (event, process_id, routing_id, id, name, value) ->
|
||||
try
|
||||
obj = objectsRegistry.get process_id, routing_id, id
|
||||
obj = objectsRegistry.get id
|
||||
obj[name] = value
|
||||
catch e
|
||||
event.result = type: 'error', value: e.message
|
||||
|
||||
ipc.on 'ATOM_INTERNAL_MEMBER_GET', (event, process_id, routing_id, id, name) ->
|
||||
try
|
||||
obj = objectsRegistry.get process_id, routing_id, id
|
||||
obj = objectsRegistry.get id
|
||||
event.result = new PlainObject(process_id, routing_id, obj[name])
|
||||
catch e
|
||||
event.result = type: 'error', value: e.message
|
||||
|
||||
ipc.on 'ATOM_INTERNAL_GET_OBJECT', (event, process_id, routing_id, id) ->
|
||||
try
|
||||
obj = objectsRegistry.get id
|
||||
event.result = new PlainObject(process_id, routing_id, obj)
|
||||
catch e
|
||||
event.result = type: 'error', value: e.message
|
||||
|
||||
ipc.on 'ATOM_INTERNAL_DESTROY', (process_id, routing_id, id) ->
|
||||
objectsRegistry.remove process_id, routing_id, id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue