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

Use Cu.unload where available.

--HG--
extra : rebase_source : 28ce17c49f2eeb6b330ce47e13e0543569348c59
This commit is contained in:
Kris Maglione
2011-07-12 19:10:16 -04:00
parent 7c85bffedd
commit 5b01369d62
3 changed files with 51 additions and 23 deletions

2
common/bootstrap.js vendored
View File

@@ -221,7 +221,7 @@ function init() {
createInstance: function () this.instance createInstance: function () this.instance
}); });
Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader = JSMLoader; Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader = !Cu.unload && JSMLoader;
for each (let component in components) for each (let component in components)
component.register(); component.register();

View File

@@ -6,6 +6,8 @@
try { try {
let { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
var EXPORTED_SYMBOLS = ["JSMLoader"]; var EXPORTED_SYMBOLS = ["JSMLoader"];
var BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap"; var BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap";
@@ -22,15 +24,27 @@ if (JSMLoader && JSMLoader.bump === 4)
else else
JSMLoader = { JSMLoader = {
bump: 4, bump: 4,
builtin: Components.utils.Sandbox(this),
builtin: Cu.Sandbox(this),
canonical: {}, canonical: {},
factories: [], factories: [],
global: this, global: this,
globals: JSMLoader ? JSMLoader.globals : {}, globals: JSMLoader ? JSMLoader.globals : {},
io: Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService),
loader: Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader), io: Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),
manager: Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar),
loader: Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader),
manager: Components.manager.QueryInterface(Ci.nsIComponentRegistrar),
modules: JSMLoader ? JSMLoader.modules : {},
stale: JSMLoader ? JSMLoader.stale : {}, stale: JSMLoader ? JSMLoader.stale : {},
suffix: "", suffix: "",
times: { times: {
@@ -67,7 +81,7 @@ else
url = "resource://dactyl" + this.suffix + "/" + url; url = "resource://dactyl" + this.suffix + "/" + url;
let chan = this.io.newChannel(url, null, null); let chan = this.io.newChannel(url, null, null);
chan.cancel(Components.results.NS_BINDING_ABORTED); chan.cancel(Cr.NS_BINDING_ABORTED);
return chan.name; return chan.name;
}, },
@@ -91,7 +105,8 @@ else
try { try {
let now = Date.now(); let now = Date.now();
let global = Components.utils.import(url, target); this.modules[url] = true;
let global = Cu.import(url, target);
if (!(name in this.globals)) if (!(name in this.globals))
this.times.add("require", name, Date.now() - now); this.times.add("require", name, Date.now() - now);
@@ -118,25 +133,37 @@ else
purge: function purge() { purge: function purge() {
dump("dactyl: JSMLoader: purge\n"); dump("dactyl: JSMLoader: purge\n");
for (let [url, global] in Iterator(this.globals)) { if (Cu.unload) {
if (url === "bootstrap.jsm" || url === "resource://dactyl/bootstrap.jsm") Object.keys(this.modules).reverse().forEach(function (url) {
continue;
let target = this.getTarget(url);
this.stale[url] = target;
this.stale[target] = target;
for each (let prop in Object.getOwnPropertyNames(global))
try { try {
if (!(prop in this.builtin) && Cu.unload(url);
["JSMLoader", "set", "EXPORTED_SYMBOLS"].indexOf(prop) < 0 &&
!global.__lookupGetter__(prop))
global[prop] = undefined;
} }
catch (e) { catch (e) {
dump("Deleting property " + prop + " on " + url + ":\n " + e + "\n"); Cu.reportError(e);
Components.utils.reportError(e);
} }
});
}
else {
for (let [url, global] in Iterator(this.globals)) {
if (url === "bootstrap.jsm" || url === "resource://dactyl/bootstrap.jsm")
continue;
let target = this.getTarget(url);
this.stale[url] = target;
this.stale[target] = target;
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");
Cu.reportError(e);
}
}
} }
}, },
@@ -149,6 +176,6 @@ else
} }
}; };
}catch(e){ dump(e + "\n" + (e.stack || Error().stack)); Components.utils.reportError(e) } }catch(e){ dump(e + "\n" + (e.stack || Error().stack)); Cu.reportError(e) }
// vim: set fdm=marker sw=4 sts=4 et ft=javascript: // vim: set fdm=marker sw=4 sts=4 et ft=javascript:

View File

@@ -1623,6 +1623,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
rehash: function (args) { rehash: function (args) {
JSMLoader.commandlineArgs = args; JSMLoader.commandlineArgs = args;
this.timeout(function () { this.timeout(function () {
services.observer.notifyObservers(null, "startupcache-invalidate", "");
this.rehashing = true; this.rehashing = true;
let addon = config.addon; let addon = config.addon;
addon.userDisabled = true; addon.userDisabled = true;