diff --git a/common/content/commandline.js b/common/content/commandline.js index 8ebe3769..95388bac 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -1964,7 +1964,7 @@ const ItemList = Class("ItemList", { //if (index == 0) // this.start = now; //if (index == Math.min(len - 1, 100)) - // dactyl.dump({ time: Date.now() - this.start }); + // util.dump({ time: Date.now() - this.start }); }, onEvent: function onEvent(event) false diff --git a/common/content/dactyl.js b/common/content/dactyl.js index ce85f822..73853241 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -59,7 +59,7 @@ const Dactyl = Module("dactyl", { autocommands.trigger("LeavePre", {}); storage.saveAll(); dactyl.triggerObserver("shutdown", null); - dactyl.dump("All dactyl modules destroyed\n"); + util.dump("All dactyl modules destroyed\n"); autocommands.trigger("Leave", {}); }, @@ -1897,7 +1897,7 @@ const Dactyl = Module("dactyl", { dactyl.commandLineOptions.noPlugins = "++noplugin" in args; dactyl.commandLineOptions.postCommands = args["+c"]; dactyl.commandLineOptions.preCommands = args["++cmd"]; - dactyl.dump("Processing command-line option: " + commandline); + util.dump("Processing command-line option: " + commandline); } dactyl.log("Command-line options: " + util.objectToString(dactyl.commandLineOptions), 3); diff --git a/common/content/events.js b/common/content/events.js index ea8b2a06..d0cee8b6 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -88,7 +88,7 @@ const Events = Module("events", { }, destroy: function () { - dactyl.dump("Removing all event listeners"); + util.dump("Removing all event listeners"); for (let args in values(this.sessionListeners)) args[0].removeEventListener.apply(args[0], args.slice(1)); }, @@ -571,7 +571,7 @@ const Events = Module("events", { * @returns {boolean} */ waitForPageLoad: function () { - //dactyl.dump("start waiting in loaded state: " + buffer.loaded); + //util.dump("start waiting in loaded state: " + buffer.loaded); util.threadYield(true); // clear queue if (buffer.loaded == 1) @@ -584,7 +584,7 @@ const Events = Module("events", { while (now = Date.now(), now < end) { util.threadYield(); //if ((now - start) % 1000 < 10) - // dactyl.dump("waited: " + (now - start) + " ms"); + // util.dump("waited: " + (now - start) + " ms"); if (!events.feedingKeys) return false; @@ -602,7 +602,7 @@ const Events = Module("events", { let ret = (buffer.loaded == 1); if (!ret) dactyl.echoerr("Page did not load completely in " + maxWaitTime + " seconds. Macro stopped."); - //dactyl.dump("done waiting: " + ret); + //util.dump("done waiting: " + ret); // sometimes the input widget had focus when replaying a macro // maybe this call should be moved somewhere else? diff --git a/common/content/javascript.js b/common/content/javascript.js index b32b366c..8c6c492f 100644 --- a/common/content/javascript.js +++ b/common/content/javascript.js @@ -62,6 +62,8 @@ const JavaScript = Module("javascript", { return []; let completions = [k for (k in this.iter(obj, toplevel))]; + if (obj == modules) // Hack. + completions = completions.concat([k for (k in this.iter(jsmodules, toplevel))]); return completions; }, diff --git a/common/content/modules.js b/common/content/modules.js index ad383e4f..bf0acd60 100644 --- a/common/content/modules.js +++ b/common/content/modules.js @@ -82,7 +82,6 @@ window.addEventListener("load", function onLoad() { }); }); - function dump(str) window.dump(String.replace(str, /\n?$/, "\n").replace(/^/m, services.get("dactyl:").name + ": ")); const start = Date.now(); const deferredInit = { load: [] }; const seen = set(); @@ -136,7 +135,7 @@ window.addEventListener("load", function onLoad() { fn(); } catch (e) { - dump("Loading " + (module && module.className) + ": " + e + "\n" + (e.stack || "")); + util.dump("Loading " + (module && module.className) + ": " + e + "\n" + (e.stack || "")); } return modules[module.className]; } @@ -145,7 +144,7 @@ window.addEventListener("load", function onLoad() { deferredInit["load"].forEach(call); modules.times = update({}, defineModule.times); - dump("Loaded in " + (Date.now() - start) + "ms"); + util.dump("Loaded in " + (Date.now() - start) + "ms"); }, false); window.addEventListener("unload", function onUnload() { diff --git a/common/content/quickmarks.js b/common/content/quickmarks.js index 07cf7134..8a8646f2 100644 --- a/common/content/quickmarks.js +++ b/common/content/quickmarks.js @@ -157,7 +157,6 @@ const QuickMarks = Module("quickmarks", { commands.add(["qmarks"], "Show all QuickMarks", function (args) { - dactyl.dump(args); args = args[0] || ""; // ignore invalid qmark characters unless there are no valid qmark chars diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 859aeed8..33635641 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -137,7 +137,10 @@ function require(obj, name, from) { } catch (e) { dump("loading " + String.quote("resource://dactyl/" + name + ".jsm") + "\n"); - dump(" " + e.fileName + ":" + e.lineNumber + ": " + e +"\n"); + if (loaded.util) + util.reportError(e); + else + dump(" " + e.fileName + ":" + e.lineNumber + ": " + e +"\n"); } } @@ -151,7 +154,7 @@ defineModule("base", { "isObject", "isString", "isSubclass", "iter", "iterAll", "keys", "memoize", "properties", "requiresMainThread", "set", "update", "values" ], - use: ["services"] + use: ["services", "util"] }); function Runnable(self, func, args) { @@ -697,12 +700,7 @@ Class.Property.prototype.init = function () {}; Class.extend = function extend(subclass, superclass, overrides) { subclass.superclass = superclass; - try { - subclass.prototype = Object.create(superclass.prototype); - } - catch(e) { - dump(e + "\n" + String.replace(e.stack, /^/gm, " ") + "\n\n"); - } + subclass.prototype = Object.create(superclass.prototype); update(subclass.prototype, overrides); subclass.prototype.constructor = subclass; subclass.prototype._class_ = subclass; diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index 55acbdee..0c57a174 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -153,7 +153,8 @@ const Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakR catch (e) { errors = errors || {}; errors[itemName] = e; - dump("Error sanitizing " + itemName + ": " + e + "\n" + e.stack + "\n"); + util.dump("Error sanitizing " + itemName); + util.reportError(e); } } @@ -172,7 +173,8 @@ const Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakR catch (e) { errors = errors || {}; errors[itemName] = e; - dump("Error sanitizing " + itemName + ": " + e + "\n" + e.stack + "\n"); + util.dump("Error sanitizing " + itemName); + util.reportError(e); } return errors; } diff --git a/common/modules/services.jsm b/common/modules/services.jsm index 7460ab50..93daf28b 100644 --- a/common/modules/services.jsm +++ b/common/modules/services.jsm @@ -6,7 +6,8 @@ Components.utils.import("resource://dactyl/base.jsm"); defineModule("services", { - exports: ["Services", "services"] + exports: ["Services", "services"], + use: ["util"] }); /** @@ -72,7 +73,7 @@ const Services = Module("Services", { } catch (e) { // dactyl.log() is not defined at this time, so just dump any error - dump("Service creation failed for '" + classes + "': " + e + "\n"); + util.dump("Service creation failed for '" + classes + "': " + e + "\n"); return null; } }, diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 1888bb27..74b78c46 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -299,7 +299,7 @@ const File = Class("File", { file.initWithPath(expandedPath); } catch (e) { - dump("dactyl: " + e + "\n" + String.replace(e.stack, /^/gm, "dactyl: ") + "\n"); + util.reportError(e); return null; } } diff --git a/common/modules/util.jsm b/common/modules/util.jsm index dcb827b4..a2342e1a 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -57,7 +57,6 @@ const Util = Module("Util", { if (observers[target]) observers[target].call(obj, subject, data); }); - this.dactyl.dump(String(obj), obj instanceof Ci.nsIObserver); register("addObserver"); }, @@ -230,9 +229,6 @@ const Util = Module("Util", { * Prints a message to the console. If msg is an object it is * pretty printed. * - * NOTE: the "browser.dom.window.dump.enabled" preference needs to be - * set. - * * @param {string|Object} msg The message to print. */ dump: function dump_() { @@ -676,6 +672,8 @@ const Util = Module("Util", { } }, + maxErrors: 15, + errors: Class.memoize(function () []), reportError: function (error) { if (Cu.reportError) Cu.reportError(error); @@ -686,16 +684,16 @@ const Util = Module("Util", { stack: <>{String.replace(error.stack || Error().stack, /^/mg, "\t")} }); - let errors = storage.newArray("errors", { store: false }); - errors.toString = function () [String(v[0]) + "\n" + v[1] for ([k, v] in this)].join("\n\n"); - errors.push([new Date, obj + obj.stack]); + this.errors.push([new Date, obj + "\n" + obj.stack]); + this.errors = this.errors.slice(-this.maxErrors); + this.errors.toString = function () [k + "\n" + v for ([k, v] in array.iterValues(this))].join("\n\n"); - util.dump(String(error)); - util.dump(obj); - util.dump(""); + this.dump(String(error)); + this.dump(obj); + this.dump(""); } catch (e) { - dump(e); + this.dump(e); } }, diff --git a/pentadactyl/content/config.js b/pentadactyl/content/config.js index a14c49e4..81a314d9 100644 --- a/pentadactyl/content/config.js +++ b/pentadactyl/content/config.js @@ -240,7 +240,6 @@ const Config = Module("config", ConfigBase, { }); }, completion: function () { - dactyl.dump("Load completion\n"); var searchRunning = false; // only until Firefox fixes https://bugzilla.mozilla.org/show_bug.cgi?id=510589 completion.location = function location(context) { if (!services.get("autoCompleteSearch"))