X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Futil.jsm;fp=common%2Fmodules%2Futil.jsm;h=d6eaf80ceaa1d0430d6886b9c8d6b860bd750bb8;hb=205a9e35484fed6fc69161897a59f51110ba708d;hp=bf7b67eeefa1ad7427becced9a9890a5b5db3184;hpb=ea765b42ac553c79ee79137be7b70fec68edb560;p=dactyl.git diff --git a/common/modules/util.jsm b/common/modules/util.jsm index bf7b67e..d6eaf80 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -1,6 +1,6 @@ // Copyright (c) 2006-2008 by Martin Stubenschrott // Copyright (c) 2007-2011 by Doug Kearns -// Copyright (c) 2008-2012 Kris Maglione +// Copyright (c) 2008-2013 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. @@ -161,7 +161,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), } }); - obj.observe.unregister = function () register("removeObserver"); + obj.observe.unregister = () => register("removeObserver"); register("addObserver"); }, { dump: dump, Error: Error }), @@ -185,7 +185,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {string} name The name to mangle. * @returns {string} The mangled name. */ - camelCase: function camelCase(name) String.replace(name, /-(.)/g, function (m, m1) m1.toUpperCase()), + camelCase: function camelCase(name) String.replace(name, /-(.)/g, + (m, m1) => m1.toUpperCase()), /** * Capitalizes the first character of the given string. @@ -261,12 +262,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), function frame() update( function _frame(obj) - _frame === stack.top || _frame.valid(obj) ? - _frame.elements.map(function (e) callable(e) ? e(obj) : e).join("") : "", + _frame === stack.top || _frame.valid(obj) + ? _frame.elements.map(e => callable(e) ? e(obj) : e) + .join("") + : "", { elements: [], seen: {}, - valid: function valid(obj) this.elements.every(function (e) !e.test || e.test(obj)) + valid: function valid(obj) this.elements.every(e => !e.test || e.test(obj)) }); let end = 0; @@ -295,7 +298,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), char = char.toLowerCase(); stack.top.elements.push(update( - function (obj) obj[char] != null ? quote(obj, char) : "", + function (obj) obj[char] != null ? quote(obj, char) + : "", { test: function test(obj) obj[char] != null })); for (let elem in array.iterValues(stack)) @@ -340,16 +344,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), let unknown = util.identity; if (!keepUnknown) - unknown = function () ""; + unknown = () => ""; function frame() update( function _frame(obj) - _frame === stack.top || _frame.valid(obj) ? - _frame.elements.map(function (e) callable(e) ? e(obj) : e).join("") : "", + _frame === stack.top || _frame.valid(obj) + ? _frame.elements.map(e => callable(e) ? e(obj) : e) + .join("") + : "", { elements: [], seen: {}, - valid: function valid(obj) this.elements.every(function (e) !e.test || e.test(obj)) + valid: function valid(obj) this.elements.every(e => (!e.test || e.test(obj))) }); let defaults = { lt: "<", gt: ">" }; @@ -396,7 +402,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), if (idx) { idx = Number(idx) - 1; stack.top.elements.push(update( - function (obj) obj[name] != null && idx in obj[name] ? quote(obj[name][idx]) + obj => obj[name] != null && idx in obj[name] ? quote(obj[name][idx]) : Set.has(obj, name) ? "" : unknown(full), { test: function test(obj) obj[name] != null && idx in obj[name] @@ -406,7 +412,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), } else { stack.top.elements.push(update( - function (obj) obj[name] != null ? quote(obj[name]) + obj => obj[name] != null ? quote(obj[name]) : Set.has(obj, name) ? "" : unknown(full), { test: function test(obj) obj[name] != null @@ -491,7 +497,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), fn(match); } res.push(pattern.substr(end)); - return res.map(function (s) util.dequote(s, dequote)); + return res.map(s => util.dequote(s, dequote)); }; let patterns = []; @@ -539,7 +545,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @returns {string} */ dequote: function dequote(pattern, chars) - pattern.replace(/\\(.)/, function (m0, m1) chars.indexOf(m1) >= 0 ? m1 : m0), + pattern.replace(/\\(.)/, (m0, m1) => chars.indexOf(m1) >= 0 ? m1 : m0), /** * Returns the nsIDocShell for the given window. @@ -582,10 +588,10 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {string} msg The trace message. * @param {number} frames The number of frames to print. */ - dumpStack: function dumpStack(msg, frames) { + dumpStack: function dumpStack(msg="Stack", frames=null) { let stack = util.stackLines(Error().stack); stack = stack.slice(1, 1 + (frames || stack.length)).join("\n").replace(/^/gm, " "); - util.dump((arguments.length == 0 ? "Stack" : msg) + "\n" + stack + "\n"); + util.dump(msg + "\n" + stack + "\n"); }, /** @@ -747,7 +753,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), httpGet: function httpGet(url, callback, self) { let params = callback; if (!isObject(params)) - params = { callback: params && function () callback.apply(self, arguments) }; + params = { callback: params && ((...args) => callback.apply(self, args)) }; try { let xmlhttp = services.Xmlhttp(); @@ -868,7 +874,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * top-level window and sub-frames thereof. */ iterDocuments: function iterDocuments(types) { - types = types ? types.map(function (s) "type" + util.capitalize(s)) + types = types ? types.map(s => "type" + util.capitalize(s)) : ["typeChrome", "typeContent"]; let windows = services.windowMediator.getXULWindowEnumerator(null); @@ -887,7 +893,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), }, // ripped from Firefox; modified - unsafeURI: Class.Memoize(function () util.regexp(String.replace(literal(/* + unsafeURI: Class.Memoize(() => util.regexp(String.replace(literal(/* [ \s // Invisible characters (bug 452979) @@ -933,10 +939,10 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), : val, isDOM ? /['%]/g : /['"%&<>]/g, - function (m) map[m]); + m => map[m]); } - return iter(obj).map(function ([k, v]) + return iter(obj).map(([k, v]) => [""].join("")) .join("\n"); }, @@ -999,7 +1005,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), if (color) { obj = template.highlightFilter(util.clip(obj, 150), "\n", - function () ["span", { highlight: "NonText" }, "^J"]); + () => ["span", { highlight: "NonText" }, + "^J"]); + var head = ["span", { highlight: "Title Object" }, obj, "::\n"]; } else @@ -1066,7 +1074,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), return String.localeCompare(a[0], b[0]); } - let vals = template.map(keys.sort(compare), function (f) f[1], "\n"); + let vals = template.map(keys.sort(compare), f => f[1], + "\n"); + if (color) { return ["div", { style: "white-space: pre-wrap" }, head, vals]; } @@ -1245,14 +1255,15 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), // Replace replacement . if (tokens) expr = String.replace(expr, /(\(?P)?<(\w+)>/g, - function (m, n1, n2) !n1 && Set.has(tokens, n2) ? tokens[n2].dactylSource - || tokens[n2].source - || tokens[n2] - : m); + (m, n1, n2) => !n1 && Set.has(tokens, n2) ? tokens[n2].dactylSource + || tokens[n2].source + || tokens[n2] + : m); // Strip comments and white space. if (/x/.test(flags)) - expr = String.replace(expr, /(\\.)|\/\/[^\n]*|\/\*[^]*?\*\/|\s+/gm, function (m, m1) m1 || ""); + expr = String.replace(expr, /(\\.)|\/\/[^\n]*|\/\*[^]*?\*\/|\s+/gm, + (m, m1) => m1 || ""); // Replace (?P parameters) if (/\(\?P m1 === "/" ? m1 + : m0), /** * Iterates over all matches of the given regexp in the given @@ -1345,7 +1358,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), }, errorCount: 0, - errors: Class.Memoize(function () []), + errors: Class.Memoize(() => []), maxErrors: 15, /** * Reports an error to the Error Console and the standard output, @@ -1411,7 +1424,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), let ary = host.split("."); ary = [ary.slice(i).join(".") for (i in util.range(ary.length, 0, -1))]; - return ary.filter(function (h) h.length >= base.length); + return ary.filter(h => h.length >= base.length); }, /** @@ -1669,7 +1682,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), catch (e) {} Array.forEach(frame.frames, rec); })(win); - return res.filter(function (h) !Set.add(seen, h)); + return res.filter(h => !Set.add(seen, h)); }, /** @@ -1688,7 +1701,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), catch (e) {} Array.forEach(frame.frames, rec); })(win); - return res.filter(function (h) !Set.add(seen, h.spec)); + return res.filter(h => !Set.add(seen, h.spec)); }, /**