]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/javascript.jsm
Import r6923 from upstream hg supporting Firefox up to 22.0a1
[dactyl.git] / common / modules / javascript.jsm
index c33ca86930e8eb8bf36e229ff5955b7f47dfe649..a0981d7894fed5048a2ca8b945035fa2d6389a60 100644 (file)
@@ -1,18 +1,19 @@
-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2012 Kris Maglione <maglione.k at Gmail>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
-/* use strict */
+"use strict";
 
 let { getOwnPropertyNames } = Object;
 
 try {
 
-Components.utils.import("resource://dactyl/bootstrap.jsm");
 defineModule("javascript", {
     exports: ["JavaScript", "javascript"],
     require: ["util"]
-}, this);
+});
+
+lazyRequire("template", ["template"]);
 
 let isPrototypeOf = Object.prototype.isPrototypeOf;
 
@@ -118,7 +119,8 @@ var JavaScript = Module("javascript", {
 
         context[JavaScript.EVAL_TMP] = tmp;
         try {
-            cache[key] = this.modules.dactyl.userEval(arg, context, /*L*/"[Command Line Completion]", 1);
+            cache[key] = this.modules.dactyl.userEval(arg, context,
+                                                      /*L*/"[Command Line Completion]", 1);
 
             return cache[key];
         }
@@ -489,9 +491,9 @@ var JavaScript = Module("javascript", {
                         let [, prefix, args] = /^(function .*?)\((.*?)\)/.exec(Function.prototype.toString.call(func));
                         let n = this._get(i).comma.length;
                         args = template.map(Iterator(args.split(", ")),
-                            function ([i, arg]) <span highlight={i == n ? "Filter" : ""}>{arg}</span>,
-                            <>,&#xa0;</>);
-                        this.context.message = <>{prefix}({args})</>;
+                            function ([i, arg]) ["span", { highlight: i == n ? "Filter" : "" }, arg],
+                            ",\u00a0");
+                        this.context.message = ["", prefix + "(", args, ")"];
                     }
                 }
             }
@@ -595,8 +597,8 @@ var JavaScript = Module("javascript", {
         if (!this.context.tabPressed && key == "" && obj.length > 1) {
             let message = this.context.message || "";
             this.context.waitingForTab = true;
-            this.context.message = <>{message}
-                                     {_("completion.waitingForKeyPress")}</>;
+            this.context.message = ["", message, "\n",
+                                    _("completion.waitingForKeyPress")];
             return null;
         }
 
@@ -715,7 +717,6 @@ var JavaScript = Module("javascript", {
             },
 
             addOutput: function addOutput(js) {
-                default xml namespace = XHTML;
                 this.count++;
 
                 try {
@@ -728,19 +729,21 @@ var JavaScript = Module("javascript", {
 
                     if (e.fileName)
                         e = util.fixURI(e.fileName) + ":" + e.lineNumber + ": " + e;
-                    xml = <span highlight="ErrorMsg">{e}</span>;
+                    xml = ["span", { highlight: "ErrorMsg" }, e];
                 }
 
                 let prompt = "js" + this.count;
                 Class.replaceProperty(this.context, prompt, result);
 
-                XML.ignoreWhitespace = XML.prettyPrinting = false;
                 let nodes = {};
                 this.rootNode.appendChild(
-                    util.xmlToDom(<e4x>
-                        <div highlight="REPL-E" key="e"><span highlight="REPL-R">{prompt}></span> {js}</div>
-                        <div highlight="REPL-P" key="p">{xml}</div>
-                    </e4x>.elements(), this.document, nodes));
+                    DOM.fromJSON(
+                        [["div", { highlight: "REPL-E", key: "e" },
+                            ["span", { highlight: "REPL-R" },
+                                prompt, ">"], " ", js],
+                         ["div", { highlight: "REPL-P", key: "p" },
+                            xml]],
+                        this.document, nodes));
 
                 this.rootNode.scrollTop += nodes.e.getBoundingClientRect().top
                                          - this.rootNode.getBoundingClientRect().top;
@@ -749,8 +752,7 @@ var JavaScript = Module("javascript", {
             count: 0,
 
             message: Class.Memoize(function () {
-                default xml namespace = XHTML;
-                util.xmlToDom(<div highlight="REPL" key="rootNode"/>,
+                DOM.fromJSON(["div", { highlight: "REPL", key: "rootNode" }],
                               this.document, this);
 
                 return this.rootNode;
@@ -878,7 +880,7 @@ var JavaScript = Module("javascript", {
         bind(["<C-b>", "<PageUp>"], "Scroll up half a page",
              function ({ self }) { self.repl.scrollVertical("pages", -1); });
     },
-    options: function (dactyl, modules, window) {
+    options: function initOptions(dactyl, modules, window) {
         modules.options.add(["jsdebugger", "jsd"],
             "Enable the JavaScript debugger service for use in JavaScript completion",
             "boolean", false, {