Merge pull request #3103 from bengotow/bengotow/debug-release

Allow "released callback" errors to be traced to remote calls
This commit is contained in:
Cheng Zhao 2015-10-16 20:21:46 +08:00
commit 4871ea715c
2 changed files with 17 additions and 1 deletions

View 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

View 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