X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Ftemplate.jsm;fp=common%2Fmodules%2Ftemplate.jsm;h=61c64cdeae079190451c9041454b4f2477a3fd4c;hb=9044153cb63835e39b9de8ec4ade237c03e3888a;hp=6e18dc506c676e085153eebcfb9f338d1dfe68be;hpb=70740024f9c028c1fd63e1a1850ab062ff956054;p=dactyl.git diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 6e18dc5..61c64cd 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -2,13 +2,13 @@ // // 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 global = this; Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("template", { exports: ["Binding", "Template", "template"], - require: ["util"], - use: ["messages", "services"] + require: ["util"] }, this); default xml namespace = XHTML; @@ -22,7 +22,7 @@ var Binding = Class("Binding", { Object.defineProperties(node, this.constructor.properties); for (let [event, handler] in values(this.constructor.events)) - node.addEventListener(event, handler, false); + node.addEventListener(event, util.wrapCallback(handler, true), false); }, set collapsed(collapsed) { @@ -57,7 +57,7 @@ var Binding = Class("Binding", { } }, - events: Class.memoize(function () { + events: Class.Memoize(function () { let res = []; for (let obj in this.bindings) if (Object.getOwnPropertyDescriptor(obj, "events")) @@ -66,7 +66,7 @@ var Binding = Class("Binding", { return res; }), - properties: Class.memoize(function () { + properties: Class.Memoize(function () { let res = {}; for (let obj in this.bindings) for (let prop in properties(obj)) { @@ -153,9 +153,11 @@ var Template = Module("Template", { let obj = params.eventTarget; let events = obj[this.getAttribute("events") || "events"]; + if (Set.has(events, "input")) + events["dactyl-input"] = events["input"]; for (let [event, handler] in Iterator(events)) - node.addEventListener(event, obj.closure(handler), false); + node.addEventListener(event, util.wrapCallback(obj.closure(handler), true), false); } }) }, @@ -171,7 +173,7 @@ var Template = Module("Template", { <> ) })  } - {text || ""} , @@ -204,7 +206,7 @@ var Template = Module("Template", { }, helpLink: function (token, text, type) { - if (!services["dactyl:"].initialized) + if (!help.initialized) util.dactyl.initHelp(); let topic = token; // FIXME: Evil duplication! @@ -213,7 +215,7 @@ var Template = Module("Template", { else if (/^n_/.test(topic)) topic = topic.slice(2); - if (services["dactyl:"].initialized && !Set.has(services["dactyl:"].HELP_TAGS, topic)) + if (help.initialized && !Set.has(help.tags, topic)) return {text || token}; XML.ignoreWhitespace = false; XML.prettyPrinting = false; @@ -224,7 +226,7 @@ var Template = Module("Template", { return {text || topic}; }, HelpLink: function (token) { - if (!services["dactyl:"].initialized) + if (!help.initialized) util.dactyl.initHelp(); let topic = token; // FIXME: Evil duplication! @@ -233,7 +235,7 @@ var Template = Module("Template", { else if (/^n_/.test(topic)) topic = topic.slice(2); - if (services["dactyl:"].initialized && !Set.has(services["dactyl:"].HELP_TAGS, topic)) + if (help.initialized && !Set.has(help.tags, topic)) return <>{token}; XML.ignoreWhitespace = false; XML.prettyPrinting = false; @@ -256,13 +258,32 @@ var Template = Module("Template", { })(), template[help ? "HelpLink" : "helpLink"]); }, + // Fixes some strange stack rewinds on NS_ERROR_OUT_OF_MEMORY + // exceptions that we can't catch. + stringify: function stringify(arg) { + if (!callable(arg)) + return String(arg); + + try { + this._sandbox.arg = arg; + return Cu.evalInSandbox("String(arg)", this._sandbox); + } + finally { + this._sandbox.arg = null; + } + }, + + _sandbox: Class.Memoize(function () Cu.Sandbox(global, { wantXrays: false })), + // if "processStrings" is true, any passed strings will be surrounded by " and // any line breaks are displayed as \n - highlight: function highlight(arg, processStrings, clip) { + highlight: function highlight(arg, processStrings, clip, bw) { XML.ignoreWhitespace = false; XML.prettyPrinting = false; // some objects like window.JSON or getBrowsers()._browsers need the try/catch try { - let str = clip ? util.clip(String(arg), clip) : String(arg); + let str = this.stringify(arg); + if (clip) + str = util.clip(str, clip); switch (arg == null ? "undefined" : typeof arg) { case "number": return {str}; @@ -273,17 +294,21 @@ var Template = Module("Template", { case "boolean": return {str}; case "function": - // Vim generally doesn't like /foo*/, because */ looks like a comment terminator. - // Using /foo*(:?)/ instead. + if (arg instanceof Ci.nsIDOMElement) // wtf? + return util.objectToString(arg, !bw); + + str = str.replace("/* use strict */ \n", "/* use strict */ "); if (processStrings) return {str.replace(/\{(.|\n)*(?:)/g, "{ ... }")}; <>}; /* Vim */ + arg = String(arg).replace("/* use strict */ \n", "/* use strict */ "); return <>{arg}; case "undefined": return {arg}; case "object": if (arg instanceof Ci.nsIDOMElement) - return util.objectToString(arg, false); + return util.objectToString(arg, !bw); + // for java packages value.toString() would crash so badly // that we cannot even try/catch it if (/^\[JavaPackage.*\]$/.test(arg)) @@ -302,7 +327,10 @@ var Template = Module("Template", { } }, - highlightFilter: function highlightFilter(str, filter, highlight) { + highlightFilter: function highlightFilter(str, filter, highlight, isURI) { + if (isURI) + str = util.losslessDecodeURI(str); + return this.highlightSubstrings(str, (function () { if (filter.length == 0) return; @@ -364,6 +392,8 @@ var Template = Module("Template", { return + + @@ -372,6 +402,8 @@ var Template = Module("Template", { + + )
{_("title.Jump")}{_("title.HPos")}{_("title.VPos")} {_("title.Title")} {_("title.URI")}
{idx == index ? ">" : ""} {Math.abs(idx - index)}{val.offset ? val.offset.x : ""}{val.offset ? val.offset.y : ""} {val.title} {util.losslessDecodeURI(val.URI.spec)}