use idweakmap for holding callbacks in browser
This commit is contained in:
parent
62d15953ff
commit
eae7c840b7
6 changed files with 63 additions and 13 deletions
|
@ -1,3 +1,5 @@
|
|||
v8Util = process.atomBinding 'v8_util'
|
||||
|
||||
module.exports =
|
||||
class CallbacksRegistry
|
||||
constructor: ->
|
||||
|
@ -7,10 +9,6 @@ class CallbacksRegistry
|
|||
add: (callback) ->
|
||||
id = ++@nextId
|
||||
|
||||
for id,value of @callbacks
|
||||
if value == callback
|
||||
return id
|
||||
|
||||
# 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
|
||||
|
@ -21,10 +19,14 @@ class CallbacksRegistry
|
|||
continue if location.indexOf('(native)') isnt -1
|
||||
continue if location.indexOf('atom.asar') isnt -1
|
||||
[x, filenameAndLine] = /([^/^\)]*)\)?$/gi.exec(location)
|
||||
id = "#{filenameAndLine} (#{id})"
|
||||
break
|
||||
|
||||
if v8Util.getHiddenValue(callback, 'metaId')?
|
||||
return v8Util.getHiddenValue(callback, 'metaId')
|
||||
|
||||
@callbacks[id] = callback
|
||||
v8Util.setHiddenValue callback, 'metaId', id
|
||||
v8Util.setHiddenValue callback, 'location', filenameAndLine
|
||||
id
|
||||
|
||||
get: (id) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue