From 43f329512727ccc6d0da2193f5eead5ae0d6d705 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 7 May 2012 17:01:21 -0400 Subject: [PATCH] Merge addon-common module loading code to fix Minefield. --HG-- extra : rebase_source : 6b5f0dc0a575a6d21892e18cbb56ab0230382356 --- common/bootstrap.js | 395 ++++++++++++++++++++----------- common/chrome.manifest | 12 +- common/content/dactyl.js | 1 - common/modules/addons.jsm | 10 +- common/modules/base.jsm | 132 ++--------- common/modules/bookmarkcache.jsm | 3 +- common/modules/bootstrap.jsm | 206 +--------------- common/modules/buffer.jsm | 16 +- common/modules/cache.jsm | 6 +- common/modules/commands.jsm | 7 +- common/modules/completion.jsm | 4 +- common/modules/config.jsm | 15 +- common/modules/contexts.jsm | 9 +- common/modules/dom.jsm | 5 +- common/modules/downloads.jsm | 8 +- common/modules/finder.jsm | 9 +- common/modules/help.jsm | 9 +- common/modules/highlight.jsm | 6 +- common/modules/io.jsm | 9 +- common/modules/javascript.jsm | 5 +- common/modules/main.jsm | 9 +- common/modules/messages.jsm | 7 +- common/modules/options.jsm | 11 +- common/modules/overlay.jsm | 7 +- common/modules/prefs.jsm | 6 +- common/modules/protocol.jsm | 4 +- common/modules/sanitizer.jsm | 9 +- common/modules/services.jsm | 3 +- common/modules/storage.jsm | 8 +- common/modules/styles.jsm | 6 +- common/modules/template.jsm | 8 +- common/modules/util.jsm | 9 +- pentadactyl/config.json | 4 + 33 files changed, 415 insertions(+), 543 deletions(-) diff --git a/common/bootstrap.js b/common/bootstrap.js index d81411ea..f756a28f 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -6,16 +6,15 @@ // See https://wiki.mozilla.org/Extension_Manager:Bootstrapped_Extensions // for details. -const NAME = "bootstrap"; const global = this; var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; -function module(uri) { - let obj = {}; - Cu.import(uri, obj); - return obj; -} +function module(uri) Cu.import(uri, {}); + +const DEBUG = true; + +__defineGetter__("BOOTSTRAP", function () "resource://" + moduleName + "/bootstrap.jsm"); const { AddonManager } = module("resource://gre/modules/AddonManager.jsm"); const { XPCOMUtils } = module("resource://gre/modules/XPCOMUtils.jsm"); @@ -26,43 +25,267 @@ const resourceProto = Services.io.getProtocolHandler("resource") const categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); const manager = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -const DISABLE_ACR = "resource://dactyl-content/disable-acr.jsm"; -const BOOTSTRAP_JSM = "resource://dactyl/bootstrap.jsm"; const BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap"; -var JSMLoader = BOOTSTRAP_CONTRACT in Cc && Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader; var name = "dactyl"; function reportError(e) { - dump("\n" + name + ": bootstrap: " + e + "\n" + (e.stack || Error().stack) + "\n"); + let stack = e.stack || Error().stack; + dump("\n" + name + ": bootstrap: " + e + "\n" + stack + "\n"); Cu.reportError(e); + Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService) + .logStringMessage(stack); } -function debug(msg) { - dump(name + ": " + msg + "\n"); +function debug() { + if (DEBUG) + dump(name + ": " + Array.join(arguments, ", ") + "\n"); } -function httpGet(url) { +function httpGet(uri) { let xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest); xmlhttp.overrideMimeType("text/plain"); - xmlhttp.open("GET", url, false); + xmlhttp.open("GET", uri.spec || uri, false); xmlhttp.send(null); return xmlhttp; } +let moduleName; let initialized = false; let addon = null; let addonData = null; let basePath = null; +let bootstrap; let categories = []; let components = {}; let resources = []; let getURI = null; -function updateLoader() { - try { - JSMLoader.loader = Cc["@dactyl.googlecode.com/extra/utils"].getService(Ci.dactylIUtils); +let JSMLoader = { + get addon() addon, + + currentModule: null, + + factories: [], + + get name() name, + + get module() moduleName, + + globals: {}, + modules: {}, + + times: { + all: 0, + add: function add(major, minor, delta) { + this.all += delta; + + this[major] = (this[major] || 0) + delta; + if (minor) { + minor = ":" + minor; + this[minor] = (this[minor] || 0) + delta; + this[major + minor] = (this[major + minor] || 0) + delta; + } + }, + clear: function clear() { + for (let key in this) + if (typeof this[key] !== "number") + delete this[key]; + } + }, + + getTarget: function getTarget(url) { + let chan = Services.io.newChannel(url, null, null); + try { chan.cancel(Cr.NS_BINDING_ABORTED) } catch (e) {} + return chan.name; + }, + + _atexit: [], + + atexit: function atexit(arg, self) { + if (typeof arg !== "string") + this._atexit.push(arguments); + else + for each (let [fn, self] in this._atexit) + try { + fn.call(self, arg); + } + catch (e) { + reportError(e); + } + }, + + _load: function _load(name, target) { + let urls = [name]; + if (name.indexOf(":") === -1) + urls = this.config["module-paths"].map(function (path) path + name + ".jsm"); + + for each (let url in urls) + try { + var uri = resourceProto.resolveURI(Services.io.newURI(url, null, null)); + if (uri in this.globals) + return this.modules[name] = this.globals[uri]; + + this.globals[uri] = this.modules[name]; + bootstrap.loadSubScript(url, this.modules[name]); + return; + } + catch (e) { + delete this.globals[uri]; + if (typeof e != "string") + throw e; + } + + throw Error("No such module: " + name); + }, + + load: function load(name, target) { + if (!this.modules.hasOwnProperty(name)) { + this.modules[name] = this.modules.base ? bootstrap.create(this.modules.base) + : bootstrap.import({ JSMLoader: this, module: global.module }); + + let currentModule = this.currentModule; + this.currentModule = this.modules[name]; + + try { + this._load(name, this.modules[name]); + } + catch (e) { + delete this.modules[name]; + reportError(e); + throw e; + } + finally { + this.currentModule = currentModule; + } + } + + let module = this.modules[name]; + if (target) + for each (let symbol in module.EXPORTED_SYMBOLS) + target[symbol] = module[symbol]; + + return module; + }, + + // Cuts down on stupid, fscking url mangling. + get loadSubScript() bootstrap.loadSubScript, + + cleanup: function unregister() { + for each (let factory in this.factories.splice(0)) + manager.unregisterFactory(factory.classID, factory); + }, + + Factory: function Factory(class_) ({ + __proto__: class_.prototype, + + createInstance: function (outer, iid) { + try { + if (outer != null) + throw Cr.NS_ERROR_NO_AGGREGATION; + if (!class_.instance) + class_.instance = new class_(); + return class_.instance.QueryInterface(iid); + } + catch (e) { + Cu.reportError(e); + throw e; + } + } + }), + + registerFactory: function registerFactory(factory) { + manager.registerFactory(factory.classID, + String(factory.classID), + factory.contractID, + factory); + this.factories.push(factory); } - catch (e) {}; +}; + +function init() { + debug("bootstrap: init"); + + let manifestURI = getURI("chrome.manifest"); + let manifest = httpGet(manifestURI) + .responseText + .replace(/#(resource)#/g, "$1") + .replace(/^\s*|\s*$|#.*/g, "") + .replace(/^\s*\n/gm, ""); + + for each (let line in manifest.split("\n")) { + let fields = line.split(/\s+/); + switch(fields[0]) { + case "category": + categoryManager.addCategoryEntry(fields[1], fields[2], fields[3], false, true); + categories.push([fields[1], fields[2]]); + break; + case "component": + components[fields[1]] = new FactoryProxy(getURI(fields[2]).spec, fields[1]); + break; + case "contract": + components[fields[2]].contractID = fields[1]; + break; + + case "resource": + moduleName = moduleName || fields[1]; + resources.push(fields[1]); + resourceProto.setSubstitution(fields[1], getURI(fields[2])); + } + } + + bootstrap = module(BOOTSTRAP); + bootstrap.require = JSMLoader.load("base").require; + + // Flush the cache if necessary, just to be paranoid + let pref = "extensions.dactyl.cacheFlushCheck"; + let val = addon.version; + if (!Services.prefs.prefHasUserValue(pref) || Services.prefs.getCharPref(pref) != val) { + var cacheFlush = true; + Services.obs.notifyObservers(null, "startupcache-invalidate", ""); + Services.prefs.setCharPref(pref, val); + } + + try { + //JSMLoader.load("disable-acr").init(addon.id); + } + catch (e) { + reportError(e); + } + + Services.obs.notifyObservers(null, "dactyl-rehash", null); + + JSMLoader.name = name; + JSMLoader.bootstrap = this; + + JSMLoader.load("config", global); + JSMLoader.load("main", global); + + JSMLoader.cacheFlush = cacheFlush; + JSMLoader.load("base", global); + + if (!(BOOTSTRAP_CONTRACT in Cc)) { + // Use Sandbox to prevent closures over this scope + let sandbox = Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].getService()); + let factory = Cu.evalInSandbox("({ createInstance: function () this })", sandbox); + + factory.classID = Components.ID("{f541c8b0-fe26-4621-a30b-e77d21721fb5}"); + factory.contractID = BOOTSTRAP_CONTRACT; + factory.QueryInterface = XPCOMUtils.generateQI([Ci.nsIFactory]); + factory.wrappedJSObject = factory; + + manager.registerFactory(factory.classID, String(factory.classID), + BOOTSTRAP_CONTRACT, factory); + } + + Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader = !Cu.unload && JSMLoader; + + for each (let component in components) + component.register(); + + updateVersion(); + + if (addon !== addonData) + require("main", global); } /** @@ -74,8 +297,7 @@ function updateVersion() { if (typeof require === "undefined" || addon === addonData) return; - require(global, "config"); - require(global, "prefs"); + JSMLoader.load("prefs", global); config.lastVersion = localPrefs.get("lastVersion", null); localPrefs.set("lastVersion", addon.version); @@ -100,7 +322,7 @@ function startup(data, reason) { if (!initialized) { initialized = true; - debug("bootstrap: init" + " " + data.id); + debug("bootstrap: init " + data.id); addonData = data; addon = data; @@ -108,10 +330,9 @@ function startup(data, reason) { AddonManager.getAddonByID(addon.id, function (a) { addon = a; - updateLoader(); updateVersion(); if (typeof require !== "undefined") - require(global, "main"); + require("main", global); }); if (basePath.isDirectory()) @@ -125,6 +346,7 @@ function startup(data, reason) { Services.io.newURI("jar:" + Services.io.newFileURI(basePath).spec.replace(/!/g, "%21") + "!" + "/" + path, null, null); + JSMLoader.config = JSON.parse(httpGet(getURI("config.json")).responseText); try { init(); } @@ -166,120 +388,13 @@ FactoryProxy.prototype = { } } -function init() { - debug("bootstrap: init"); - - let manifestURI = getURI("chrome.manifest"); - let manifest = httpGet(manifestURI.spec) - .responseText - .replace(/^\s*|\s*$|#.*/g, "") - .replace(/^\s*\n/gm, ""); - - let suffix = "-"; - let chars = "0123456789abcdefghijklmnopqrstuv"; - for (let n = Date.now(); n; n = Math.round(n / chars.length)) - suffix += chars[n % chars.length]; - - for each (let line in manifest.split("\n")) { - let fields = line.split(/\s+/); - switch(fields[0]) { - case "category": - categoryManager.addCategoryEntry(fields[1], fields[2], fields[3], false, true); - categories.push([fields[1], fields[2]]); - break; - case "component": - components[fields[1]] = new FactoryProxy(getURI(fields[2]).spec, fields[1]); - break; - case "contract": - components[fields[2]].contractID = fields[1]; - break; - - case "resource": - resources.push(fields[1], fields[1] + suffix); - resourceProto.setSubstitution(fields[1], getURI(fields[2])); - resourceProto.setSubstitution(fields[1] + suffix, getURI(fields[2])); - } - } - - // Flush the cache if necessary, just to be paranoid - let pref = "extensions.dactyl.cacheFlushCheck"; - let val = addon.version; - if (!Services.prefs.prefHasUserValue(pref) || Services.prefs.getCharPref(pref) != val) { - var cacheFlush = true; - Services.obs.notifyObservers(null, "startupcache-invalidate", ""); - Services.prefs.setCharPref(pref, val); - } - - try { - module(DISABLE_ACR).init(addon.id); - } - catch (e) { - reportError(e); - } - - if (JSMLoader) { - // Temporary hacks until platforms and dactyl releases that don't - // support Cu.unload are phased out. - if (Cu.unload) { - // Upgrading from dactyl release without Cu.unload support. - Cu.unload(BOOTSTRAP_JSM); - for (let [name] in Iterator(JSMLoader.globals)) - Cu.unload(~name.indexOf(":") ? name : "resource://dactyl" + JSMLoader.suffix + "/" + name); - } - else if (JSMLoader.bump != 6) { - // We're in a version without Cu.unload support and the - // JSMLoader interface has changed. Bump off the old one. - Services.scriptloader.loadSubScript("resource://dactyl" + suffix + "/bootstrap.jsm", - Cu.import(BOOTSTRAP_JSM, global)); - } - } - - if (!JSMLoader || JSMLoader.bump !== 6 || Cu.unload) - Cu.import(BOOTSTRAP_JSM, global); - - JSMLoader.name = name; - JSMLoader.bootstrap = this; - - JSMLoader.load(BOOTSTRAP_JSM, global); - - JSMLoader.init(suffix); - JSMLoader.cacheFlush = cacheFlush; - JSMLoader.load("base.jsm", global); - - if (!(BOOTSTRAP_CONTRACT in Cc)) { - // Use Sandbox to prevent closures over this scope - let sandbox = Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].getService()); - let factory = Cu.evalInSandbox("({ createInstance: function () this })", sandbox); - - factory.classID = Components.ID("{f541c8b0-fe26-4621-a30b-e77d21721fb5}"); - factory.contractID = BOOTSTRAP_CONTRACT; - factory.QueryInterface = XPCOMUtils.generateQI([Ci.nsIFactory]); - factory.wrappedJSObject = factory; - - manager.registerFactory(factory.classID, String(factory.classID), - BOOTSTRAP_CONTRACT, factory); - } - - Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader = !Cu.unload && JSMLoader; - - for each (let component in components) - component.register(); - - Services.obs.notifyObservers(null, "dactyl-rehash", null); - updateVersion(); - - updateLoader(); - if (addon !== addonData) - require(global, "main"); -} - function shutdown(data, reason) { - debug("bootstrap: shutdown " + reasonToString(reason)); + let strReason = reasonToString(reason); + debug("bootstrap: shutdown " + strReason); + if (reason != APP_SHUTDOWN) { try { - module(DISABLE_ACR).cleanup(); - if (Cu.unload) - Cu.unload(DISABLE_ACR); + //JSMLoader.load("disable-acr").cleanup(addon.id); } catch (e) { reportError(e); @@ -288,10 +403,18 @@ function shutdown(data, reason) { if (~[ADDON_UPGRADE, ADDON_DOWNGRADE, ADDON_UNINSTALL].indexOf(reason)) Services.obs.notifyObservers(null, "dactyl-purge", null); - Services.obs.notifyObservers(null, "dactyl-cleanup", reasonToString(reason)); + Services.obs.notifyObservers(null, "dactyl-cleanup", strReason); Services.obs.notifyObservers(null, "dactyl-cleanup-modules", reasonToString(reason)); - JSMLoader.purge(); + JSMLoader.atexit(strReason); + JSMLoader.cleanup(strReason); + + if (Cu.unload) + Cu.unload(BOOTSTRAP); + else + bootstrap.require = null; + + for each (let [category, entry] in categories) categoryManager.deleteCategoryEntry(category, entry, false); for each (let resource in resources) diff --git a/common/chrome.manifest b/common/chrome.manifest index 3eae8e1c..fbf90962 100644 --- a/common/chrome.manifest +++ b/common/chrome.manifest @@ -1,14 +1,14 @@ +resource dactyl ../common/modules/ +resource dactyl-common ../common/ +resource dactyl-content ../common/content/ +resource dactyl-skin ../common/skin/ +resource dactyl-locale ../common/locale/ + resource dactyl-local ./ resource dactyl-local-content content/ resource dactyl-local-skin skin/ resource dactyl-local-locale locale/ -resource dactyl-common ../common/ -resource dactyl ../common/modules/ -resource dactyl-content ../common/content/ -resource dactyl-skin ../common/skin/ -resource dactyl-locale ../common/locale/ - content dactyl ../common/content/ component {16dc34f7-6d22-4aa4-a67f-2921fb5dcb69} components/commandline-handler.js diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 2933dcd9..ce461416 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -1264,7 +1264,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { return '\n' + '\n' + - '\n' +

{_("help.title.Using Plugins")}

diff --git a/common/modules/addons.jsm b/common/modules/addons.jsm index 732e8cca..487f2f90 100644 --- a/common/modules/addons.jsm +++ b/common/modules/addons.jsm @@ -7,11 +7,13 @@ try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("addons", { exports: ["AddonManager", "Addons", "Addon", "addons"], - require: ["services"] -}, this); + require: ["services", "util"] +}); + +this.lazyRequire("completion", ["completion"]); +lazyRequire("template", ["template"]); var callResult = function callResult(method) { let args = Array.slice(arguments, 1); @@ -496,7 +498,7 @@ var Addons = Module("addons", { }); if (!services.has("extensionManager")) - Components.utils.import("resource://gre/modules/AddonManager.jsm"); + Components.utils.import("resource://gre/modules/AddonManager.jsm", this); else var AddonManager = { PERM_CAN_UNINSTALL: 1, diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 18e17f9e..32de7015 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -6,8 +6,7 @@ var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; -Cu.import("resource://dactyl/bootstrap.jsm"); -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm", this); try { var ctypes; Cu.import("resource://gre/modules/ctypes.jsm"); @@ -27,116 +26,28 @@ if (!XPCNativeWrapper.unwrap) return obj.wrappedJSObject; return obj; }; -if (!Object.create) - Object.create = function create(proto, props) { - let obj = { __proto__: proto }; - for (let k in properties(props || {})) - Object.defineProperty(obj, k, props[k]); - return obj; - }; -if (!Object.defineProperty) - Object.defineProperty = function defineProperty(obj, prop, desc) { - try { - let value = desc.value; - if ("value" in desc) - if (desc.writable && !__lookupGetter__.call(obj, prop) - && !__lookupSetter__.call(obj, prop)) - try { - obj[prop] = value; - } - catch (e if e instanceof TypeError) {} - else { - __defineGetter__.call(obj, prop, function () value); - if (desc.writable) - __defineSetter__.call(obj, prop, function (val) { value = val; }); - } - - if ("get" in desc) - __defineGetter__.call(obj, prop, desc.get); - if ("set" in desc) - __defineSetter__.call(obj, prop, desc.set); - } - catch (e) { - throw e.stack ? e : Error(e); - } - }; -if (!Object.defineProperties) - Object.defineProperties = function defineProperties(obj, props) { - for (let [k, v] in Iterator(props)) - Object.defineProperty(obj, k, v); - }; -if (!Object.freeze) - Object.freeze = function freeze(obj) {}; -if (!Object.getPropertyDescriptor) - Object.getPropertyDescriptor = function getPropertyDescriptor(obj, prop) { - try { - let desc = { - configurable: true, - enumerable: propertyIsEnumerable.call(obj, prop) - }; - var get = __lookupGetter__.call(obj, prop), - set = __lookupSetter__.call(obj, prop); - if (!get && !set) { - desc.value = obj[prop]; - desc.writable = true; - } - if (get) - desc.get = get; - if (set) - desc.set = set; - return desc; - } - catch (e) { - throw e.stack ? e : Error(e); - } - }; -if (!Object.getOwnPropertyDescriptor) - Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(obj, prop) { - if (hasOwnProperty.call(obj, prop)) - return Object.getPropertyDescriptor(obj, prop); - }; -if (!Object.getOwnPropertyNames) - Object.getOwnPropertyNames = function getOwnPropertyNames(obj, _debugger) { - try { - // This is an ugly and unfortunately necessary hack. - if (hasOwnProperty.call(obj, "__iterator__")) { - var oldIter = obj.__iterator__; - delete obj.__iterator__; - } - let res = [k for (k in obj) if (hasOwnProperty.call(obj, k))]; - if (oldIter !== undefined) { - obj.__iterator__ = oldIter; - res.push("__iterator__"); - } - return res; - } - catch (e) { - throw e.stack ? e : Error(e); - } - }; -if (!Object.getPrototypeOf) - Object.getPrototypeOf = function getPrototypeOf(obj) obj.__proto__; -if (!Object.keys) - Object.keys = function keys(obj) - Object.getOwnPropertyNames(obj).filter(function (k) propertyIsEnumerable.call(obj, k)); let getGlobalForObject = Cu.getGlobalForObject || function (obj) obj.__parent__; -let jsmodules = { - lazyRequire: function lazyRequire(module, names, target) { - for each (let name in names) - memoize(target || this, name, function (name) require(module)[name]); - } -}; +function require(module, target) JSMLoader.load(module, target); + +function lazyRequire(module, names, target) { + for each (let name in names) + memoize(target || this, name, function (name) require(module)[name]); +} + +let jsmodules = { lazyRequire: lazyRequire }; jsmodules.jsmodules = jsmodules; +function toString() "[module-global " + this.NAME + "]"; + let use = {}; let loaded = {}; let currentModule; let global = this; function defineModule(name, params, module) { if (!module) - module = getGlobalForObject(params); + module = this; module.NAME = name; module.EXPORTED_SYMBOLS = params.exports || []; @@ -147,8 +58,7 @@ function defineModule(name, params, module) { defineModule.prefix += " "; for (let [, mod] in Iterator(params.require || [])) - require(module, mod, null, name); - module.__proto__ = jsmodules; + require(mod, module); module._lastModule = currentModule; currentModule = module; @@ -196,11 +106,11 @@ function endModule() { defineModule.loadLog.push("(End " + currentModule.NAME + ")"); loaded[currentModule.NAME] = 1; - require(jsmodules, currentModule.NAME); + require(currentModule.NAME, jsmodules); currentModule = currentModule._lastModule; } -function require(obj, name, from, targetName) { +function require_(obj, name, from, targetName) { try { if (arguments.length === 1) [obj, name] = [{}, obj]; @@ -230,7 +140,7 @@ function require(obj, name, from, targetName) { defineModule("base", { // sed -n 's/^(const|var|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt exports: [ - "ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "JSMLoader", "Object", + "ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "JSMLoader", "Set", "Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMShim", "XPCOMUtils", "XPCSafeJSObjectWrapper", "array", "bind", "call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule", "deprecated", "endModule", "forEach", "isArray", @@ -238,10 +148,12 @@ defineModule("base", { "iterOwnProperties", "keys", "memoize", "octal", "properties", "require", "set", "update", "values", "withCallerGlobal" ] -}, this); +}); +this.lazyRequire("config", ["config"]); this.lazyRequire("messages", ["_", "Messages"]); -this.lazyRequire("util", ["util"]); +this.lazyRequire("services", ["services"]); +this.lazyRequire("util", ["FailedAssertion", "util"]); /** * Returns a list of all of the top-level properties of an object, by @@ -653,7 +565,7 @@ function memoize(obj, key, getter) { } } -let sandbox = Cu.Sandbox(this); +let sandbox = Cu.Sandbox(Cu.getGlobalForObject(this)); sandbox.__proto__ = this; /** * Wraps a function so that when called, the global object of the caller @@ -666,7 +578,7 @@ var withCallerGlobal = Cu.evalInSandbox(, Cu.Sandbox(this), "1.8"); +]]>, Cu.Sandbox(Cu.getGlobalForObject(this)), "1.8"); /** * Updates an object with the properties of another object. Getters diff --git a/common/modules/bookmarkcache.jsm b/common/modules/bookmarkcache.jsm index 8183615c..f70560a3 100644 --- a/common/modules/bookmarkcache.jsm +++ b/common/modules/bookmarkcache.jsm @@ -4,11 +4,10 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("bookmarkcache", { exports: ["Bookmark", "BookmarkCache", "Keyword", "bookmarkcache"], require: ["services", "util"] -}, this); +}); this.lazyRequire("storage", ["storage"]); diff --git a/common/modules/bootstrap.jsm b/common/modules/bootstrap.jsm index 7145110b..a672d196 100644 --- a/common/modules/bootstrap.jsm +++ b/common/modules/bootstrap.jsm @@ -4,200 +4,18 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -try { +var EXPORTED_SYMBOLS = ["require"]; -let { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; +// Deal with cross-compartment XML passing issues. +function create(proto) Object.create(proto); +function import(obj) { + let res = {}; + for each (let key in Object.getOwnPropertyNames(obj)) + Object.defineProperty(res, key, Object.getOwnPropertyDescriptor(obj, key)); + return res; +} -var EXPORTED_SYMBOLS = ["JSMLoader"]; +// Deal with subScriptLoader prepending crap to loaded URLs +Components.utils.import("resource://gre/modules/Services.jsm"); +function loadSubScript() Services.scriptloader.loadSubScript.apply(null, arguments); -var BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap"; -var JSMLoader = BOOTSTRAP_CONTRACT in Components.classes && - Components.classes[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader; - -if (JSMLoader && JSMLoader.bump === 6) - JSMLoader.global = this; -else - JSMLoader = { - bump: 6, - - builtin: Cu.Sandbox(this), - - canonical: {}, - - factories: [], - - name: "dactyl", - - global: this, - - globals: JSMLoader ? JSMLoader.globals : {}, - - 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: { - all: 0, - add: function add(major, minor, delta) { - this.all += delta; - - this[major] = (this[major] || 0) + delta; - if (minor) { - minor = ":" + minor; - this[minor] = (this[minor] || 0) + delta; - this[major + minor] = (this[major + minor] || 0) + delta; - } - }, - clear: function clear() { - for (let key in this) - if (typeof this[key] !== "number") - delete this[key]; - } - }, - - init: function init(suffix) { - this.initialized = true; - this.suffix = suffix || ""; - - let base = this.load("base.jsm", this.global); - this.global.EXPORTED_SYMBOLS = base.EXPORTED_SYMBOLS; - this.global.JSMLoader = this; - base.JSMLoader = this; - }, - - getTarget: function getTarget(url) { - if (url.indexOf(":") === -1) - url = "resource://dactyl" + this.suffix + "/" + url; - - let chan = this.io.newChannel(url, null, null); - chan.cancel(Cr.NS_BINDING_ABORTED); - return chan.name; - }, - - load: function load(name, target) { - let url = name; - if (url.indexOf(":") === -1) - url = "resource://dactyl" + this.suffix + "/" + url; - let targetURL = this.getTarget(url); - - let stale = this.stale[name] || this.stale[targetURL]; - if (stale) { - delete this.stale[name]; - delete this.stale[targetURL]; - - let loadURL = url.replace(RegExp("^(resource://dactyl)/"), "$1" + this.suffix + "/"); - - let global = this.globals[name]; - if (stale === targetURL) - this.loadSubScript(loadURL, global.global || global); - } - - try { - let now = Date.now(); - this.modules[url] = true; - let global = Cu.import(url, target); - - if (!(name in this.globals)) - this.times.add("require", name, Date.now() - now); - - return this.globals[name] = global; - } - catch (e) { - dump("Importing " + url + ": " + e + "\n" + (e.stack || Error().stack)); - throw e; - } - }, - - loadSubScript: function loadSubScript(script) { - let now = Date.now(); - this.loader.loadSubScript.apply(this.loader, arguments); - this.times.add("loadSubScript", script, Date.now() - now); - }, - - cleanup: function unregister() { - for each (let factory in this.factories) - this.manager.unregisterFactory(factory.classID, factory); - this.factories = {}; - }, - - purge: function purge() { - dump("dactyl: JSMLoader: purge\n"); - - this.bootstrap = null; - - if (Cu.unload) { - Object.keys(this.modules).reverse().forEach(function (url) { - try { - Cu.unload(url); - } - catch (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", "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); - } - } - } - }, - - Factory: function Factory(clas) ({ - __proto__: clas.prototype, - - createInstance: function (outer, iid) { - try { - if (outer != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - if (!clas.instance) - clas.instance = new clas(); - return clas.instance.QueryInterface(iid); - } - catch (e) { - Cu.reportError(e); - throw e; - } - } - }), - - registerFactory: function registerFactory(factory) { - if (Set.has(this.factories, factory.contractID)) - this.manager.unregisterFactory(this.factories[factory.contractID].classID, - this.factories[factory.contractID]); - - this.manager.registerFactory(factory.classID, - String(factory.classID), - factory.contractID, - factory); - this.factories[factory.contractID] = factory; - } - }; - -}catch(e){ dump(e + "\n" + (e.stack || Error().stack)); Components.utils.reportError(e) } - -// vim: set fdm=marker sw=4 sts=4 et ft=javascript: diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index c5491489..e4eabbe5 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -4,18 +4,18 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -try {"use strict"; +// "use strict"; -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("buffer", { exports: ["Buffer", "buffer"], require: ["prefs", "services", "util"] -}, this); +}); -this.lazyRequire("finder", ["RangeFind"]); -this.lazyRequire("overlay", ["overlay"]); -this.lazyRequire("storage", ["storage"]); -this.lazyRequire("template", ["template"]); +lazyRequire("bookmarkcache", ["bookmarkcache"]); +lazyRequire("finder", ["RangeFind"]); +lazyRequire("overlay", ["overlay"]); +lazyRequire("storage", ["storage"]); +lazyRequire("template", ["template"]); /** * A class to manage the primary web content buffer. The name comes @@ -2529,7 +2529,7 @@ Buffer.addPageInfoSection("s", "Security", function (verbose) { } }); -} catch(e){ if (!e.stack) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); } +// catch(e){ if (!e.stack) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); } endModule(); diff --git a/common/modules/cache.jsm b/common/modules/cache.jsm index c2408467..384e0cba 100644 --- a/common/modules/cache.jsm +++ b/common/modules/cache.jsm @@ -4,11 +4,13 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("cache", { exports: ["Cache", "cache"], require: ["config", "services", "util"] -}, this); +}); + +lazyRequire("overlay", ["overlay"]); +lazyRequire("storage", ["File"]); var Cache = Module("Cache", XPCOM(Ci.nsIRequestObserver), { init: function init() { diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index eca375bf..48fd43e1 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -8,11 +8,14 @@ try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("commands", { exports: ["ArgType", "Command", "Commands", "CommandOption", "Ex", "commands"], require: ["contexts", "messages", "util"] -}, this); +}); + +lazyRequire("help", ["help"]); +lazyRequire("options", ["Option"]); +lazyRequire("template", ["template"]); /** * A structure representing the options available for a command. diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 87453c82..c0cba3ae 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -6,11 +6,13 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("completion", { exports: ["CompletionContext", "Completion", "completion"] }, this); +lazyRequire("messages", ["_", "messages"]); +lazyRequire("template", ["template"]); + /** * Creates a new completion context. * diff --git a/common/modules/config.jsm b/common/modules/config.jsm index 5f7e6b56..da039e50 100644 --- a/common/modules/config.jsm +++ b/common/modules/config.jsm @@ -7,18 +7,17 @@ /* use strict */ let global = this; -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("config", { exports: ["ConfigBase", "Config", "config"], require: ["dom", "io", "protocol", "services", "util", "template"] -}, this); +}); -this.lazyRequire("addons", ["AddonManager"]); -this.lazyRequire("cache", ["cache"]); -this.lazyRequire("highlight", ["highlight"]); -this.lazyRequire("messages", ["_"]); -this.lazyRequire("prefs", ["localPrefs", "prefs"]); -this.lazyRequire("storage", ["storage", "File"]); +lazyRequire("addons", ["AddonManager"]); +lazyRequire("cache", ["cache"]); +lazyRequire("highlight", ["highlight"]); +lazyRequire("messages", ["_"]); +lazyRequire("prefs", ["localPrefs", "prefs"]); +lazyRequire("storage", ["storage", "File"]); function AboutHandler() {} AboutHandler.prototype = { diff --git a/common/modules/contexts.jsm b/common/modules/contexts.jsm index 6d32fb83..be0bed80 100644 --- a/common/modules/contexts.jsm +++ b/common/modules/contexts.jsm @@ -4,13 +4,16 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("contexts", { exports: ["Contexts", "Group", "contexts"], require: ["services", "util"] -}, this); +}); -this.lazyRequire("overlay", ["overlay"]); +lazyRequire("commands", ["ArgType", "CommandOption", "commands"]); +lazyRequire("options", ["Option"]); +lazyRequire("overlay", ["overlay"]); +lazyRequire("storage", ["File"]); +lazyRequire("template", ["template"]); var Const = function Const(val) Class.Property({ enumerable: true, value: val }); diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index e86b2b39..490d5dbc 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -5,10 +5,11 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("dom", { exports: ["$", "DOM", "NS", "XBL", "XHTML", "XUL"] -}, this); +}); + +lazyRequire("highlight", ["highlight"]); var XBL = Namespace("xbl", "http://www.mozilla.org/xbl"); var XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); diff --git a/common/modules/downloads.jsm b/common/modules/downloads.jsm index b02331ef..23ad3dc4 100644 --- a/common/modules/downloads.jsm +++ b/common/modules/downloads.jsm @@ -4,12 +4,12 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("downloads", { - exports: ["Download", "Downloads", "downloads"] -}, this); + exports: ["Download", "Downloads", "downloads"], + require: ["util"] +}); -this.lazyRequire("overlay", ["overlay"]); +lazyRequire("overlay", ["overlay"]); Cu.import("resource://gre/modules/DownloadUtils.jsm", this); diff --git a/common/modules/finder.jsm b/common/modules/finder.jsm index bde3f429..3dbe5d00 100644 --- a/common/modules/finder.jsm +++ b/common/modules/finder.jsm @@ -4,14 +4,13 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("finder", { exports: ["RangeFind", "RangeFinder", "rangefinder"], - require: ["prefs"] -}, this); + require: ["prefs", "util"] +}); -this.lazyRequire("buffer", ["Buffer"]); -this.lazyRequire("overlay", ["overlay"]); +lazyRequire("buffer", ["Buffer"]); +lazyRequire("overlay", ["overlay"]); function equals(a, b) XPCNativeWrapper(a) == XPCNativeWrapper(b); diff --git a/common/modules/help.jsm b/common/modules/help.jsm index dadadfcd..20b144d9 100644 --- a/common/modules/help.jsm +++ b/common/modules/help.jsm @@ -4,14 +4,14 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("help", { exports: ["help"], require: ["cache", "dom", "protocol", "services", "util"] -}, this); +}); -this.lazyRequire("completion", ["completion"]); -this.lazyRequire("overlay", ["overlay"]); +lazyRequire("completion", ["completion"]); +lazyRequire("overlay", ["overlay"]); +lazyRequire("template", ["template"]); var HelpBuilder = Class("HelpBuilder", { init: function init() { @@ -202,7 +202,6 @@ var Help = Module("Help", { return '\n' + '\n' + - '\n' +

{config.appName} Versions

diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index 7d6cfaf0..e6f18f39 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -4,13 +4,13 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("highlight", { exports: ["Highlight", "Highlights", "highlight"], require: ["services", "util"] -}, this); +}); -this.lazyRequire("styles", ["Styles", "styles"]); +lazyRequire("styles", ["Styles", "styles"]); +lazyRequire("template", ["template"]); var Highlight = Struct("class", "selector", "sites", "defaultExtends", "defaultValue", diff --git a/common/modules/io.jsm b/common/modules/io.jsm index dbd73816..6834ba6c 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -9,14 +9,15 @@ try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("io", { exports: ["IO", "io"], require: ["services"] -}, this); +}); -this.lazyRequire("config", ["config"]); -this.lazyRequire("contexts", ["Contexts", "contexts"]); +lazyRequire("config", ["config"]); +lazyRequire("contexts", ["Contexts", "contexts"]); +lazyRequire("storage", ["File", "storage"]); +lazyRequire("styles", ["styles"]); // TODO: why are we passing around strings rather than file objects? /** diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index f08c2d13..1e16b5ef 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -8,10 +8,11 @@ let { getOwnPropertyNames } = Object; try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("javascript", { exports: ["JavaScript", "javascript"] -}, this); +}); + +lazyRequire("template", ["template"]); let isPrototypeOf = Object.prototype.isPrototypeOf; diff --git a/common/modules/main.jsm b/common/modules/main.jsm index 27bcc609..6d6ba181 100644 --- a/common/modules/main.jsm +++ b/common/modules/main.jsm @@ -6,11 +6,10 @@ try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("main", { exports: ["ModuleBase"], require: ["config", "overlay", "services", "util"] -}, this); +}); var BASE = "resource://dactyl-content/"; @@ -130,7 +129,7 @@ var Modules = function Modules(window) { } } try { - require(jsmodules, script); + require(script, jsmodules); } catch (e) { util.dump("Loading script " + script + ":"); @@ -150,7 +149,7 @@ var Modules = function Modules(window) { wantXrays: false }); // Hack: - sandbox.Object = jsmodules.Object; + // sandbox.Object = jsmodules.Object; sandbox.File = jsmodules.File; sandbox.Math = jsmodules.Math; sandbox.__proto__ = proto || modules; @@ -181,7 +180,7 @@ overlay.overlayWindow(Object.keys(config.overlays), function _overlay(window) ({ defineModule.time("load", null, function _load() { config.modules.global - .forEach(function (name) defineModule.time("load", name, require, null, modules.jsmodules, name)); + .forEach(function (name) defineModule.time("load", name, require, null, name, modules.jsmodules)); config.modules.window .forEach(function (name) defineModule.time("load", name, modules.load, modules, name)); diff --git a/common/modules/messages.jsm b/common/modules/messages.jsm index 3e20f27a..abdcc528 100644 --- a/common/modules/messages.jsm +++ b/common/modules/messages.jsm @@ -4,13 +4,10 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -try { - -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("messages", { exports: ["Messages", "messages", "_"], require: ["services", "util"] -}, this); +}); var Messages = Module("messages", { @@ -206,6 +203,6 @@ var { _ } = messages; endModule(); -} catch(e){ if (!e.stack) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); } +// catch(e){ if (!e.stack) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); } // vim: set fdm=marker sw=4 ts=4 et ft=javascript: diff --git a/common/modules/options.jsm b/common/modules/options.jsm index dacafbdd..f579cef8 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -8,13 +8,18 @@ try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("options", { exports: ["Option", "Options", "ValueError", "options"], require: ["contexts", "messages", "storage"] -}, this); +}); -this.lazyRequire("config", ["config"]); +lazyRequire("cache", ["cache"]); +lazyRequire("config", ["config"]); +lazyRequire("commands", ["Commands"]); +lazyRequire("completion", ["CompletionContext"]); +lazyRequire("prefs", ["prefs"]); +lazyRequire("styles", ["Styles"]); +lazyRequire("template", ["template"]); /** @scope modules */ diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm index 0ccf502c..9209ed15 100644 --- a/common/modules/overlay.jsm +++ b/common/modules/overlay.jsm @@ -6,11 +6,12 @@ try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("overlay", { exports: ["overlay"], require: ["util"] -}, this); +}); + +lazyRequire("highlight", ["highlight"]); var getAttr = function getAttr(elem, ns, name) elem.hasAttributeNS(ns, name) ? elem.getAttributeNS(ns, name) : null; @@ -224,7 +225,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen iterator = ([elem.@id, elem.elements(), elem.@*::*.(function::name() != "id")] for each (elem in obj[key])); for (let [elem, xml, attr] in iterator) { - if (elem = doc.getElementById(elem)) { + if (elem = doc.getElementById(String(elem))) { let node = DOM.fromXML(xml, doc, obj.objects); if (!(node instanceof Ci.nsIDOMDocumentFragment)) elems.push(node); diff --git a/common/modules/prefs.jsm b/common/modules/prefs.jsm index 3f865b61..0caa8047 100644 --- a/common/modules/prefs.jsm +++ b/common/modules/prefs.jsm @@ -8,13 +8,13 @@ try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("prefs", { exports: ["Prefs", "localPrefs", "prefs"], require: ["services", "util"] -}, this); +}); -this.lazyRequire("messages", ["_"]); +lazyRequire("messages", ["_"]); +lazyRequire("template", ["template"]); var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { ORIGINAL: "extensions.dactyl.original.", diff --git a/common/modules/protocol.jsm b/common/modules/protocol.jsm index edb642ec..ab99a8d9 100644 --- a/common/modules/protocol.jsm +++ b/common/modules/protocol.jsm @@ -4,11 +4,10 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("protocol", { exports: ["LocaleChannel", "Protocol", "RedirectChannel", "StringChannel", "XMLChannel"], require: ["services", "util"] -}, this); +}); var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal); @@ -224,6 +223,7 @@ XMLChannel.prototype = { this.writes.push(services.io.newChannel(url, null, this.uri).open()); } catch (e) { + util.dump("addChannel('" + url + "'):"); util.reportError(e); } }, diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index efc0f2de..155cf393 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -12,15 +12,14 @@ // FIXME: // - finish 1.9.0 support if we're going to support sanitizing in Melodactyl -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("sanitizer", { exports: ["Range", "Sanitizer", "sanitizer"], require: ["config", "prefs", "services", "util"] -}, this); +}); -this.lazyRequire("messages", ["_"]); -this.lazyRequire("storage", ["storage"]); -this.lazyRequire("template", ["teplate"]); +lazyRequire("messages", ["_"]); +lazyRequire("storage", ["storage"]); +lazyRequire("template", ["template"]); let tmp = {}; JSMLoader.loadSubScript("chrome://browser/content/sanitize.js", tmp); diff --git a/common/modules/services.jsm b/common/modules/services.jsm index bf8db8c2..c9992a9b 100644 --- a/common/modules/services.jsm +++ b/common/modules/services.jsm @@ -7,10 +7,9 @@ try { var global = this; -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("services", { exports: ["services"] -}, this); +}); /** * A lazily-instantiated XPCOM class and service cache. diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 664124e8..ff40d8de 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -4,14 +4,14 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("storage", { exports: ["File", "Storage", "storage"], require: ["services", "util"] -}, this); +}); -this.lazyRequire("config", ["config"]); -this.lazyRequire("io", ["IO"]); +lazyRequire("config", ["config"]); +lazyRequire("io", ["IO"]); +lazyRequire("overlay", ["overlay"]); var win32 = /^win(32|nt)$/i.test(services.runtime.OS); var myObject = JSON.parse("{}").constructor; diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 98d49605..11c2a415 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -4,11 +4,13 @@ // given in the LICENSE.txt file included with this file. /* use strict */ -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("styles", { exports: ["Style", "Styles", "styles"], require: ["services", "util"] -}, this); +}); + +lazyRequire("contexts", ["Contexts"]); +lazyRequire("template", ["template"]); function cssUri(css) "chrome-data:text/css," + encodeURI(css); var namespace = "@namespace html " + XHTML.uri.quote() + ";\n" + diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 09300d0e..947d8c28 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -5,11 +5,12 @@ /* use strict */ let global = this; -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("template", { exports: ["Binding", "Template", "template"], require: ["util"] -}, this); +}); + +lazyRequire("help", ["help"]); default xml namespace = XHTML; @@ -282,7 +283,8 @@ var Template = Module("Template", { } }, - _sandbox: Class.Memoize(function () Cu.Sandbox(global, { wantXrays: false })), + _sandbox: Class.Memoize(function () Cu.Sandbox(Cu.getGlobalForObject(global), + { wantXrays: false })), // if "processStrings" is true, any passed strings will be surrounded by " and // any line breaks are displayed as \n diff --git a/common/modules/util.jsm b/common/modules/util.jsm index c5cd610f..1ffd484f 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -8,13 +8,14 @@ try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("util", { exports: ["DOM", "$", "FailedAssertion", "Math", "NS", "Point", "Util", "XBL", "XHTML", "XUL", "util"], require: ["dom", "services"] -}, this); +}); -this.lazyRequire("overlay", ["overlay"]); +lazyRequire("overlay", ["overlay"]); +lazyRequire("storage", ["File", "storage"]); +lazyRequire("template", ["template"]); var FailedAssertion = Class("FailedAssertion", ErrorBase, { init: function init(message, level, noTrace) { @@ -1615,7 +1616,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @singleton */ var GlobalMath = Math; -var Math = update(Object.create(GlobalMath), { +this.Math = update(Object.create(GlobalMath), { /** * Returns the specified *value* constrained to the range *min* - *max*. * diff --git a/pentadactyl/config.json b/pentadactyl/config.json index 844c5f42..5ba3bdd9 100644 --- a/pentadactyl/config.json +++ b/pentadactyl/config.json @@ -5,6 +5,10 @@ "host": "Firefox", "hostbin": "firefox", + "module-paths": [ + "resource://dactyl/" + ], + "autocommands": { "BookmarkAdd": "Triggered after a page is bookmarked", "BookmarkChange": "Triggered after a page's bookmark is changed",