Do not dereference remote callback if its renderer view is released.

This commit is contained in:
Cheng Zhao 2013-10-05 20:53:31 +08:00
parent 1e1fec15b6
commit caaab22841
2 changed files with 8 additions and 1 deletions

View file

@ -39,7 +39,7 @@ class ObjectsStore
key = "#{processId}_#{routingId}" key = "#{processId}_#{routingId}"
delete @stores[key] delete @stores[key]
class ObjectsRegistry class ObjectsRegistry extends EventEmitter
constructor: -> constructor: ->
# Objects in weak map will be not referenced (so we won't leak memory), and # Objects in weak map will be not referenced (so we won't leak memory), and
# every object created in browser will have a unique id in weak map. # every object created in browser will have a unique id in weak map.
@ -84,6 +84,7 @@ class ObjectsRegistry
# Clear all references to objects from renderer view. # Clear all references to objects from renderer view.
clear: (processId, routingId) -> clear: (processId, routingId) ->
@emit "release-renderer-view-#{processId}-#{routingId}"
ObjectsStore.releaseForRenderView processId, routingId ObjectsStore.releaseForRenderView processId, routingId
# Return an array of all browser windows. # Return an array of all browser windows.

View file

@ -52,9 +52,15 @@ unwrapArgs = (processId, routingId, args) ->
returnValue = metaToValue meta.value returnValue = metaToValue meta.value
-> returnValue -> returnValue
when 'function' when 'function'
rendererReleased = false
objectsRegistry.once "release-renderer-view-#{processId}-#{routingId}", ->
rendererReleased = true
ret = -> ret = ->
throw new Error('Calling a callback of released renderer view') if rendererReleased
ipc.sendChannel processId, routingId, 'ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(processId, routingId, arguments) ipc.sendChannel processId, routingId, 'ATOM_RENDERER_CALLBACK', meta.id, valueToMeta(processId, routingId, arguments)
v8Util.setDestructor ret, -> v8Util.setDestructor ret, ->
return if rendererReleased
ipc.sendChannel processId, routingId, 'ATOM_RENDERER_RELEASE_CALLBACK', meta.id ipc.sendChannel processId, routingId, 'ATOM_RENDERER_RELEASE_CALLBACK', meta.id
ret ret
else throw new TypeError("Unknown type: #{meta.type}") else throw new TypeError("Unknown type: #{meta.type}")