diff --git a/common/bootstrap.js b/common/bootstrap.js index c1027f7f..cc6977ed 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -221,7 +221,7 @@ function init() { 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) component.register(); diff --git a/common/modules/bootstrap.jsm b/common/modules/bootstrap.jsm index 6945b05b..3aa08d4b 100644 --- a/common/modules/bootstrap.jsm +++ b/common/modules/bootstrap.jsm @@ -6,6 +6,8 @@ try { +let { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; + var EXPORTED_SYMBOLS = ["JSMLoader"]; var BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap"; @@ -22,15 +24,27 @@ if (JSMLoader && JSMLoader.bump === 4) else JSMLoader = { bump: 4, - builtin: Components.utils.Sandbox(this), + + builtin: Cu.Sandbox(this), + canonical: {}, + factories: [], + global: this, + 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), - manager: Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar), + + io: Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService), + + 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 : {}, + suffix: "", times: { @@ -67,7 +81,7 @@ else url = "resource://dactyl" + this.suffix + "/" + url; let chan = this.io.newChannel(url, null, null); - chan.cancel(Components.results.NS_BINDING_ABORTED); + chan.cancel(Cr.NS_BINDING_ABORTED); return chan.name; }, @@ -91,7 +105,8 @@ else try { 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)) this.times.add("require", name, Date.now() - now); @@ -118,25 +133,37 @@ else purge: function purge() { dump("dactyl: JSMLoader: purge\n"); - 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)) + if (Cu.unload) { + Object.keys(this.modules).reverse().forEach(function (url) { try { - if (!(prop in this.builtin) && - ["JSMLoader", "set", "EXPORTED_SYMBOLS"].indexOf(prop) < 0 && - !global.__lookupGetter__(prop)) - global[prop] = undefined; + Cu.unload(url); } catch (e) { - dump("Deleting property " + prop + " on " + url + ":\n " + e + "\n"); - Components.utils.reportError(e); + Cu.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: diff --git a/common/modules/util.jsm b/common/modules/util.jsm index fcc80c0c..e9648160 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -1623,6 +1623,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), rehash: function (args) { JSMLoader.commandlineArgs = args; this.timeout(function () { + services.observer.notifyObservers(null, "startupcache-invalidate", ""); this.rehashing = true; let addon = config.addon; addon.userDisabled = true;