From: Cheng Zhao Date: Fri, 26 Apr 2013 14:33:31 +0000 (+0800) Subject: Keep an id for each object added to global weak map. X-Git-Tag: v0.1.0~249 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=536b523232ab8b75071ae1e2ac67102760339bd9;p=electron.git Keep an id for each object added to global weak map. --- diff --git a/browser/atom/objects_registry.coffee b/browser/atom/objects_registry.coffee index 1f838ab6..1ecc6357 100644 --- a/browser/atom/objects_registry.coffee +++ b/browser/atom/objects_registry.coffee @@ -3,6 +3,12 @@ IDWeakMap = require 'id_weak_map' globalStore = {} globalMap = new IDWeakMap +addObjectToWeakMap = (obj) -> + id = globalMap.add obj + Object.defineProperty obj, 'id', + enumerable: true, writable: false, value: id + id + getStoreForRenderView = (process_id, routing_id) -> key = "#{process_id}_#{routing_id}" globalStore[key] = {} unless globalStore[key]? @@ -10,13 +16,15 @@ getStoreForRenderView = (process_id, routing_id) -> process.on 'ATOM_BROWSER_INTERNAL_NEW', (obj) -> # For objects created in browser scripts, keep a weak reference here. - id = globalMap.add obj - obj.id = id + addObjectToWeakMap obj exports.add = (process_id, routing_id, obj) -> # Some native types may already been added to globalMap, in that case we # don't add it twice. - id = obj.id ? globalMap.add obj + if obj.id? + id = obj.id + else + id = addObjectToWeakMap obj store = getStoreForRenderView process_id, routing_id