mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 10:17:58 +01:00
Cleanup module globals more eagerly.
This commit is contained in:
6
common/bootstrap.js
vendored
6
common/bootstrap.js
vendored
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user