Use random number as id in CallbacksRegistry.
It's very possible that the callbacks got GCed before the render view is closed (like page getting refreshed), so we should not let browser call the wrong callback, instead we should throw error whenever a callback is not found.
This commit is contained in:
parent
0a63395b0f
commit
844fccc177
1 changed files with 8 additions and 4 deletions
|
@ -1,15 +1,19 @@
|
|||
module.exports =
|
||||
class CallbacksRegistry
|
||||
constructor: ->
|
||||
@nextId = 0
|
||||
@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."
|
||||
@callbacks = {}
|
||||
|
||||
add: (callback) ->
|
||||
@callbacks[++@nextId] = callback
|
||||
@nextId
|
||||
id = Math.random().toString()
|
||||
@callbacks[id] = callback
|
||||
id
|
||||
|
||||
get: (id) ->
|
||||
@callbacks[id]
|
||||
@callbacks[id] ? ->
|
||||
|
||||
call: (id, args...) ->
|
||||
@get(id).call global, args...
|
||||
|
|
Loading…
Reference in a new issue