From caaab22841ed99120efc441831aabd70d12b60c2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Oct 2013 20:53:31 +0800 Subject: [PATCH] Do not dereference remote callback if its renderer view is released. --- browser/atom/objects-registry.coffee | 3 ++- browser/atom/rpc-server.coffee | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/browser/atom/objects-registry.coffee b/browser/atom/objects-registry.coffee index b107d0f156aa..df2ad535244d 100644 --- a/browser/atom/objects-registry.coffee +++ b/browser/atom/objects-registry.coffee @@ -39,7 +39,7 @@ class ObjectsStore key = "#{processId}_#{routingId}" delete @stores[key] -class ObjectsRegistry +class ObjectsRegistry extends EventEmitter constructor: -> # 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. @@ -84,6 +84,7 @@ class ObjectsRegistry # Clear all references to objects from renderer view. clear: (processId, routingId) -> + @emit "release-renderer-view-#{processId}-#{routingId}" ObjectsStore.releaseForRenderView processId, routingId # Return an array of all browser windows. diff --git a/browser/atom/rpc-server.coffee b/browser/atom/rpc-server.coffee index 04d5fe2c9484..6b56bfca2063 100644 --- a/browser/atom/rpc-server.coffee +++ b/browser/atom/rpc-server.coffee @@ -52,9 +52,15 @@ unwrapArgs = (processId, routingId, args) -> returnValue = metaToValue meta.value -> returnValue when 'function' + rendererReleased = false + objectsRegistry.once "release-renderer-view-#{processId}-#{routingId}", -> + rendererReleased = true + 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) v8Util.setDestructor ret, -> + return if rendererReleased ipc.sendChannel processId, routingId, 'ATOM_RENDERER_RELEASE_CALLBACK', meta.id ret else throw new TypeError("Unknown type: #{meta.type}")