diff --git a/common/bootstrap.js b/common/bootstrap.js index 65469a7d..b17cba4c 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -29,15 +29,19 @@ const resourceProto = Services.io.getProtocolHandler("resource") const categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); const manager = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -try { // Temporary migration code. - const storage = Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication).storage; - var JSMLoader = storage.get("dactyl.JSMLoader", undefined); -} -catch (e) {} - const BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap"; JSMLoader = JSMLoader || BOOTSTRAP_CONTRACT in Cc && Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader; +var JSMLoader = BOOTSTRAP_CONTRACT in Components.classes && + Components.classes[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader; + +// Temporary migration code. +if (!JSMLoader && "@mozilla.org/fuel/application;1" in Components.classes) + JSMLoader = Components.classes["@mozilla.org/fuel/application;1"] + .getService(Components.interfaces.extIApplication) + .storage.get("dactyl.JSMLoader", null); + + function reportError(e) { dump("\ndactyl: bootstrap: " + e + "\n" + (e.stack || Error().stack) + "\n"); Cu.reportError(e); @@ -152,6 +156,7 @@ function init() { let chars = "0123456789abcdefghijklmnopqrstuv"; for (let n = Date.now(); n; n = Math.round(n / chars.length)) suffix += chars[n % chars.length]; + suffix = ""; for each (let line in manifest.split("\n")) { let fields = line.split(/\s+/); diff --git a/common/content/commandline.js b/common/content/commandline.js index 593d879f..e26bff6f 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -721,7 +721,7 @@ var CommandLine = Module("commandline", { highlightGroup = highlightGroup || this.HL_NORMAL; if (flags & this.APPEND_TO_MESSAGES) { - let message = isObject(data) && !isinstance(data, _) ? data : { message: String(data) }; + let message = isObject(data) ? data : { message: String(data) }; this._messageHistory.add(update({ highlight: highlightGroup }, message)); data = message.message; } diff --git a/common/content/mappings.js b/common/content/mappings.js index f286c8d6..668d8ce1 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -337,11 +337,14 @@ var Mappings = Module("mappings", { * @param {Object} extra An optional extra configuration hash. * @optional */ - add: function () { - util.assert(util.isDactyl(Components.stack.caller), - "User scripts may not add builtin mappings. Please use group.mappings.add instead."); + add: function add() { + let group = this.builtin; + if (!util.isDactyl(Components.stack.caller)) { + deprecated.warn(add, "mappings.add", "group.mappings.add"); + group = this.user; + } - let map = this.builtin.add.apply(this.builtin, arguments); + let map = group.add.apply(group, arguments); map.definedAt = contexts.getCaller(Components.stack.caller); return map; }, diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 4f88164c..280d1313 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -287,27 +287,33 @@ function deprecated(alternative, fn) { let name, func = callable(fn) ? fn : function () this[fn].apply(this, arguments); function deprecatedMethod() { - let frame = Components.stack.caller; let obj = this.className ? this.className + "#" : this.constructor.className ? this.constructor.className + "#" : ""; - let filename = util.fixURI(frame.filename || "unknown"); - if (!set.add(deprecatedMethod.seen, filename)) - util.dactyl(fn).warn( - util.urlPath(filename) + ":" + frame.lineNumber + ": " + - obj + (fn.name || name) + " is deprecated: Please use " + alternative + " instead"); + + deprecated.warn(func, obj + (fn.name || name), alternative); return func.apply(this, arguments); } - memoize(deprecatedMethod, "seen", function () set([ - "resource://dactyl" + JSMLoader.suffix + "/javascript.jsm", - "resource://dactyl" + JSMLoader.suffix + "/util.jsm" - ])); return callable(fn) ? deprecatedMethod : Class.Property({ get: function () deprecatedMethod, init: function (prop) { name = prop; } }); } +deprecated.warn = function warn(func, name, alternative, frame) { + if (!func.seenCaller) + func.seenCaller = set([ + "resource://dactyl" + JSMLoader.suffix + "/javascript.jsm", + "resource://dactyl" + JSMLoader.suffix + "/util.jsm" + ]); + + frame = frame || Components.stack.caller.caller; + let filename = util.fixURI(frame.filename || "unknown"); + if (!set.add(func.seenCaller, filename)) + util.dactyl(func).warn( + util.urlPath(filename) + ":" + frame.lineNumber + ": " + + name + " is deprecated: Please use " + alternative + " instead"); +} /** * Iterates over all of the top-level, iterable property names of an diff --git a/common/modules/bootstrap.jsm b/common/modules/bootstrap.jsm index e25510e8..005ba162 100644 --- a/common/modules/bootstrap.jsm +++ b/common/modules/bootstrap.jsm @@ -12,6 +12,11 @@ var BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap"; var JSMLoader = BOOTSTRAP_CONTRACT in Components.classes && Components.classes[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader; +if (!JSMLoader && "@mozilla.org/fuel/application;1" in Components.classes) + JSMLoader = Components.classes["@mozilla.org/fuel/application;1"] + .getService(Components.interfaces.extIApplication) + .storage.get("dactyl.JSMLoader", null); + if (JSMLoader && JSMLoader.bump === 4) JSMLoader.global = this; else diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 446d9ad5..1036f20c 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -692,9 +692,13 @@ var Commands = Module("commands", { repeat: null, add: function add() { - util.assert(util.isDactyl(Components.stack.caller), - "User scripts may not add builtin commands. Please use group.commands.add instead."); - return this.builtin._add.apply(this.builtin, arguments); + let group = this.builtin; + if (!util.isDactyl(Components.stack.caller)) { + deprecated.warn(add, "commands.add", "group.commands.add"); + group = this.user; + } + + return group._add.apply(group, arguments); }, addUserCommand: deprecated("group.commands.add", { get: function addUserCommand() this.user.closure._add }), getUserCommands: deprecated("iter(group.commands)", function getUserCommands() iter(this.user).toArray()), diff --git a/common/modules/messages.jsm b/common/modules/messages.jsm index bd614f0d..09379929 100644 --- a/common/modules/messages.jsm +++ b/common/modules/messages.jsm @@ -24,7 +24,7 @@ var Messages = Module("messages", { init: function _(message) { this.args = arguments; }, - value: Class.memoize(function () { + message: Class.memoize(function () { let message = this.args[0]; if (this.args.length > 1) { @@ -33,8 +33,8 @@ var Messages = Module("messages", { } return self.get(message); }), - valueOf: function valueOf() this.value, - toString: function toString() this.value + valueOf: function valueOf() this.message, + toString: function toString() this.message }); let seen = {}; diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm index bd42ff17..848007c9 100644 --- a/common/modules/overlay.jsm +++ b/common/modules/overlay.jsm @@ -292,7 +292,7 @@ var Overlay = Module("Overlay", { defineModule.modules.forEach(function defModule({ lazyInit, constructor: { className } }) { if (!lazyInit) { frob(className); - modules[className] = modules[className]; + Class.replaceProperty(modules, className, modules[className]); } else modules.__defineGetter__(className, function () { diff --git a/common/modules/util.jsm b/common/modules/util.jsm index b72f6fa1..30d45baa 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -864,7 +864,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), */ isDactyl: Class.memoize(function () { let base = util.regexp.escape(Components.stack.filename.replace(/[^\/]+$/, "")); - let re = RegExp("^(resource://dactyl|" + base + ")\\S+( -> resource://dactyl(?!-content/eval.js)\\S+)?$"); + let re = RegExp("^(?:.* -> )?(?:resource://dactyl(?!-content/eval.js)|" + base + ")\\S+$"); return function isDactyl(frame) re.test(frame.filename); }),