1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 08:07:58 +01:00

Cleanup module globals more eagerly.

This commit is contained in:
Kris Maglione
2011-01-13 17:10:27 -05:00
parent 97da21c4aa
commit 3e85415890
3 changed files with 23 additions and 16 deletions

6
common/bootstrap.js vendored
View File

@@ -45,6 +45,7 @@ let initialized = false;
let addon = null;
let basePath = null;
let components = {};
let resources = [];
let getURI = null;
storage.set("dactyl.bootstrap", this);
@@ -139,6 +140,7 @@ function init() {
break;
case "resource":
resources.push(fields[1]);
resourceProto.setSubstitution(fields[1], getURI(fields[2]));
}
}
@@ -174,6 +176,10 @@ function shutdown(data, reason) {
services.observer.notifyObservers(null, "dactyl-cleanup", null);
services.observer.notifyObservers(null, "dactyl-cleanup-modules", null);
JSMLoader.purge();
for each (let resource in resources)
resourceProto.setSubstitution(resource, null);
}
}

View File

@@ -36,22 +36,12 @@ if (!JSMLoader || JSMLoader.bump != 1)
delete this.stale[url];
let global = this.globals[url];
for each (let prop in Object.getOwnPropertyNames(global))
try {
if (!(prop in this.builtin) && ["JSMLoader", "set"].indexOf(prop) < 0 &&
!global.__lookupGetter__(prop))
global[prop] = undefined;
}
catch (e) {
dump("Deleting property " + prop + " on " + url + ":\n " + e + "\n");
Components.utils.reportError(e);
}
if (stale === this.getTarget(url))
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader)
.loadSubScript(url, global.global || global);
}
try {
let global = Components.utils.import(url, target);
@@ -73,9 +63,23 @@ if (!JSMLoader || JSMLoader.bump != 1)
this.manager.unregisterFactory(factory.classID, factory);
},
purge: function purge() {
for (let [url, global] in Iterator(this.globals))
for (let [url, global] in Iterator(this.globals)) {
this.stale[url] = this.getTarget(url);
for each (let prop in Object.getOwnPropertyNames(global))
try {
if (!(prop in this.builtin) &&
["JSMLoader", "set", "EXPORTED_SYMBOLS"].indexOf(prop) < 0 &&
!global.__lookupGetter__(prop))
global[prop] = undefined;
}
catch (e) {
dump("Deleting property " + prop + " on " + url + ":\n " + e + "\n");
Components.utils.reportError(e);
}
}
},
registerFactory: function registerFactory(factory) {
this.manager.registerFactory(factory.classID,
String(factory.classID),

View File

@@ -965,9 +965,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
services.observer.removeObserver(this, "dactyl-rehash");
defineModule.loadLog.push("dactyl: util: observe: dactyl-rehash");
if (this.rehashing)
JSMLoader.purge();
else
if (!this.rehashing)
for (let module in values(defineModule.modules)) {
defineModule.loadLog.push("dactyl: util: init(" + module + ")");
if (module.reinit)
@@ -978,7 +976,6 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
},
"dactyl-purge": function () {
this.rehashing = 1;
JSMLoader.purge();
},
"toplevel-window-ready": function (window, data) {
window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) {