[Pkg-mozext-commits] [itsalltext] 379/459: I moved the tracker into the page's userdata

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository itsalltext.

commit 8990f71fff8dc2fd378f4e2c819c8f3412dddd48
Author: Christian Höltje <docwhat at gerf.org>
Date:   Sat Aug 13 19:53:35 2011 -0400

    I moved the tracker into the page's userdata
    
    I was storing the tracker in the extension's memory, which
    caused problems because the caceobjs stored in the tracker
    had references to elements on the pages.  When the page
    was closed, the memory wouldn't be deallocated because of
    the tracker.
    
    I also disabled the cleanCacheObj since it is now auto-cleaned
    when the document is unloaded.
    
    See also: https://bugzilla.mozilla.org/show_bug.cgi?id=672619
---
 src/chrome/content/cacheobj.js   | 10 ++-----
 src/chrome/content/itsalltext.js | 64 +++++++++++++++++++++++++---------------
 2 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/src/chrome/content/cacheobj.js b/src/chrome/content/cacheobj.js
index 64cf966..bbabbd3 100644
--- a/src/chrome/content/cacheobj.js
+++ b/src/chrome/content/cacheobj.js
@@ -71,7 +71,7 @@ function CacheObj(node) {
     // @todo [security] Add a serial to the uid hash.
 
     node.setUserData(ItsAllText.MYSTRING + '_UID', that.uid, null);
-    ItsAllText.tracker[that.uid] = that;
+    ItsAllText.addToTracker(that.uid, that);
 
     /* Figure out where we will store the file.  While the filename can
      * change, the directory that the file is stored in should not!
@@ -829,17 +829,13 @@ CacheObj.prototype.hashString = function (some_string) {
  */
 CacheObj.get = function (node) {
     var str = ItsAllText.MYSTRING + "_UID",
-        id = null;
+    id = null;
     if (typeof(node) === 'string') {
         id = node;
     } else if (node && node.getUserData(str)) {
         id = node.getUserData(str);
     }
-    if (id && ItsAllText.tracker.hasOwnProperty(id)) {
-        return ItsAllText.tracker[id];
-    } else {
-        return null;
-    }
+    return ItsAllText.getFromTracker(id);
 };
 
 /**
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index 37172d7..c56d718 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -34,12 +34,6 @@ var ItsAllText = function () {
         loadthings;
 
     /**
-     * Used for tracking all the all the textareas that we are watching.
-     * @type Hash
-     */
-    that.tracker = {};
-
-    /**
      * A serial for tracking ids
      * @type Integer
      */
@@ -461,26 +455,48 @@ var ItsAllText = function () {
      * Cleans out all old cache objects.
      */
     that.cleanCacheObjs = function () {
-        var count = 0,
-            cobj,
-            id,
-            cdoc;
-        for (id in that.tracker) {
-            if (that.tracker.hasOwnProperty(id)) {
-                cobj = that.tracker[id];
-                cdoc = cobj.node.ownerDocument;
-                if (!cdoc.defaultView || !cdoc.location) {
-                    cobj.destroy();
-                    cdoc = null;
-                    delete that.tracker[id];
-                } else {
-                    count += 1;
-                }
-            }
-        }
-        //disabled-debug -- that.debug('textarea count (tracker):', count);
+//        var count = 0,
+//            cobj,
+//            id,
+//            cdoc;
+//        for (id in that.tracker) {
+//            if (that.tracker.hasOwnProperty(id)) {
+//                cobj = that.tracker[id];
+//                cdoc = cobj.node.ownerDocument;
+//                if (!cdoc.defaultView || !cdoc.location) {
+//                    cobj.destroy();
+//                    cdoc = null;
+//                    delete that.tracker[id];
+//                } else {
+//                    count += 1;
+//                }
+//            }
+//        }
+//        //disabled-debug -- that.debug('textarea count (tracker):', count);
     };
 
+    that.getFromTracker = function (id) {
+	var tracker;
+	tracker = gBrowser.contentDocument.getUserData(that.MYSTRING + "_tracker");
+	if (!tracker) {
+	    tracker = {};
+	    gBrowser.contentDocument.setUserData(that.MYSTRING + "_tracker", tracker, null);
+	}
+	that.debug("getFromTracker:", id, tracker);
+	return tracker[id];
+    }
+
+    that.addToTracker = function (id, cobj) {
+	var tracker;
+	tracker = gBrowser.contentDocument.getUserData(that.MYSTRING + "_tracker");
+	if (!tracker) {
+	    tracker = {};
+	}
+	tracker[id] = cobj;
+	gBrowser.contentDocument.setUserData(that.MYSTRING + "_tracker", tracker, null);
+	that.debug("addToTracker:", id, cobj, tracker);
+    }
+
     // @todo [wish] Refresh textarea on editor quit.
     // @todo [9] IDEA: support for input elements as well?
     // @todo [5] Minimum size for textareas.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git



More information about the Pkg-mozext-commits mailing list