From 7e712dae0f2fdc3a91d4193ca860cb9701007eb5 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 25 Dec 2010 13:37:26 -0500 Subject: [PATCH 1/2] Fix some key handling bugs. Closes issue #210. --- common/content/commandline.js | 2 ++ common/content/events.js | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/common/content/commandline.js b/common/content/commandline.js index 739cda81..0e2a9fa8 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -470,6 +470,7 @@ const CommandLine = Module("commandline", { this.widgets.message = null; modes.push(modes.COMMAND_LINE, this.currentExtendedMode, { + onEvent: this.closure.onEvent, leave: function (params) { if (params.pop) commandline.leave(); @@ -746,6 +747,7 @@ const CommandLine = Module("commandline", { modes.push(modes.COMMAND_LINE, modes.PROMPT | extra.extended, update(Object.create(extra), { + onEvent: extra.onEvent || this.closure.onEvent, leave: function leave(stack) { commandline.leave(stack); leave.supercall(this, stack); diff --git a/common/content/events.js b/common/content/events.js index d1166e2b..bb99b277 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -1011,11 +1011,11 @@ const Events = Module("events", { } let res = this.onKeyPress(event); - if (res === true) + if (res === true || res == null) kill(event); else if (isArray(res)) { if (this.fallthrough) { - if (this.fallthrough(res[0]) === true) + if (dactyl.trapErrors(this.fallthrough, this, res[0]) === true) kill(res[0]); } else if (Events.isEscape(event)) @@ -1025,10 +1025,6 @@ const Events = Module("events", { dactyl.beep(); kill(event); } - - if (this.main == modes.COMMAND_LINE) - if (!(this.extended & modes.INPUT_MULTILINE)) - dactyl.trapErrors(commandline.onEvent, commandline, event); } // Reprocess unconsumed events From 617a37db1ec790f6f7e0c5c15e8063e3c40c4f6b Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 25 Dec 2010 13:45:05 -0500 Subject: [PATCH 2/2] Merge changes from bootstrapped. --- common/components/commandline-handler.js | 17 +++--- common/components/protocols.js | 18 ++++--- common/content/commandline.js | 2 + common/content/dactyl.js | 21 ++++---- common/modules/base.jsm | 67 +++++++++++++++++++----- common/modules/bookmarkcache.jsm | 8 +-- common/modules/highlight.jsm | 8 +-- common/modules/prefs.jsm | 2 +- common/modules/sanitizer.jsm | 6 +-- common/modules/services.jsm | 3 +- common/modules/storage.jsm | 14 ++--- common/modules/styles.jsm | 8 +-- common/modules/template.jsm | 2 +- common/modules/util.jsm | 21 ++++---- 14 files changed, 124 insertions(+), 73 deletions(-) diff --git a/common/components/commandline-handler.js b/common/components/commandline-handler.js index 3083af0f..6998b34d 100644 --- a/common/components/commandline-handler.js +++ b/common/components/commandline-handler.js @@ -4,14 +4,17 @@ // given in the LICENSE.txt file included with this file. "use strict"; -const Ci = Components.interfaces, Cc = Components.classes; +var global = this; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); -const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService) +var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService) .getBranch("extensions.dactyl."); -const appName = prefs.getComplexValue("appName", Ci.nsISupportsString).data; -const name = prefs.getComplexValue("name", Ci.nsISupportsString).data; +var appName = prefs.getComplexValue("appName", Ci.nsISupportsString).data; +var name = prefs.getComplexValue("name", Ci.nsISupportsString).data; function CommandLineHandler() { this.wrappedJSObject = this; @@ -45,9 +48,9 @@ CommandLineHandler.prototype = { }; if (XPCOMUtils.generateNSGetFactory) - const NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]); + var NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]); else - const NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]); -var EXPORTED_SYMBOLS = ["NSGetFactory"]; + var NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]); +var EXPORTED_SYMBOLS = ["NSGetFactory", "global"]; // vim: set fdm=marker sw=4 ts=4 et: diff --git a/common/components/protocols.js b/common/components/protocols.js index b68df555..40ae3ae0 100644 --- a/common/components/protocols.js +++ b/common/components/protocols.js @@ -12,14 +12,18 @@ * By Kris Maglione, ideas from Ed Anuff's nsChromeExtensionHandler. */ -const Ci = Components.interfaces, Cc = Components.classes; +var NAME = "protocols"; +var global = this; +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); -const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); -const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService) +var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); +var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService) .getBranch("extensions.dactyl."); -const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal); +var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal); function dataURL(type, data) "data:" + (type || "application/xml;encoding=UTF-8") + "," + escape(data); function makeChannel(url, orig) { @@ -199,9 +203,9 @@ Shim.prototype = { }; if (XPCOMUtils.generateNSGetFactory) - const NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutHandler, ChromeData, Dactyl, Shim]); + var NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutHandler, ChromeData, Dactyl, Shim]); else - const NSGetModule = XPCOMUtils.generateNSGetModule([AboutHandler, ChromeData, Dactyl, Shim]); -var EXPORTED_SYMBOLS = ["NSGetFactory"]; + var NSGetModule = XPCOMUtils.generateNSGetModule([AboutHandler, ChromeData, Dactyl, Shim]); +var EXPORTED_SYMBOLS = ["NSGetFactory", "global"]; // vim: set fdm=marker sw=4 ts=4 et: diff --git a/common/content/commandline.js b/common/content/commandline.js index 0e2a9fa8..4e6e186e 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -539,6 +539,8 @@ const CommandLine = Module("commandline", { this.widgets.message = null; if (modes.main != modes.COMMAND_LINE) this.widgets.command = null; + if ((modes.extended & modes.OUTPUT_MULTILINE) && this.widgets.multilineOutput.atEnd) + modes.pop(); if (modes.extended != modes.OUTPUT_MULTILINE) this.multilineOutputVisible = false; }, diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 39319659..dda0c8d8 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -1844,8 +1844,7 @@ const Dactyl = Module("dactyl", { commands.add(["res[tart]"], "Force " + config.appName + " to restart", - function () { dactyl.restart(); }, - { argCount: "0" }); + function () { dactyl.restart(); }); var toolbox = document.getElementById("navigator-toolbox"); if (toolbox) { @@ -2070,14 +2069,16 @@ const Dactyl = Module("dactyl", { if (!services.commandLineHandler) services.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=" + config.name); - let commandline = services.commandLineHandler.optionValue; - if (commandline) { - let args = dactyl.parseCommandLine(commandline); - dactyl.commandLineOptions.rcFile = args["+u"]; - dactyl.commandLineOptions.noPlugins = "++noplugin" in args; - dactyl.commandLineOptions.postCommands = args["+c"]; - dactyl.commandLineOptions.preCommands = args["++cmd"]; - util.dump("Processing command-line option: " + commandline); + if (services.commandlinehandler) { + let commandline = services.commandLineHandler.optionValue; + if (commandline) { + let args = dactyl.parseCommandLine(commandline); + dactyl.commandLineOptions.rcFile = args["+u"]; + dactyl.commandLineOptions.noPlugins = "++noplugin" in args; + dactyl.commandLineOptions.postCommands = args["+c"]; + dactyl.commandLineOptions.preCommands = args["++cmd"]; + util.dump("Processing command-line option: " + commandline); + } } dactyl.log("Command-line options: " + util.objectToString(dactyl.commandLineOptions), 3); diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 35ff5875..7de7cb39 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -4,10 +4,49 @@ // given in the LICENSE.txt file included with this file. "use strict"; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const Cu = Components.utils; +if (!JSMLoader) + var JSMLoader = { + builtin: Components.utils.Sandbox(this), + globals: {}, + stale: {}, + load: function load(url, target) { + dump("dactyl: load: " + url + "\n"); + if (this.stale[url]) { + delete this.stale[url]; + dump("dactyl: load stale\n"); + + let global = this.globals[url]; + for each (let prop in Object.getOwnPropertyNames(global)) + try { + if (!set.has(this.builtin, prop) && [this, set].indexOf(global[prop]) < 0) + delete global[prop]; + } + catch (e) {} + + Components.classes["@mozilla.org/moz/jssubscript-loader;1"] + .getService(Components.interfaces.mozIJSSubScriptLoader) + .loadSubScript(url, this.globals[url]); + dump("dactyl: load reloaded: " + url + "\n"); + } + Components.utils.import(url, target); + }, + purge: function purge() { + for (let [url, global] in Iterator(this.globals)) + this.stale[url] = true; + }, + registerGlobal: function registerGlobal(uri, obj) { + if (Cu.getGlobalForObject) + this.globals[uri.replace(/.* -> /, "")] = Cu.getGlobalForObject(obj); + } + }; + +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cr = Components.results; +var Cu = Components.utils; + +Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication) + .storage.set("dactyl.JSMLoader", JSMLoader); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); try { @@ -98,7 +137,8 @@ let loaded = {}; let currentModule; function defineModule(name, params) { let module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__; - defineModule.globals.push(module); + JSMLoader.registerGlobal(Components.stack.caller.filename, module); + module.NAME = name; module.EXPORTED_SYMBOLS = params.exports || []; defineModule.loadLog.push("defineModule " + name); @@ -115,7 +155,6 @@ function defineModule(name, params) { currentModule = module; } -defineModule.globals = []; defineModule.loadLog = []; Object.defineProperty(defineModule.loadLog, "push", { value: function (val) { defineModule.dump(val + "\n"); this[this.length] = val; } @@ -162,7 +201,7 @@ function endModule() { function require(obj, name, from) { try { defineModule.loadLog.push((from || "require") + ": loading " + name + " into " + obj.NAME); - Cu.import("resource://dactyl/" + name + ".jsm", obj); + JSMLoader.load("resource://dactyl/" + name + ".jsm", obj); } catch (e) { defineModule.dump("loading " + String.quote("resource://dactyl/" + name + ".jsm") + "\n"); @@ -176,7 +215,7 @@ function require(obj, name, from) { defineModule("base", { // sed -n 's/^(const|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt exports: [ - "ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "Object", "Runnable", + "ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "JSMLoader", "Object", "Runnable", "Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "array", "call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule", "deprecated", "endModule", "forEach", "isArray", "isGenerator", @@ -478,7 +517,7 @@ function isSubclass(targ, src) { * @param {object|string|[object|string]} src The types to check targ against. * @returns {boolean} */ -const isinstance_types = { +var isinstance_types = { boolean: Boolean, string: String, function: Function, @@ -513,7 +552,7 @@ function isObject(obj) typeof obj === "object" && obj != null || obj instanceof * any window, frame, namespace, or execution context, which * is not the case when using (obj instanceof Array). */ -const isArray = +var isArray = Array.isArray // This is bloody stupid. ? function isArray(val) Array.isArray(val) || val && val.constructor && val.constructor.name === "Array" @@ -617,7 +656,7 @@ sandbox.__proto__ = this; * is prepended to its arguments. */ // Hack to get around lack of access to caller in strict mode. -const withCallerGlobal = Cu.evalInSandbox( */ -const Highlights = Module("Highlight", { +var Highlights = Module("Highlight", { init: function () { this.highlight = {}; this.loaded = {}; diff --git a/common/modules/prefs.jsm b/common/modules/prefs.jsm index 63ebac52..c948dca9 100644 --- a/common/modules/prefs.jsm +++ b/common/modules/prefs.jsm @@ -13,7 +13,7 @@ defineModule("prefs", { use: ["template"] }); -const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { +var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { SAVED: "extensions.dactyl.saved.", RESTORE: "extensions.dactyl.restore.", diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index 13274585..f9141d2c 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -24,7 +24,7 @@ let tmp = {}; services.subscriptLoader.loadSubScript("chrome://browser/content/sanitize.js", tmp); tmp.Sanitizer.prototype.__proto__ = Class.prototype; -const Range = Struct("min", "max"); +var Range = Struct("min", "max"); Range.prototype.contains = function (date) date == null || (this.min == null || date >= this.min) && (this.max == null || date <= this.max); Range.prototype.__defineGetter__("isEternity", function () this.max == null && this.min == null); @@ -33,7 +33,7 @@ Range.prototype.__defineGetter__("native", function () this.isEternity ? null : [range.min || 0, range.max == null ? Number.MAX_VALUE : range.max]); -const Item = Class("Item", { +var Item = Class("Item", { init: function (name) { this.name = name; }, @@ -55,7 +55,7 @@ const Item = Class("Item", { SHUTDOWN_BRANCH: "privacy.clearOnShutdown." }); -const Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference], tmp.Sanitizer), { +var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference], tmp.Sanitizer), { sessionStart: Date.now() * 1000, init: function () { diff --git a/common/modules/services.jsm b/common/modules/services.jsm index 38212cf8..77060989 100644 --- a/common/modules/services.jsm +++ b/common/modules/services.jsm @@ -14,7 +14,7 @@ defineModule("services", { /** * A lazily-instantiated XPCOM class and service cache. */ -const Services = Module("Services", { +var Services = Module("Services", { init: function () { this.classes = {}; this.services = {}; @@ -36,6 +36,7 @@ const Services = Module("Services", { this.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager); this.add("favicon", "@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService); this.add("focus", "@mozilla.org/focus-manager;1", Ci.nsIFocusManager); + this.add("fuel", "@mozilla.org/fuel/application;1", Ci.fuelIApplication); this.add("history", "@mozilla.org/browser/global-history;2", [Ci.nsIBrowserHistory, Ci.nsIGlobalHistory3, Ci.nsINavHistoryService, Ci.nsPIPlacesDatabase]); this.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService); diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 6e06377b..bb18bf0e 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -7,14 +7,14 @@ if (this.XPCSafeJSObjectWrapper == null) this.XPCSafeJSObjectWrapper = XPCNativeWrapper; -const myObject = Object; +var myObject = Object; Components.utils.import("resource://dactyl/base.jsm"); defineModule("storage", { exports: ["File", "storage"], require: ["services", "util"] }); -const win32 = /^win(32|nt)$/i.test(services.runtime.OS); +var win32 = /^win(32|nt)$/i.test(services.runtime.OS); function loadData(name, store, type) { try { @@ -33,7 +33,7 @@ function saveData(obj) { storage.infoPath.child(obj.name).write(obj.serial); } -const StoreBase = Class("StoreBase", { +var StoreBase = Class("StoreBase", { OPTIONS: ["privateData", "replacer"], fireEvent: function (event, arg) { storage.fireEvent(this.name, event, arg); }, @@ -61,7 +61,7 @@ const StoreBase = Class("StoreBase", { save: function () { saveData(this); }, }); -const ArrayStore = Class("ArrayStore", StoreBase, { +var ArrayStore = Class("ArrayStore", StoreBase, { _constructor: Array, get length() this._object.length, @@ -107,7 +107,7 @@ const ArrayStore = Class("ArrayStore", StoreBase, { __iterator__: function () Iterator(this._object), }); -const ObjectStore = Class("ObjectStore", StoreBase, { +var ObjectStore = Class("ObjectStore", StoreBase, { _constructor: myObject, clear: function () { @@ -142,7 +142,7 @@ const ObjectStore = Class("ObjectStore", StoreBase, { __iterator__: function () Iterator(this._object), }); -const Storage = Module("Storage", { +var Storage = Module("Storage", { alwaysReload: {}, init: function () { @@ -269,7 +269,7 @@ const Storage = Module("Storage", { * @param {boolean} checkPWD Whether to allow expansion relative to the * current directory. @default true */ -const File = Class("File", { +var File = Class("File", { init: function (path, checkPWD) { let file = services.File(); diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 1049b899..bb4f0f03 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -12,11 +12,11 @@ defineModule("styles", { }); function cssUri(css) "chrome-data:text/css," + encodeURI(css); -const namespace = "@namespace html " + XHTML.uri.quote() + ";\n" + +var namespace = "@namespace html " + XHTML.uri.quote() + ";\n" + "@namespace xul " + XUL.uri.quote() + ";\n" + "@namespace dactyl " + NS.uri.quote() + ";\n"; -const Sheet = Struct("name", "id", "sites", "css", "hive", "agent"); +var Sheet = Struct("name", "id", "sites", "css", "hive", "agent"); Sheet.liveProperty = function (name) { let i = this.prototype.members[name]; this.prototype.__defineGetter__(name, function () this[i]); @@ -73,7 +73,7 @@ update(Sheet.prototype, { } }); -const Hive = Class("Hive", { +var Hive = Class("Hive", { init: function () { this.sheets = []; this.names = {}; @@ -212,7 +212,7 @@ const Hive = Class("Hive", { * * @author Kris Maglione */ -const Styles = Module("Styles", { +var Styles = Module("Styles", { init: function () { this._id = 0; this.user = Hive(); diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 4bcfeee3..0a4652fc 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -13,7 +13,7 @@ defineModule("template", { default xml namespace = XHTML; -const Template = Module("Template", { +var Template = Module("Template", { add: function add(a, b) a + b, join: function join(c) function (a, b) a + c + b, diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 83505ecb..ac8410e5 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -15,10 +15,10 @@ defineModule("util", { use: ["highlight", "storage", "template"] }); -const XBL = Namespace("xbl", "http://www.mozilla.org/xbl"); -const XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); -const XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); -const NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator"); +var XBL = Namespace("xbl", "http://www.mozilla.org/xbl"); +var XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); +var XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); +var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator"); default xml namespace = XHTML; memoize(this, "Commands", function () { @@ -28,7 +28,7 @@ memoize(this, "Commands", function () { return obj.Commands; }); -const FailedAssertion = Class("FailedAssertion", ErrorBase); +var FailedAssertion = Class("FailedAssertion", ErrorBase); function wrapCallback(fn) fn.wrapper = function wrappedCallback () { @@ -41,7 +41,7 @@ function wrapCallback(fn) } } -const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { +var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { init: function () { this.Array = array; @@ -92,16 +92,17 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) * @param {object} obj */ addObserver: function (obj) { - let observers = obj.observe; + let observers = obj._observe || obj.observe; + obj._observe = observers; function register(meth) { services.observer[meth](obj, "quit-application", true); - services.observer[meth](obj, "dactyl-unload", true); + services.observer[meth](obj, "dactyl-cleanup", true); for (let target in keys(observers)) services.observer[meth](obj, target, true); } Class.replaceProperty(obj, "observe", function (subject, target, data) { - if (target == "quit-application" || target == "dactyl-unload") + if (target == "quit-application" || target == "dactyl-cleanup") register("removeObserver"); if (observers[target]) observers[target].call(obj, subject, data); @@ -1402,7 +1403,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) * Math utility methods. * @singleton */ -const GlobalMath = Math; +var GlobalMath = Math; var Math = update(Object.create(GlobalMath), { /** * Returns the specified *value* constrained to the range *min* - *max*.