diff --git a/common/bootstrap.js b/common/bootstrap.js index c006d1cc..d0dd98a8 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -56,12 +56,15 @@ let addon = null; let addonData = null; let basePath = null; let bootstrap; +let bootstrap_jsm; let categories = []; let components = {}; let resources = []; let getURI = null; let JSMLoader = { + SANDBOX: Cu.nukeSandbox && false, + get addon() addon, currentModule: null, @@ -131,7 +134,7 @@ let JSMLoader = { return this.modules[name] = this.globals[uri]; this.globals[uri] = this.modules[name]; - bootstrap.loadSubScript(url, this.modules[name]); + bootstrap_jsm.loadSubScript(url, this.modules[name]); return; } catch (e) { @@ -175,7 +178,7 @@ let JSMLoader = { }, // Cuts down on stupid, fscking url mangling. - get loadSubScript() bootstrap.loadSubScript, + get loadSubScript() bootstrap_jsm.loadSubScript, cleanup: function unregister() { for each (let factory in this.factories.splice(0)) @@ -242,7 +245,14 @@ function init() { JSMLoader.config = JSON.parse(httpGet("resource://dactyl-local/config.json").responseText); - bootstrap = module(BOOTSTRAP); + bootstrap_jsm = module(BOOTSTRAP); + if (!JSMLoader.SANDBOX) + bootstrap = bootstrap_jsm; + else { + bootstrap = Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].createInstance(), + { sandboxName: BOOTSTRAP }); + Services.scriptloader.loadSubScript(BOOTSTRAP, bootstrap); + } bootstrap.require = JSMLoader.load("base").require; // Flush the cache if necessary, just to be paranoid @@ -273,7 +283,7 @@ function init() { if (!(BOOTSTRAP_CONTRACT in Cc)) { // Use Sandbox to prevent closures over this scope - let sandbox = Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].getService()); + let sandbox = Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].createInstance()); let factory = Cu.evalInSandbox("({ createInstance: function () this })", sandbox); factory.classID = Components.ID("{f541c8b0-fe26-4621-a30b-e77d21721fb5}"); @@ -416,11 +426,12 @@ function shutdown(data, reason) { JSMLoader.atexit(strReason); JSMLoader.cleanup(strReason); - if (Cu.unload) - Cu.unload(BOOTSTRAP); - else - bootstrap.require = null; - + if (JSMLoader.SANDBOX) + Cu.nukeSandbox(bootstrap); + bootstrap_jsm.require = null; + Cu.unload(BOOTSTRAP); + bootstrap = null; + bootstrap_jsm = null; for each (let [category, entry] in categories) categoryManager.deleteCategoryEntry(category, entry, false); diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 0e555bd7..65ec1150 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -135,7 +135,7 @@ var Bookmarks = Module("bookmarks", { checkBookmarked: function checkBookmarked(uri) { if (PlacesUtils.asyncGetBookmarkIds) - PlacesUtils.asyncGetBookmarkIds(uri, function (ids) { + PlacesUtils.asyncGetBookmarkIds(uri, function withBookmarkIDs(ids) { statusline.bookmarked = ids.length; }); else diff --git a/common/content/dactyl.js b/common/content/dactyl.js index e3bf2495..2d882e4b 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -467,11 +467,11 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @param {Object} context The context object into which the script * should be loaded. */ - loadScript: function (uri, context) { + loadScript: function loadScript(uri, context) { JSMLoader.loadSubScript(uri, context, File.defaultEncoding); }, - userEval: function (str, context, fileName, lineNumber) { + userEval: function userEval(str, context, fileName, lineNumber) { let ctxt; if (jsmodules.__proto__ != window && jsmodules.__proto__ != XPCNativeWrapper(window) && jsmodules.isPrototypeOf(context)) @@ -523,7 +523,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * Acts like the Function builtin, but the code executes in the * userContext global. */ - userFunc: function () { + userFunc: function userFunc() { return this.userEval( "(function userFunction(" + Array.slice(arguments, 0, -1).join(", ") + ")" + " { " + arguments[arguments.length - 1] + " })"); @@ -538,7 +538,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @param {boolean} silent Whether the command should be echoed on the * command line. */ - execute: function (str, modifiers, silent) { + execute: function execute(str, modifiers, silent) { // skip comments and blank lines if (/^\s*("|$)/.test(str)) return; @@ -622,7 +622,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @param {string} feature The feature name. * @returns {boolean} */ - has: function (feature) Set.has(config.features, feature), + has: function has(feature) Set.has(config.features, feature), /** * @private @@ -762,7 +762,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { get: function globalVariables() this._globalVariables }), - loadPlugins: function (args, force) { + loadPlugins: function loadPlugins(args, force) { function sourceDirectory(dir) { dactyl.assert(dir.isReadable(), _("io.notReadable", dir.path)); @@ -819,7 +819,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @param {string|Object} msg The message to print. * @param {number} level The logging level 0 - 15. */ - log: function (msg, level) { + log: function log(msg, level) { let verbose = config.prefs.get("loglevel", 0); if (!level || level <= verbose) { @@ -889,7 +889,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * tabs. * @returns {boolean} */ - open: function (urls, params, force) { + open: function open(urls, params, force) { if (typeof urls == "string") urls = dactyl.parseURLs(urls); @@ -1078,7 +1078,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @param {boolean} force Forcibly quit irrespective of whether all * windows could be closed individually. */ - quit: function (saveSession, force) { + quit: function quit(saveSession, force) { if (!force && !this.confirmQuit()) return; @@ -1095,7 +1095,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { /** * Restart the host application. */ - restart: function (args) { + restart: function restart(args) { if (!this.confirmQuit()) return; @@ -1171,7 +1171,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @returns {Object} * @see Commands#parseArgs */ - parseCommandLine: function (cmdline) { + parseCommandLine: function parseCommandLine(cmdline) { try { return commands.get("rehash").parseArgs(cmdline); } @@ -1180,7 +1180,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { return []; } }, - wrapCallback: function (callback, self) { + wrapCallback: function wrapCallback(callback, self) { self = self || this; let save = ["forceOpen"]; let saved = save.map(function (p) dactyl[p]); @@ -1616,13 +1616,13 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { "Reload the " + config.appName + " add-on", function (args) { if (args.trailing) - storage.session.rehashCmd = args.trailing; // Hack. + storage.storeForSession("rehashCmd", args.trailing); // Hack. args.break = true; if (args["+purgecaches"]) cache.flush(); - util.rehash(args); + util.delay(function () { util.rehash(args) }); }, { argCount: "0", // FIXME diff --git a/common/content/hints.js b/common/content/hints.js index 62740ccb..3b8b1252 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -862,7 +862,7 @@ var Hints = Module("hints", { } else if (option == "label") { if (elem.id) { - let label = elem.ownerDocument.dactylLabels[elem.id]; + let label = (elem.ownerDocument.dactylLabels || {})[elem.id]; if (label) return [label.textContent.toLowerCase(), true]; } diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 02f8833e..a3494b8b 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -146,7 +146,7 @@ defineModule("base", { "debuggerProperties", "defineModule", "deprecated", "endModule", "forEach", "isArray", "isGenerator", "isinstance", "isObject", "isString", "isSubclass", "isXML", "iter", "iterAll", "iterOwnProperties", "keys", "literal", "memoize", "octal", "properties", - "require", "set", "update", "values" + "require", "set", "update", "values", "update_" ] }); @@ -598,7 +598,7 @@ function memoize(obj, key, getter) { } } -let sandbox = Cu.Sandbox(Cu.getGlobalForObject(this)); +let sandbox = Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].createInstance()); sandbox.__proto__ = this; /** @@ -632,7 +632,7 @@ function update(target) { if (typeof desc.value === "function" && target.__proto__ && !(desc.value instanceof Ci.nsIDOMElement /* wtf? */)) { let func = desc.value.wrapped || desc.value; if (!func.superapply) { - func.__defineGetter__("super", function () Object.getPrototypeOf(target)[k]); + func.__defineGetter__("super", function get_super() Object.getPrototypeOf(target)[k]); func.superapply = function superapply(self, args) let (meth = Object.getPrototypeOf(target)[k]) meth && meth.apply(self, args); @@ -647,6 +647,33 @@ function update(target) { } return target; } +function update_(target) { + for (let i = 1; i < arguments.length; i++) { + let src = arguments[i]; + Object.getOwnPropertyNames(src || {}).forEach(function (k) { + let desc = Object.getOwnPropertyDescriptor(src, k); + if (desc.value instanceof Class.Property) + desc = desc.value.init(k, target) || desc.value; + + try { + if (typeof desc.value === "function" && target.__proto__ && !(desc.value instanceof Ci.nsIDOMElement /* wtf? */)) { + let func = desc.value.wrapped || desc.value; + if (!func.superapply) { + func.__defineGetter__("super", function get_super_() Object.getPrototypeOf(target)[k]); + func.superapply = function super_apply(self, args) + let (meth = Object.getPrototypeOf(target)[k]) + meth && meth.apply(self, args); + func.supercall = function super_call(self) + func.superapply(self, Array.slice(arguments, 1)); + } + } + Object.defineProperty(target, k, desc); + } + catch (e) {} + }); + } + return target; +} /** * @constructor Class diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 10c1551b..209068d5 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -176,6 +176,8 @@ var ObjectStore = Class("ObjectStore", StoreBase, { } }); +var sessionGlobal = Cu.import("resource://gre/modules/Services.jsm", {}) + var Storage = Module("Storage", { alwaysReload: {}, @@ -184,7 +186,7 @@ var Storage = Module("Storage", { let { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); if (!Services.dactylSession) - Services.dactylSession = {}; + Services.dactylSession = Cu.createObjectIn(sessionGlobal); this.session = Services.dactylSession; }, @@ -201,6 +203,13 @@ var Storage = Module("Storage", { this.observers = {}; }, + storeForSession: function storeForSession(key, val) { + if (val) + this.session[key] = sessionGlobal.JSON.parse(JSON.stringify(val)); + else + delete this.dactylSession[key]; + }, + infoPath: Class.Memoize(function () File(IO.runtimePath.replace(/,.*/, "")) .child("info").child(config.profileName)), diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 6d14d4e8..47fd94db 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -173,7 +173,7 @@ var Template = Module("Template", { !(item.extra && item.extra.length) ? [] : ["span", { highlight: "URLExtra" }, " (", - this.map(item.extra, function (e) + template.map(item.extra, function (e) ["", e[0], ": ", ["span", { highlight: e[2] }, e[1]]], "\u00a0"), diff --git a/common/modules/util.jsm b/common/modules/util.jsm index ea396652..0e83efe7 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -64,7 +64,7 @@ var wrapCallback = function wrapCallback(fn, isEvent) { var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { Magic: Magic, - init: function () { + init: function init() { this.Array = array; this.addObserver(this); @@ -104,7 +104,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), var global = Class.objectGlobal(obj); return { - __noSuchMethod__: function (meth, args) { + __noSuchMethod__: function __noSuchMethod__(meth, args) { let win = overlay.activeWindow; var dactyl = global && global.dactyl || win && win.dactyl; @@ -118,7 +118,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), } }; }, { - __noSuchMethod__: function () this().__noSuchMethod__.apply(null, arguments) + __noSuchMethod__: function __noSuchMethod__() this().__noSuchMethod__.apply(null, arguments) }), /** @@ -173,7 +173,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {string} message The message to present to the * user on failure. */ - assert: function (condition, message, quiet) { + assert: function assert(condition, message, quiet) { if (!condition) throw FailedAssertion(message, 1, quiet === undefined ? true : quiet); return condition; @@ -266,7 +266,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { elements: [], seen: {}, - valid: function (obj) this.elements.every(function (e) !e.test || e.test(obj)) + valid: function valid(obj) this.elements.every(function (e) !e.test || e.test(obj)) }); let end = 0; @@ -296,7 +296,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), stack.top.elements.push(update( function (obj) obj[char] != null ? quote(obj, char) : "", - { test: function (obj) obj[char] != null })); + { test: function test(obj) obj[char] != null })); for (let elem in array.iterValues(stack)) elem.seen[char] = true; @@ -349,7 +349,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { elements: [], seen: {}, - valid: function (obj) this.elements.every(function (e) !e.test || e.test(obj)) + valid: function valid(obj) this.elements.every(function (e) !e.test || e.test(obj)) }); let defaults = { lt: "<", gt: ">" }; @@ -399,9 +399,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), function (obj) obj[name] != null && idx in obj[name] ? quote(obj[name][idx]) : Set.has(obj, name) ? "" : unknown(full), { - test: function (obj) obj[name] != null && idx in obj[name] - && obj[name][idx] !== false - && (!flags.e || obj[name][idx] != "") + test: function test(obj) obj[name] != null && idx in obj[name] + && obj[name][idx] !== false + && (!flags.e || obj[name][idx] != "") })); } else { @@ -409,9 +409,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), function (obj) obj[name] != null ? quote(obj[name]) : Set.has(obj, name) ? "" : unknown(full), { - test: function (obj) obj[name] != null - && obj[name] !== false - && (!flags.e || obj[name] != "") + test: function test(obj) obj[name] != null + && obj[name] !== false + && (!flags.e || obj[name] != "") })); } @@ -519,6 +519,17 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), } }, + /** + * Briefly delay the execution of the passed function. + * + * @param {function} callback The function to delay. + */ + delay: function delay(callback) { + let { mainThread } = services.threading; + mainThread.dispatch(callback, + mainThread.DISPATCH_NORMAL); + }, + /** * Removes certain backslash-quoted characters while leaving other * backslash-quoting sequences untouched. @@ -556,7 +567,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {string} stack The stack trace from an Error. * @returns {[string]} The stack frames. */ - stackLines: function (stack) { + stackLines: function stackLines(stack) { let lines = []; let match, re = /([^]*?)@([^@\n]*)(?:\n|$)/g; while (match = re.exec(stack)) @@ -688,7 +699,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {string} url * @returns {string|null} */ - getHost: function (url) { + getHost: function getHost(url) { try { return util.createURI(url).host; } @@ -809,7 +820,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {Object} r2 * @returns {Object} */ - intersection: function (r1, r2) ({ + intersection: function intersection(r1, r2) ({ get width() this.right - this.left, get height() this.bottom - this.top, left: Math.max(r1.left, r2.left), @@ -1031,6 +1042,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), if (color) value = template.highlight(value, true, 150, !color); + else if (value instanceof Magic) + value = String(value); else value = util.clip(String(value).replace(/\n/g, "^J"), 150); @@ -1121,7 +1134,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), }, observers: { - "dactyl-cleanup-modules": function (subject, reason) { + "dactyl-cleanup-modules": function cleanupModules(subject, reason) { defineModule.loadLog.push("dactyl: util: observe: dactyl-cleanup-modules " + reason); for (let module in values(defineModule.modules)) @@ -1135,7 +1148,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), if (!this.rehashing) services.observer.addObserver(this, "dactyl-rehash", true); }, - "dactyl-rehash": function () { + "dactyl-rehash": function dactylRehash() { services.observer.removeObserver(this, "dactyl-rehash"); defineModule.loadLog.push("dactyl: util: observe: dactyl-rehash"); @@ -1148,7 +1161,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), module.init(); } }, - "dactyl-purge": function () { + "dactyl-purge": function dactylPurge() { this.rehashing = 1; }, }, @@ -1258,7 +1271,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), let res = update(RegExp(expr, flags.replace("x", "")), { closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "closure")), dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"], - iterate: function (str, idx) util.regexp.iterate(this, str, idx) + iterate: function iterate(str, idx) util.regexp.iterate(this, str, idx) }); // Return a struct with properties for named parameters if we @@ -1321,8 +1334,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * Reloads dactyl in entirety by disabling the add-on and * re-enabling it. */ - rehash: function (args) { - storage.session.commandlineArgs = args; + rehash: function rehash(args) { + storage.storeForSession("commandlineArgs", args); this.timeout(function () { this.flushCache(); this.rehashing = true; @@ -1408,7 +1421,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {Window} window * @returns {nsISelectionController} */ - selectionController: function (win) + selectionController: function selectionController(win) win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation) .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsISelectionDisplay) .QueryInterface(Ci.nsISelectionController), @@ -1427,7 +1440,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * * @param {number} delay The time period for which to sleep in milliseconds. */ - sleep: function (delay) { + sleep: function sleep(delay) { let mainThread = services.threading.mainThread; let end = Date.now() + delay; @@ -1448,7 +1461,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {number} limit The maximum number of elements to return. * @returns {[string]} */ - split: function (str, re, limit) { + split: function split(str, re, limit) { re.lastIndex = 0; if (!re.global) re = RegExp(re.source || re, "g"); @@ -1508,7 +1521,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * interrupted by pressing , in which case, * Error("Interrupted") will be thrown. */ - threadYield: function (flush, interruptable) { + threadYield: function threadYield(flush, interruptable) { this.yielders++; try { let mainThread = services.threading.mainThread; @@ -1647,7 +1660,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {nsIDOMWindow} win The window for which to find domains. * @returns {[string]} The visible domains. */ - visibleHosts: function (win) { + visibleHosts: function visibleHosts(win) { let res = [], seen = {}; (function rec(frame) { try { @@ -1667,7 +1680,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {nsIDOMWindow} win The window for which to find URIs. * @returns {[nsIURI]} The visible URIs. */ - visibleURIs: function (win) { + visibleURIs: function visibleURIs(win) { let res = [], seen = {}; (function rec(frame) { try { diff --git a/pentadactyl/NEWS b/pentadactyl/NEWS index 876fbad5..d653d640 100644 --- a/pentadactyl/NEWS +++ b/pentadactyl/NEWS @@ -3,6 +3,7 @@ - renamed :mksyntax to :mkvimruntime which now generates all Vim related files. - Vimball packages are no longer available. + • Removed and mappings. 1.0: • Extensive Firefox 4 support, including: