]> khamidou — GitHub mirrors - electron.git/commitdiff
Allow "released callback" errors to be traced to remote calls
authorBen Gotow <bengotow@gmail.com>
Fri, 16 Oct 2015 01:36:02 +0000 (18:36 -0700)
committerBen Gotow <bengotow@gmail.com>
Fri, 16 Oct 2015 01:46:59 +0000 (18:46 -0700)
atom/browser/lib/rpc-server.coffee
atom/common/api/lib/callbacks-registry.coffee

index 149b208b409d8c1eca71993efa9f189b181b4001..7bbc019b6d72ed7726fb592760ab690b1d340825 100644 (file)
@@ -69,7 +69,9 @@ unwrapArgs = (sender, args) ->
           rendererReleased = true
 
         ret = ->
-          throw new Error('Calling a callback of released renderer view') if rendererReleased
+          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}.")
           sender.send 'ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(sender, arguments)
         v8Util.setDestructor ret, ->
           return if rendererReleased
index 8f5eb62916c0e08fac51ebdb42da0a98a5030f9a..a9e9c7b1228fd6a16cf0edcf5511b2faaabec8be 100644 (file)
@@ -11,6 +11,20 @@ class CallbacksRegistry
 
   add: (callback) ->
     id = Math.random().toString()
+
+    # Capture the location of the function and put it in the ID string,
+    # so that release errors can be tracked down easily.
+    regexp = /at (.*)/gi
+    stackString = (new Error).stack
+
+    while (match = regexp.exec(stackString)) isnt null
+      [x, location] = match
+      continue if location.indexOf('(native)') isnt -1
+      continue if location.indexOf('atom.asar') isnt -1
+      [x, filenameAndLine] = /([^/^\)]*)\)?$/gi.exec(location)
+      id = "#{filenameAndLine} (#{id})"
+      break
+
     @callbacks[id] = callback
     id