diff --git a/common/content/completion.js b/common/modules/completion.jsm
similarity index 91%
rename from common/content/completion.js
rename to common/modules/completion.jsm
index c1e0c409..d7ba2d2b 100644
--- a/common/content/completion.js
+++ b/common/modules/completion.jsm
@@ -6,7 +6,13 @@
// given in the LICENSE.txt file included with this file.
"use strict";
-/** @scope modules */
+try {
+
+Components.utils.import("resource://dactyl/base.jsm");
+defineModule("completion", {
+ exports: ["CompletionContext", "Completion", "completion"],
+ use: ["config", "template", "util"]
+});
/**
* Creates a new completion context.
@@ -36,9 +42,9 @@ var CompletionContext = Class("CompletionContext", {
let parent = editor;
name = parent.name + "/" + name;
- this.autoComplete = options.get("autocomplete").getKey(name);
- this.sortResults = options.get("wildsort").getKey(name);
- this.wildcase = options.get("wildcase").getKey(name);
+ this.autoComplete = this.options.get("autocomplete").getKey(name);
+ this.sortResults = this.options.get("wildsort").getKey(name);
+ this.wildcase = this.options.get("wildcase").getKey(name);
this.contexts = parent.contexts;
if (name in this.contexts)
@@ -237,7 +243,7 @@ var CompletionContext = Class("CompletionContext", {
return this.cache.allItemsResult;
}
catch (e) {
- dactyl.reportError(e);
+ util.reportError(e);
return { start: 0, items: [], longestAllSubstring: "" };
}
},
@@ -385,7 +391,7 @@ var CompletionContext = Class("CompletionContext", {
this.itemCache[this.key] = res;
}
catch (e) {
- dactyl.reportError(e);
+ util.reportError(e);
this.message = "Error: " + e;
}
}
@@ -446,7 +452,7 @@ var CompletionContext = Class("CompletionContext", {
delete this._substrings;
if (!this.forceAnchored)
- this.anchored = options.get("wildanchor").getKey(this.name, this.anchored);
+ this.anchored = this.options.get("wildanchor").getKey(this.name, this.anchored);
// Item matchers
if (this.ignoreCase)
@@ -484,7 +490,7 @@ var CompletionContext = Class("CompletionContext", {
}
catch (e) {
this.message = "Error: " + e;
- dactyl.reportError(e);
+ util.reportError(e);
return [];
}
},
@@ -645,7 +651,7 @@ var CompletionContext = Class("CompletionContext", {
fork: function fork(name, offset, self, completer) {
if (isString(completer))
completer = self[completer];
- let context = CompletionContext(this, name, offset);
+ let context = this.constructor(this, name, offset);
if (this.contextList.indexOf(context) < 0)
this.contextList.push(context);
@@ -833,40 +839,44 @@ var Completion = Module("completion", {
get setFunctionCompleter() JavaScript.setCompleter, // Backward compatibility
- // FIXME
- _runCompleter: function _runCompleter(name, filter, maxItems) {
- let context = CompletionContext(filter);
- context.maxItems = maxItems;
- let res = context.fork.apply(context, ["run", 0, this, name].concat(Array.slice(arguments, 3)));
- if (res) {
- if (Components.stack.caller.name === "runCompleter") // FIXME
- return { items: res.map(function (i) ({ item: i })) };
- context.contexts["/run"].completions = res;
- }
- context.wait(true);
- return context.allItems;
- },
+ Local: function (dactyl, modules, window) ({
+ options: modules.options,
- runCompleter: function runCompleter(name, filter, maxItems) {
- return this._runCompleter.apply(this, Array.slice(arguments))
- .items.map(function (i) i.item);
- },
+ // FIXME
+ _runCompleter: function _runCompleter(name, filter, maxItems) {
+ let context = modules.CompletionContext(filter);
+ context.maxItems = maxItems;
+ let res = context.fork.apply(context, ["run", 0, this, name].concat(Array.slice(arguments, 3)));
+ if (res) {
+ if (Components.stack.caller.name === "runCompleter") // FIXME
+ return { items: res.map(function (i) ({ item: i })) };
+ context.contexts["/run"].completions = res;
+ }
+ context.wait(true);
+ return context.allItems;
+ },
- listCompleter: function listCompleter(name, filter, maxItems) {
- let context = CompletionContext(filter || "");
- context.maxItems = maxItems;
- context.fork.apply(context, ["list", 0, completion, name].concat(Array.slice(arguments, 3)));
- context = context.contexts["/list"];
- context.wait();
+ runCompleter: function runCompleter(name, filter, maxItems) {
+ return this._runCompleter.apply(this, Array.slice(arguments))
+ .items.map(function (i) i.item);
+ },
- commandline.commandOutput(
-
- { template.map(context.contextList.filter(function (c) c.hasItems && c.items.length),
- function (context)
- template.completionRow(context.title, "CompTitle") +
- template.map(context.items, function (item) context.createRow(item), null, 100)) }
-
);
- },
+ listCompleter: function listCompleter(name, filter, maxItems) {
+ let context = modules.CompletionContext(filter || "");
+ context.maxItems = maxItems;
+ context.fork.apply(context, ["list", 0, completion, name].concat(Array.slice(arguments, 3)));
+ context = context.contexts["/list"];
+ context.wait();
+
+ modules.commandline.commandOutput(
+
+ { template.map(context.contextList.filter(function (c) c.hasItems && c.items.length),
+ function (context)
+ template.completionRow(context.title, "CompTitle") +
+ template.map(context.items, function (item) context.createRow(item), null, 100)) }
+
);
+ },
+ }),
////////////////////////////////////////////////////////////////////////////////
////////////////////// COMPLETION TYPES ////////////////////////////////////////
@@ -882,14 +892,14 @@ var Completion = Module("completion", {
let start = 0;
let skip = 0;
- if (options["urlseparator"])
- skip = context.filter.match("^.*" + options["urlseparator"]); // start after the last 'urlseparator'
+ if (this.options["urlseparator"])
+ skip = context.filter.match("^.*" + this.options["urlseparator"]); // start after the last 'urlseparator'
if (skip)
context.advance(skip[0].length);
if (complete == null)
- complete = options["complete"];
+ complete = this.options["complete"];
if (/^about:/.test(context.filter)) {
context.fork("about", 6, this, function (context) {
@@ -960,11 +970,22 @@ var Completion = Module("completion", {
}, {
UrlCompleter: Struct("name", "description", "completer")
}, {
- commands: function () {
+ init: function init(dactyl, modules, window) {
+ init.superapply(this, arguments);
+
+ modules.CompletionContext = Class("CompletionContext", CompletionContext, {
+ init: function init() {
+ this.options = modules.options;
+ return init.superapply(this, arguments);
+ }
+ });
+ },
+ commands: function (dactyl, modules, window) {
+ const { commands, completion } = modules;
commands.add(["contexts"],
"List the completion contexts used during completion of an Ex command",
function (args) {
- commandline.commandOutput(
+ modules.commandline.commandOutput(
{ template.completionRow(["Context", "Title"], "CompTitle") }
{ template.map(completion.contextList || [], function (item) template.completionRow(item, "CompItem")) }
@@ -980,7 +1001,8 @@ var Completion = Module("completion", {
literal: 0
});
},
- options: function () {
+ options: function (dactyl, modules, window) {
+ const { completion, options } = modules;
let wildmode = {
completer: function (context) [
// Why do we need ""?
@@ -1042,4 +1064,8 @@ var Completion = Module("completion", {
}
});
+endModule();
+
+} 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:
diff --git a/common/modules/io.jsm b/common/modules/io.jsm
index 0756cdb5..5c916ae9 100644
--- a/common/modules/io.jsm
+++ b/common/modules/io.jsm
@@ -28,7 +28,7 @@ var IO = Module("io", {
this._oldcwd = null;
},
- Local: function (dactyl, modules, window) let ({ Script, plugins } = modules) ({
+ Local: function (dactyl, modules, window) let ({ Script, io, plugins } = modules) ({
init: function init() {
this._processDir = services.directory.get("CurWorkD", Ci.nsIFile);
diff --git a/common/content/javascript.js b/common/modules/javascript.jsm
similarity index 90%
rename from common/content/javascript.js
rename to common/modules/javascript.jsm
index 614b3791..ee5a606c 100644
--- a/common/content/javascript.js
+++ b/common/modules/javascript.jsm
@@ -4,24 +4,39 @@
// given in the LICENSE.txt file included with this file.
"use strict";
+try {
+
+Components.utils.import("resource://dactyl/base.jsm");
+defineModule("javascript", {
+ exports: ["JavaScript", "javascript"],
+ use: ["services", "template", "util"],
+});
+
// TODO: Clean this up.
var JavaScript = Module("javascript", {
- init: function () {
- this._stack = [];
- this._functions = [];
- this._top = {}; // The element on the top of the stack.
- this._last = ""; // The last opening char pushed onto the stack.
- this._lastNonwhite = ""; // Last non-whitespace character we saw.
- this._lastChar = ""; // Last character we saw, used for \ escaping quotes.
- this._str = "";
+ Local: function (dactyl, modules, window) ({
+ init: function () {
+ this.modules = modules;
+ this.window = window
- this._lastIdx = 0;
+ this._stack = [];
+ this._functions = [];
+ this._top = {}; // The element on the top of the stack.
+ this._last = ""; // The last opening char pushed onto the stack.
+ this._lastNonwhite = ""; // Last non-whitespace character we saw.
+ this._lastChar = ""; // Last character we saw, used for \ escaping quotes.
+ this._str = "";
- this._cacheKey = null;
+ this._lastIdx = 0;
- this._nullSandbox = Cu.Sandbox("about:blank");
- },
+ this._cacheKey = null;
+
+ this._nullSandbox = Cu.Sandbox("about:blank");
+ },
+ }),
+
+ newContext: function () this.modules.newContext(this.modules.userContext),
get completers() JavaScript.completers, // For backward compatibility
@@ -39,7 +54,7 @@ var JavaScript = Module("javascript", {
return;
let seen = isinstance(obj, ["Sandbox"]) ? set(JavaScript.magicalNames) : {};
- let globals = values(toplevel && window === obj ? JavaScript.globalNames : []);
+ let globals = values(toplevel && this.window === obj ? this.globalNames : []);
for (let key in iter(globals, properties(obj, !toplevel, true)))
if (!set.add(seen, key))
yield key;
@@ -60,12 +75,12 @@ var JavaScript = Module("javascript", {
return [];
if (isinstance(obj, ["Sandbox"]) && !toplevel) // Temporary hack.
return [];
- if (jsmodules.isPrototypeOf(obj) && !toplevel)
+ if (this.modules.jsmodules.isPrototypeOf(obj) && !toplevel)
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))]);
+ if (obj === this.modules) // Hack.
+ completions = completions.concat([k for (k in this.iter(this.modules.jsmodules, toplevel))]);
return completions;
},
@@ -82,9 +97,9 @@ var JavaScript = Module("javascript", {
context[JavaScript.EVAL_EXPORT] = function export(obj) cache[key] = obj;
try {
if (tmp != null) // Temporary hack until bug 609949 is fixed.
- dactyl.userEval(JavaScript.EVAL_EXPORT + "(" + arg + ")", context, "[Command Line Completion]", 1);
+ this.modules.dactyl.userEval(JavaScript.EVAL_EXPORT + "(" + arg + ")", context, "[Command Line Completion]", 1);
else
- cache[key] = dactyl.userEval(arg, context, "[Command Line Completion]", 1);
+ cache[key] = this.modules.dactyl.userEval(arg, context, "[Command Line Completion]", 1);
return cache[key];
}
@@ -254,7 +269,7 @@ var JavaScript = Module("javascript", {
_getObj: function (frame, stop) {
let statement = this._get(frame, 0, "statements") || 0; // Current statement.
let prev = statement;
- let obj = window;
+ let obj = this.window;
let cacheKey;
for (let [, dot] in Iterator(this._get(frame).dots.concat(stop))) {
if (dot < statement)
@@ -287,9 +302,9 @@ var JavaScript = Module("javascript", {
this._cacheKey = null;
let obj = [[this.cache.evalContext, "Local Variables"],
- [userContext, "Global Variables"],
- [modules, "modules"],
- [window, "window"]]; // Default objects;
+ [this.modules.userContext, "Global Variables"],
+ [this.modules, "modules"],
+ [this.window, "window"]]; // Default objects;
// Is this an object dereference?
if (dot < statement) // No.
dot = statement - 1;
@@ -322,7 +337,7 @@ var JavaScript = Module("javascript", {
_complete: function (objects, key, compl, string, last) {
const self = this;
- if (!window.Object.getOwnPropertyNames && !options["jsdebugger"] && !this.context.message)
+ if (!this.window.Object.getOwnPropertyNames && !services.debugger.isOn && !this.context.message)
this.context.message = "For better completion data, please enable the JavaScript debugger (:set jsdebugger)";
let orig = compl;
@@ -430,14 +445,13 @@ var JavaScript = Module("javascript", {
this._buildStack.call(this, context.filter);
}
catch (e) {
- if (e.message != "Invalid JS")
- dactyl.reportError(e);
this._lastIdx = 0;
+ util.assert(!e.message, e.message);
return null;
}
this.context.getCache("evalled", Object);
- this.context.getCache("evalContext", function () newContext(userContext));
+ this.context.getCache("evalContext", this.closure.newContext);
// Okay, have parse stack. Figure out what we're completing.
@@ -586,27 +600,15 @@ var JavaScript = Module("javascript", {
this._top.offset = o;
}
return null;
- }
-}, {
- EVAL_TMP: "__dactyl_eval_tmp",
- EVAL_EXPORT: "__dactyl_eval_export",
+ },
- /**
- * A map of argument completion functions for named methods. The
- * signature and specification of the completion function
- * are fairly complex and yet undocumented.
- *
- * @see JavaScript.setCompleter
- */
- completers: {},
-
- magicalNames: Class.memoize(function () Object.getOwnPropertyNames(Cu.Sandbox(window), true).sort()),
+ magicalNames: Class.memoize(function () Object.getOwnPropertyNames(Cu.Sandbox(this.window), true).sort()),
/**
* A list of properties of the global object which are not
* enumerable by any standard method.
*/
- globalNames: Class.memoize(function () array.uniq([
+ globalNames: Class.memoize(function () let (self = this) array.uniq([
"Array", "ArrayBuffer", "AttributeName", "Boolean", "Components",
"CSSFontFaceStyleDecl", "CSSGroupRuleRuleList", "CSSNameSpaceRule",
"CSSRGBColor", "CSSRect", "ComputedCSSStyleDeclaration", "Date",
@@ -624,8 +626,21 @@ var JavaScript = Module("javascript", {
"isXMLName", "parseFloat", "parseInt", "undefined", "uneval"
].concat([k.substr(6) for (k in keys(Ci)) if (/^nsIDOM/.test(k))])
.concat([k.substr(3) for (k in keys(Ci)) if (/^nsI/.test(k))])
- .concat(JavaScript.magicalNames)
- .filter(function (k) k in window))),
+ .concat(this.magicalNames)
+ .filter(function (k) k in self.window))),
+
+}, {
+ EVAL_TMP: "__dactyl_eval_tmp",
+ EVAL_EXPORT: "__dactyl_eval_export",
+
+ /**
+ * A map of argument completion functions for named methods. The
+ * signature and specification of the completion function
+ * are fairly complex and yet undocumented.
+ *
+ * @see JavaScript.setCompleter
+ */
+ completers: {},
/**
* Installs argument string completers for a set of functions.
@@ -658,12 +673,16 @@ var JavaScript = Module("javascript", {
return arguments[0];
}
}, {
- completion: function () {
- completion.javascript = this.closure.complete;
+ init: function init(dactyl, modules, window) {
+ init.superapply(this, arguments);
+ },
+ completion: function (dactyl, modules, window) {
+ const { completion, javascript } = modules;
+ completion.javascript = javascript.closure.complete;
completion.javascriptCompleter = JavaScript; // Backwards compatibility.
},
- options: function () {
- options.add(["jsdebugger", "jsd"],
+ options: function (dactyl, modules, window) {
+ modules.options.add(["jsdebugger", "jsd"],
"Enable the JavaScript debugger service for use in JavaScript completion",
"boolean", false, {
setter: function (value) {
@@ -678,4 +697,8 @@ var JavaScript = Module("javascript", {
}
});
+endModule();
+
+} 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:
diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm
index 3056438e..41c34c66 100644
--- a/common/modules/overlay.jsm
+++ b/common/modules/overlay.jsm
@@ -146,24 +146,24 @@ var Overlay = Module("Overlay", {
let prefix = [BASE];
["base",
+ "completion",
"config",
- "util",
- "services",
+ "javascript",
"overlay",
"prefs",
- "storage"
+ "services",
+ "storage",
+ "util"
].forEach(function (name) require(jsmodules, name));
prefix.unshift("chrome://" + config.name + "/content/");
- ["javascript",
- "dactyl",
+ ["dactyl",
"modes",
"abbreviations",
"autocommands",
"buffer",
"commandline",
"commands",
- "completion",
"editor",
"events",
"finder",
@@ -212,6 +212,8 @@ var Overlay = Module("Overlay", {
deferredInit[mod].push(init(func, mod));
}
}
+ for (let [, fn] in iter(deferredInit[module.constructor.className] || []))
+ fn();
}
function load(module, prereq, frame) {
@@ -239,8 +241,6 @@ var Overlay = Module("Overlay", {
modules[module.className] = defineModule.time(module.className, "init", module);
init(modules[module.className]);
- for (let [, fn] in iter(deferredInit[module.className] || []))
- fn();
}
catch (e) {
util.dump("Loading " + (module && module.className) + ":");
diff --git a/common/modules/util.jsm b/common/modules/util.jsm
index 2c361142..6b4c083d 100644
--- a/common/modules/util.jsm
+++ b/common/modules/util.jsm
@@ -1501,6 +1501,6 @@ var Math = update(Object.create(GlobalMath), {
endModule();
-} catch(e){ if (isString(e)) 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: