From d9fdfb711f445b161b08038a7041d1bc47c595be Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 16 Oct 2015 20:25:30 +0800 Subject: [PATCH] Clean up CallbackRegistry There were some ancient code there. --- atom/browser/lib/rpc-server.coffee | 2 +- atom/common/api/lib/callbacks-registry.coffee | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/atom/browser/lib/rpc-server.coffee b/atom/browser/lib/rpc-server.coffee index 7bbc019..a1e159a 100644 --- a/atom/browser/lib/rpc-server.coffee +++ b/atom/browser/lib/rpc-server.coffee @@ -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 diff --git a/atom/common/api/lib/callbacks-registry.coffee b/atom/common/api/lib/callbacks-registry.coffee index a9e9c7b..d4c37f0 100644 --- a/atom/common/api/lib/callbacks-registry.coffee +++ b/atom/common/api/lib/callbacks-registry.coffee @@ -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. @@ -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] -- 2.7.4