X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fjavascript.jsm;h=e85b8ca41f3002ae3151226b519139c254ab5a64;hb=70740024f9c028c1fd63e1a1850ab062ff956054;hp=0f78615cc5b204b924716042538f1bae4c41101b;hpb=eeed0be1a8abf7e3c97f43b63c1d595e940fef21;p=dactyl.git diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index 0f78615..e85b8ca 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -11,7 +11,7 @@ try { Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("javascript", { exports: ["JavaScript", "javascript"], - use: ["services", "template", "util"] + use: ["messages", "services", "template", "util"] }, this); let isPrototypeOf = Object.prototype.isPrototypeOf; @@ -41,11 +41,11 @@ var JavaScript = Module("javascript", { this.window = window; init.supercall(this); - }, + } }), globals: Class.memoize(function () [ - [this.modules.userContext, "Global Variables"], + [this.modules.userContext, /*L*/"Global Variables"], [this.modules, "modules"], [this.window, "window"] ]), @@ -54,7 +54,7 @@ var JavaScript = Module("javascript", { lazyInit: true, - newContext: function () this.modules.newContext(this.modules.userContext), + newContext: function () this.modules.newContext(this.modules.userContext, true), get completers() JavaScript.completers, // For backward compatibility @@ -71,22 +71,22 @@ var JavaScript = Module("javascript", { if (obj == null) return; - let seen = isinstance(obj, ["Sandbox"]) ? set(JavaScript.magicalNames) : {}; + let seen = isinstance(obj, ["Sandbox"]) ? Set(JavaScript.magicalNames) : {}; let globals = values(toplevel && this.window === obj ? this.globalNames : []); if (toplevel && isObject(obj) && "wrappedJSObject" in obj) - if (!set.add(seen, "wrappedJSObject")) + if (!Set.add(seen, "wrappedJSObject")) yield "wrappedJSObject"; for (let key in iter(globals, properties(obj, !toplevel, true))) - if (!set.add(seen, key)) + if (!Set.add(seen, key)) yield key; // Properties aren't visible in an XPCNativeWrapper until // they're accessed. for (let key in properties(this.getKey(obj, "wrappedJSObject"), !toplevel, true)) try { - if (key in obj && !set.has(seen, key)) + if (key in obj && !Set.has(seen, key)) yield key; } catch (e) {} @@ -117,18 +117,14 @@ var JavaScript = Module("javascript", { return cache[key]; context[JavaScript.EVAL_TMP] = tmp; - context[JavaScript.EVAL_EXPORT] = function export_(obj) cache[key] = obj; try { - if (tmp != null) // Temporary hack until bug 609949 is fixed. - this.modules.dactyl.userEval(JavaScript.EVAL_EXPORT + "(" + arg + ")", context, "[Command Line Completion]", 1); - else - cache[key] = this.modules.dactyl.userEval(arg, context, "[Command Line Completion]", 1); + cache[key] = this.modules.dactyl.userEval(arg, context, /*L*/"[Command Line Completion]", 1); return cache[key]; } catch (e) { util.reportError(e); - this.context.message = "Error: " + e; + this.context.message = _("error.error", e); return null; } finally { @@ -170,7 +166,7 @@ var JavaScript = Module("javascript", { if (this._top.char != arg) { this.context.highlight(this._top.offset, this._i - this._top.offset, "SPELLCHECK"); - throw Error("Invalid JS"); + throw Error(/*L*/"Invalid JS"); } // The closing character of this stack frame will have pushed a new @@ -308,7 +304,7 @@ var JavaScript = Module("javascript", { if (this._checkFunction(prev, dot, cacheKey)) return []; if (prev != statement && obj == null) { - this.context.message = "Error: " + cacheKey.quote() + " is " + String(obj); + this.context.message = /*L*/"Error: " + cacheKey.quote() + " is " + String(obj); return []; } @@ -324,7 +320,7 @@ var JavaScript = Module("javascript", { let end = (frame == -1 ? this._lastIdx : this._get(frame + 1).offset); this._cacheKey = null; - let obj = [[this.cache.evalContext, "Local Variables"]].concat(this.globals); + let obj = [[this.cache.evalContext, /*L*/"Local Variables"]].concat(this.globals); // Is this an object dereference? if (dot < statement) // No. dot = statement - 1; @@ -339,7 +335,7 @@ var JavaScript = Module("javascript", { const self = this; if (!getOwnPropertyNames && !services.debugger.isOn && !this.context.message) - this.context.message = "For better completion data, please enable the JavaScript debugger (:set jsdebugger)"; + this.context.message = /*L*/"For better completion data, please enable the JavaScript debugger (:set jsdebugger)"; let base = this.context.fork("js", this._top.offset); base.forceAnchored = true; @@ -419,14 +415,14 @@ var JavaScript = Module("javascript", { objects.forEach(function (obj) { obj.ctxt_p.split(obj[1] + "/anchored", this, function (context) { context.anchored = true; - context.title[0] += " (prototypes)"; + context.title[0] += /*L*/" (prototypes)"; }); }); objects.forEach(function (obj) { obj.ctxt_t.split(obj[1] + "/unanchored", this, function (context) { context.anchored = false; - context.title[0] += " (substrings)"; + context.title[0] += /*L*/" (substrings)"; context.filters.push(unanchored); }); }); @@ -434,7 +430,7 @@ var JavaScript = Module("javascript", { objects.forEach(function (obj) { obj.ctxt_p.split(obj[1] + "/unanchored", this, function (context) { context.anchored = false; - context.title[0] += " (prototype substrings)"; + context.title[0] += /*L*/" (prototype substrings)"; context.filters.push(unanchored); }); }); @@ -598,7 +594,7 @@ var JavaScript = Module("javascript", { // Wait for a keypress before completing when there's no key if (!this.context.tabPressed && key == "" && obj.length > 1) { this.context.waitingForTab = true; - this.context.message = "Waiting for key press"; + this.context.message = _("completion.waitingForKeyPress"); return null; } @@ -633,12 +629,11 @@ var JavaScript = Module("javascript", { "Math", "NaN", "Namespace", "Number", "Object", "Proxy", "QName", "ROCSSPrimitiveValue", "RangeError", "ReferenceError", "RegExp", "StopIteration", "String", "SyntaxError", "TypeError", "URIError", - "Uint16Array", "Uint32Array", "Uint8Array", "XML", - "XMLHttpProgressEvent", "XMLList", "XMLSerializer", "XPCNativeWrapper", - "XPCSafeJSWrapper", "XULControllers", "constructor", "decodeURI", - "decodeURIComponent", "encodeURI", "encodeURIComponent", "escape", - "eval", "isFinite", "isNaN", "isXMLName", "parseFloat", "parseInt", - "undefined", "unescape", "uneval" + "Uint16Array", "Uint32Array", "Uint8Array", "XML", "XMLHttpProgressEvent", + "XMLList", "XMLSerializer", "XPCNativeWrapper", "XPCSafeJSWrapper", + "XULControllers", "constructor", "decodeURI", "decodeURIComponent", + "encodeURI", "encodeURIComponent", "escape", "eval", "isFinite", "isNaN", + "isXMLName", "parseFloat", "parseInt", "undefined", "unescape", "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(this.magicalNames) @@ -646,7 +641,6 @@ var JavaScript = Module("javascript", { }, { EVAL_TMP: "__dactyl_eval_tmp", - EVAL_EXPORT: "__dactyl_eval_export", /** * A map of argument completion functions for named methods. The @@ -670,9 +664,9 @@ var JavaScript = Module("javascript", { * time they are accessed, so they should be accessed * judiciously. * - * @param {function|function[]} funcs The functions for which to + * @param {function|[function]} funcs The functions for which to * install the completers. - * @param {function[]} completers An array of completer + * @param {[function]} completers An array of completer * functions. */ setCompleter: function (funcs, completers) { @@ -705,7 +699,8 @@ var JavaScript = Module("javascript", { modes.addMode("REPL", { description: "JavaScript Read Eval Print Loop", - bases: [modes.COMMAND_LINE] + bases: [modes.COMMAND_LINE], + displayName: Class.memoize(function () this.name) }); }, commandline: function initCommandLine(dactyl, modules, window) { @@ -775,8 +770,8 @@ var JavaScript = Module("javascript", { this.js.newContext = function newContext() modules.newContext(self.context, !sandbox); this.js.globals = [ - [this.context, "REPL Variables"], - [context, "REPL Global"] + [this.context, /*L*/"REPL Variables"], + [context, /*L*/"REPL Global"] ].concat(this.js.globals.filter(function ([global]) isPrototypeOf.call(global, context))); if (!isPrototypeOf.call(modules.jsmodules, context)) @@ -790,13 +785,14 @@ var JavaScript = Module("javascript", { this.repl = REPL(this.context); }, + open: function open(context) { - this.updatePrompt(); modules.mow.echo(this.repl); this.widgets.message = null; open.superapply(this, arguments); + this.updatePrompt(); }, complete: function complete(context) { @@ -807,8 +803,10 @@ var JavaScript = Module("javascript", { mode: modes.REPL, + get completionList() this.widgets.statusbar.commandline.id, + accept: function accept() { - dactyl.trapErrors(function () { this.repl.addOutput(this.command) }, this); + dactyl.trapErrors(function () { this.repl.addOutput(this.command); }, this); this.completions.cleanup(); this.history.save(); @@ -836,8 +834,6 @@ var JavaScript = Module("javascript", { commands.add(["javas[cript]", "js"], "Evaluate a JavaScript string", function (args) { - modules.commandline; - if (args[0] && !args.bang) dactyl.userEval(args[0]); else { @@ -846,6 +842,7 @@ var JavaScript = Module("javascript", { .open(); } }, { + argCount: "?", bang: true, completer: function (context) modules.completion.javascript(context), hereDoc: true,