Skip to content

Commit

Permalink
Clean up CallbackRegistry
Browse files Browse the repository at this point in the history
There were some ancient code there.
  • Loading branch information
zcbenz committed Oct 16, 2015
1 parent 94f64c7 commit d9fdfb7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion atom/browser/lib/rpc-server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ unwrapArgs = (sender, args) ->
ret = ->
if rendererReleased
throw new Error("Attempting to call a function in a renderer window
that has been closed or released. Function provided here: #{meta.id}.")
that has been closed or released. Function provided here: #{meta.id}.")
sender.send 'ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(sender, arguments)
v8Util.setDestructor ret, ->
return if rendererReleased
Expand Down
13 changes: 4 additions & 9 deletions atom/common/api/lib/callbacks-registry.coffee
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
savedGlobal = global # the "global.global" might be deleted later

module.exports =
class CallbacksRegistry
constructor: ->
@emptyFunc = -> throw new Error "Browser trying to call a non-exist callback
in renderer, this usually happens when renderer code forgot to release
a callback installed on objects in browser when renderer was going to be
unloaded or released."
@nextId = 0
@callbacks = {}

add: (callback) ->
id = Math.random().toString()
id = ++@nextId

# Capture the location of the function and put it in the ID string,
# so that release errors can be tracked down easily.
Expand All @@ -32,10 +27,10 @@ class CallbacksRegistry
@callbacks[id] ? ->

call: (id, args...) ->
@get(id).call savedGlobal, args...
@get(id).call global, args...

apply: (id, args...) ->
@get(id).apply savedGlobal, args...
@get(id).apply global, args...

remove: (id) ->
delete @callbacks[id]

0 comments on commit d9fdfb7

Please sign in to comment.