// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2012 Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
}
});
- obj.observe.unregister = function () register("removeObserver");
+ obj.observe.unregister = () => register("removeObserver");
register("addObserver");
}, { dump: dump, Error: Error }),
* @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.
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;
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))
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: ">" };
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]
}
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
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 = [];
* @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.
* @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");
},
/**
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();
* 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);
},
// 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)
: val,
isDOM ? /['%]/g
: /['"%&<>]/g,
- function (m) map[m]);
+ m => map[m]);
}
- return iter(obj).map(function ([k, v])
+ return iter(obj).map(([k, v]) =>
["<!ENTITY ", k, " '", escape(v), "'>"].join(""))
.join("\n");
},
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
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];
}
// Replace replacement <tokens>.
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<named> parameters)
if (/\(\?P</.test(expr)) {
* @param {RegExp} re The regexp showable source of which is to be returned.
* @returns {string}
*/
- getSource: function regexp_getSource(re) re.source.replace(/\\(.)/g, function (m0, m1) m1 === "/" ? "/" : m0),
+ getSource: function regexp_getSource(re) re.source.replace(/\\(.)/g,
+ (m0, m1) => m1 === "/" ? m1
+ : m0),
/**
* Iterates over all matches of the given regexp in the given
},
errorCount: 0,
- errors: Class.Memoize(function () []),
+ errors: Class.Memoize(() => []),
maxErrors: 15,
/**
* Reports an error to the Error Console and the standard output,
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);
},
/**
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));
},
/**
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));
},
/**