Add renference links.

This commit is contained in:
Cheng Zhao 2013-04-25 15:12:56 +08:00
parent 0692776020
commit 2997eb9c77
2 changed files with 37 additions and 35 deletions

View file

@ -25,9 +25,9 @@ ipc.on 'ATOM_INTERNAL_REQUIRE', (event, process_id, routing_id, module) ->
ipc.on 'ATOM_INTERNAL_CONSTRUCTOR', (event, process_id, routing_id, id, args) -> ipc.on 'ATOM_INTERNAL_CONSTRUCTOR', (event, process_id, routing_id, id, args) ->
try try
# Call new with array of arguments.
# TODO(zcbenz): Paste the URL of the StackOverflow question.
constructor = objectsRegistry.get 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))) obj = new (Function::bind.apply(constructor, [null].concat(args)))
event.result = new PlainObject(obj) event.result = new PlainObject(obj)
catch e catch e

View file

@ -5,15 +5,17 @@ generateFromPainObject = (plain) ->
return plain.value return plain.value
else if plain.type is 'error' else if plain.type is 'error'
throw new Error('Remote Error: ' + plain.value) throw new Error('Remote Error: ' + plain.value)
else
# A shadow class to represent the remote object. # A shadow class to represent the remote object.
class RemoteObject class RemoteObject
constructor: () -> constructor: () ->
if @constructor == RemoteObject if @constructor == RemoteObject
# Constructor call. # Constructor call.
obj = ipc.sendChannelSync 'ATOM_INTERNAL_CONSTRUCTOR', plain.id, Array::slice.call(arguments) obj = ipc.sendChannelSync 'ATOM_INTERNAL_CONSTRUCTOR', plain.id, Array::slice.call(arguments)
# Returning object in constructor will replace constructed object # Returning object in constructor will replace constructed object
# with returned object. # with the returned object.
# http://stackoverflow.com/questions/1978049/what-values-can-a-constructor-return-to-avoid-returning-this
return generateFromPainObject obj return generateFromPainObject obj
else else
# Function call. # Function call.