1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-27 08:02:25 +01:00

Replace expression closures (methods).

Expression closures are to be axed. See https://bugzil.la/1083458.
This commit is contained in:
Doug Kearns
2015-07-23 01:55:32 +10:00
parent c035aa936b
commit 77d59cdfd1
45 changed files with 1595 additions and 1045 deletions

View File

@@ -19,12 +19,13 @@ var callResult = function callResult(method, ...args) {
return function (result) { result[method].apply(result, args); };
};
var listener = function listener(action, event)
function addonListener(install) {
var listener = function listener(action, event) {
return function addonListener(install) {
this.dactyl[install.error ? "echoerr" : "echomsg"](
_("addon.error", action, event, (install.name || install.sourceURI.spec) +
(install.error ? ": " + addons.errors[install.error] : "")));
};
};
var AddonListener = Class("AddonListener", {
init: function init(modules) {
@@ -84,14 +85,14 @@ var actions = {
name: "exte[nable]",
description: "Enable an extension",
action: function (addon) { addon.userDisabled = false; },
filter: function (addon) addon.userDisabled,
filter: function (addon) { return addon.userDisabled; },
perm: "enable"
},
disable: {
name: "extd[isable]",
description: "Disable an extension",
action: function (addon) { addon.userDisabled = true; },
filter: function (addon) !addon.userDisabled,
filter: function (addon) { return !addon.userDisabled; },
perm: "disable"
},
options: {
@@ -104,7 +105,9 @@ var actions = {
else
this.dactyl.open(addon.optionsURL, { from: "extoptions" });
},
filter: function (addon) addon.isActive && addon.optionsURL
filter: function (addon) {
return addon.isActive && addon.optionsURL;
}
},
rehash: {
name: "extr[ehash]",
@@ -185,7 +188,9 @@ var Addon = Class("Addon", {
action.actions([this], this.list.modules);
},
compare: function compare(other) String.localeCompare(this.name, other.name),
compare: function compare(other) {
return String.localeCompare(this.name, other.name);
},
get statusInfo() {
let info = this.isActive ? ["span", { highlight: "Enabled" }, "enabled"]
@@ -250,8 +255,8 @@ var Addon = Class("Addon", {
"scope", "screenshots", "size", "sourceURI", "translators", "type", "updateDate", "userDisabled",
"version"].forEach(function (prop) {
Object.defineProperty(Addon.prototype, prop, {
get: function get_proxy() this.addon[prop],
set: function set_proxy(val) this.addon[prop] = val
get: function get_proxy() { return this.addon[prop]; },
set: function set_proxy(val) { this.addon[prop] = val; }
});
});

View File

@@ -7,7 +7,9 @@
var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
var Cs = new Proxy(Components.stack, {
get: function Cs_get(target, prop) Components.stack.caller[prop]
get: function Cs_get(target, prop) {
return Components.stack.caller[prop];
}
});
function module(url) {
@@ -348,7 +350,7 @@ function deprecated(alternative, fn) {
let name,
func = callable(fn) ? fn
: function () apply(this, fn, arguments);
: function () { return apply(this, fn, arguments); };
function deprecatedMethod() {
let obj = !this ? "" :
@@ -365,7 +367,7 @@ function deprecated(alternative, fn) {
deprecatedMethod.realName = func.name;
return callable(fn) ? deprecatedMethod : Class.Property({
get: function () deprecatedMethod,
get: function () { return deprecatedMethod; },
init: function (prop) { name = prop; }
});
}
@@ -773,8 +775,9 @@ function memoize(obj, key, getter) {
}
},
set: function s_replaceProperty(val)
Class.replaceProperty(this.instance || this, key, val)
set: function s_replaceProperty(val) {
Class.replaceProperty(this.instance || this, key, val);
}
});
}
catch (e) {
@@ -905,7 +908,7 @@ function Class(...args) {
memoize(Constructor, "bound", Class.makeClosure);
if (Iter && Ary) // Hack. :/
Object.defineProperty(Constructor, "closure",
deprecated("bound", { get: function closure() this.bound }));
deprecated("bound", { get: function closure() { return this.bound; } }));
update(Constructor, args[1]);
Constructor.__proto__ = superclass;
@@ -972,8 +975,8 @@ Class.extend = function extend(subclass, superclass, overrides) {
* property's value.
* @returns {Class.Property}
*/
Class.Memoize = function Memoize(getter, wait)
Class.Property({
Class.Memoize = function Memoize(getter, wait) {
return Class.Property({
configurable: true,
enumerable: true,
init: function (key) {
@@ -1024,6 +1027,7 @@ Class.Memoize = function Memoize(getter, wait)
};
}
});
};
/**
* Updates the given object with the object in the target class's
@@ -1248,7 +1252,7 @@ function XPCOMShim(interfaces) {
throw Cr.NS_ERROR_NO_INTERFACE;
return this;
},
getHelperForLanguage: function () null,
getHelperForLanguage: function () { return null; },
getInterfaces: function (count) { count.value = 0; }
});
return (interfaces || []).reduce((shim, iface) => shim.QueryInterface(Ci[iface]),
@@ -1257,7 +1261,7 @@ function XPCOMShim(interfaces) {
let stub = Class.Property({
configurable: true,
enumerable: false,
value: function stub() null,
value: function stub() { return null; },
writable: true
});
@@ -1280,7 +1284,7 @@ var ErrorBase = Class("ErrorBase", Error, {
this.fileName = frame.filename;
this.lineNumber = frame.lineNumber;
},
toString: function () String(this.message)
toString: function () { return String(this.message); }
});
/**
@@ -1397,19 +1401,27 @@ var StructBase = Class("StructBase", Array, {
get toStringParams() { return this; },
clone: function struct_clone() this.constructor.apply(null, this.slice()),
clone: function struct_clone() {
return this.constructor.apply(null, this.slice());
},
bound: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "bound")),
closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "closure")),
get: function struct_get(key, val) this[this.members[key]],
set: function struct_set(key, val) this[this.members[key]] = val,
get: function struct_get(key, val) {
return this[this.members[key]];
},
set: function struct_set(key, val) {
return this[this.members[key]] = val;
},
toObject: function struct_toObject() {
return iter.toObject([k, this[k]] for (k of keys(this.members)));
},
toString: function struct_toString() Class.prototype.toString.apply(this, arguments),
toString: function struct_toString() {
return Class.prototype.toString.apply(this, arguments);
},
// Iterator over our named members
"@@iterator": function* struct__iterator__() {
@@ -1635,7 +1647,9 @@ function iter(obj, iface) {
return Iter(res);
}
update(iter, {
toArray: function toArray(iter) Ary(iter).array,
toArray: function toArray(iter) {
return Ary(iter).array;
},
// See Ary.prototype for API docs.
toObject: function toObject(iter) {
@@ -1648,7 +1662,9 @@ update(iter, {
return obj;
},
compact: function compact(iter) (item for (item of iter) if (item != null)),
compact: function compact(iter) {
return (item for (item of iter) if (item != null));
},
every: function every(iter, pred, self) {
pred = pred || identity;
@@ -1733,7 +1749,9 @@ update(iter, {
return undefined;
},
sort: function sort(iter, fn, self) Ary(iter).sort(fn, self),
sort: function sort(iter, fn, self) {
return Ary(iter).sort(fn, self);
},
uniq: function* uniq(iter) {
let seen = new RealSet;

View File

@@ -61,7 +61,7 @@ update(Bookmark.prototype, {
}
});
Bookmark.prototype.members.uri = Bookmark.prototype.members.url;
Bookmark.setter = function (key, func) this.prototype.__defineSetter__(key, func);
Bookmark.setter = function (key, func) { return this.prototype.__defineSetter__(key, func); };
Bookmark.setter("url", function (val) { this.uri = isString(val) ? newURI(val) : val; });
Bookmark.setter("title", function (val) { services.bookmarks.setItemTitle(this.id, val); });
Bookmark.setter("post", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.POST, val); });
@@ -87,7 +87,9 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
services.bookmarks.removeObserver(this);
},
"@@iterator": function () values(bookmarkcache.bookmarks),
"@@iterator": function () {
return values(bookmarkcache.bookmarks);
},
bookmarks: Class.Memoize(function () { return this.load(); }),
@@ -137,11 +139,13 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
return null;
},
readBookmark: function readBookmark(id) ({
itemId: id,
uri: services.bookmarks.getBookmarkURI(id).spec,
title: services.bookmarks.getItemTitle(id)
}),
readBookmark: function readBookmark(id) {
return {
itemId: id,
uri: services.bookmarks.getBookmarkURI(id).spec,
title: services.bookmarks.getItemTitle(id)
};
},
findRoot: function findRoot(id) {
do {
@@ -151,7 +155,9 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
return root;
},
isBookmark: function (id) this.rootFolders.indexOf(this.findRoot(id)) >= 0,
isBookmark: function (id) {
return this.rootFolders.indexOf(this.findRoot(id)) >= 0;
},
/**
* Returns true if the given URL is bookmarked and that bookmark is
@@ -254,9 +260,10 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
}, {
DEFAULT_FAVICON: "chrome://mozapps/skin/places/defaultFavicon.png",
getAnnotation: function getAnnotation(item, anno)
services.annotation.itemHasAnnotation(item, anno) ?
services.annotation.getItemAnnotation(item, anno) : null,
getAnnotation: function getAnnotation(item, anno) {
return services.annotation.itemHasAnnotation(item, anno) ?
services.annotation.getItemAnnotation(item, anno) : null;
},
getFavicon: function getFavicon(uri) {
try {

View File

@@ -29,18 +29,20 @@ lazyRequire("template", ["template"]);
* @instance buffer
*/
var Buffer = Module("Buffer", {
Local: function Local(dactyl, modules, window) ({
get win() {
return window.content;
let win = services.focus.focusedWindow;
if (!win || win == window || util.topWindow(win) != window)
Local: function Local(dactyl, modules, window) {
return {
get win() {
return window.content;
if (win.top == window)
return win;
return win.top;
}
}),
let win = services.focus.focusedWindow;
if (!win || win == window || util.topWindow(win) != window)
return window.content;
if (win.top == window)
return win;
return win.top;
}
};
},
init: function init(win) {
if (win)
@@ -870,31 +872,43 @@ var Buffer = Module("Buffer", {
* Scrolls the currently active element horizontally. See
* {@link Buffer.scrollHorizontal} for parameters.
*/
scrollHorizontal: function scrollHorizontal(increment, number)
Buffer.scrollHorizontal(this.findScrollable(number, true), increment, number),
scrollHorizontal: function scrollHorizontal(increment, number) {
return Buffer.scrollHorizontal(this.findScrollable(number, true),
increment,
number);
},
/**
* Scrolls the currently active element vertically. See
* {@link Buffer.scrollVertical} for parameters.
*/
scrollVertical: function scrollVertical(increment, number)
Buffer.scrollVertical(this.findScrollable(number, false), increment, number),
scrollVertical: function scrollVertical(increment, number) {
return Buffer.scrollVertical(this.findScrollable(number, false),
increment,
number);
},
/**
* Scrolls the currently active element to the given horizontal and
* vertical percentages. See {@link Buffer.scrollToPercent} for
* parameters.
*/
scrollToPercent: function scrollToPercent(horizontal, vertical, dir)
Buffer.scrollToPercent(this.findScrollable(dir || 0, vertical == null), horizontal, vertical),
scrollToPercent: function scrollToPercent(horizontal, vertical, dir) {
return Buffer.scrollToPercent(this.findScrollable(dir || 0, vertical == null),
horizontal,
vertical);
},
/**
* Scrolls the currently active element to the given horizontal and
* vertical positions. See {@link Buffer.scrollToPosition} for
* parameters.
*/
scrollToPosition: function scrollToPosition(horizontal, vertical)
Buffer.scrollToPosition(this.findScrollable(0, vertical == null), horizontal, vertical),
scrollToPosition: function scrollToPosition(horizontal, vertical) {
return Buffer.scrollToPosition(this.findScrollable(0, vertical == null),
horizontal,
vertical);
},
_scrollByScrollSize: function _scrollByScrollSize(count, direction) {
let { options } = this.modules;
@@ -2109,7 +2123,9 @@ var Buffer = Module("Buffer", {
}
},
notificationCallbacks: Class(XPCOM([Ci.nsIChannelEventSink, Ci.nsIInterfaceRequestor]), {
getInterface: function getInterface(iid) this.QueryInterface(iid),
getInterface: function getInterface(iid) {
return this.QueryInterface(iid);
},
asyncOnChannelRedirect: function (oldChannel, newChannel, flags, callback) {
if (newChannel instanceof Ci.nsIHttpChannel)

View File

@@ -52,14 +52,16 @@ var Cache = Module("Cache", XPCOM(Ci.nsIRequestObserver), {
});
},
Local: function Local(dactyl, modules, window) ({
init: function init() {
delete this.instance;
this.providers = {};
},
Local: function Local(dactyl, modules, window) {
return {
init: function init() {
delete this.instance;
this.providers = {};
},
isLocal: true
}),
isLocal: true
};
},
parse: function parse(str) {
if ('{['.contains(str[0]))
@@ -246,12 +248,16 @@ var Cache = Module("Cache", XPCOM(Ci.nsIRequestObserver), {
return result;
},
_has: function _has(name) hasOwnProperty(this.providers, name)
|| this.storage.has(name),
_has: function _has(name) {
return hasOwnProperty(this.providers, name) ||
this.storage.has(name);
},
has: function has(name) [this.globalProviders, this.localProviders]
.some(obj => isinstance(obj, ["Set"]) ? obj.has(name)
: hasOwnProperty(obj, name)),
has: function has(name) {
return [this.globalProviders, this.localProviders]
.some(obj => isinstance(obj, ["Set"]) ? obj.has(name)
: hasOwnProperty(obj, name));
},
register: function register(name, callback, long) {
if (this.isLocal)

View File

@@ -101,7 +101,9 @@ update(CommandOption, {
* E.g. "foo,bar"
* @final
*/
LIST: ArgType("list", function parseListArg(arg, quoted) Option.splitList(quoted))
LIST: ArgType("list", function parseListArg(arg, quoted) {
return Option.splitList(quoted);
})
});
/**
@@ -198,7 +200,9 @@ var Command = Class("Command", {
* @param {string} name The candidate name.
* @returns {boolean}
*/
hasName: function hasName(name) Command.hasName(this.parsedSpecs, name),
hasName: function hasName(name) {
return Command.hasName(this.parsedSpecs, name);
},
/**
* A helper function to parse an argument string.
@@ -212,12 +216,13 @@ var Command = Class("Command", {
* @returns {Args}
* @see Commands#parseArgs
*/
parseArgs: function parseArgs(args, complete, extra)
this.modules.commands.parseArgs(args, {
parseArgs: function parseArgs(args, complete, extra) {
return this.modules.commands.parseArgs(args, {
__proto__: this,
complete: complete,
extra: extra
}),
});
},
complained: Class.Memoize(() => new RealSet),
@@ -300,7 +305,7 @@ var Command = Class("Command", {
* whether to purge the command from history when clearing
* private data.
*/
domains: function (args) [],
domains: function (args) { return []; },
/**
* @property {boolean} At what index this command's literal arguments
@@ -343,8 +348,10 @@ var Command = Class("Command", {
explicitOpts: Class.Memoize(() => ({})),
has: function AP_has(opt) hasOwnProperty(this.explicitOpts, opt)
|| typeof opt === "number" && hasOwnProperty(this, opt),
has: function AP_has(opt) {
return hasOwnProperty(this.explicitOpts, opt) ||
typeof opt === "number" && hasOwnProperty(this, opt);
},
get literalArg() {
let { literal } = this.command;
@@ -369,7 +376,11 @@ var Command = Class("Command", {
this.options.forEach(function (opt) {
if (opt.default !== undefined) {
let prop = Object.getOwnPropertyDescriptor(opt, "default") ||
{ configurable: true, enumerable: true, get: function () opt.default };
{
configurable: true,
enumerable: true,
get: function () { return opt.default; }
};
if (prop.get && !prop.set)
prop.set = function (val) { Class.replaceProperty(this, opt.names[0], val); };
@@ -430,9 +441,10 @@ var Command = Class("Command", {
this.modules.dactyl.warn(loc + message);
}
}, {
hasName: function hasName(specs, name)
specs.some(([long, short]) =>
name.indexOf(short) == 0 && long.indexOf(name) == 0),
hasName: function hasName(specs, name) {
return specs.some(([long, short]) => name.indexOf(short) == 0 &&
long.indexOf(name) == 0);
},
// TODO: do we really need more than longNames as a convenience anyway?
/**
@@ -453,10 +465,12 @@ var Command = Class("Command", {
// Prototype.
var Ex = Module("Ex", {
Local: function Local(dactyl, modules, window) ({
get commands() { return modules.commands; },
get context() { return modules.contexts.context; }
}),
Local: function Local(dactyl, modules, window) {
return {
get commands() { return modules.commands; },
get context() { return modules.contexts.context; }
};
},
_args: function E_args(cmd, args) {
args = Array.slice(args);
@@ -506,7 +520,9 @@ var Ex = Module("Ex", {
});
},
__noSuchMethod__: function __noSuchMethod__(meth, args) this._run(meth).apply(this, args)
__noSuchMethod__: function __noSuchMethod__(meth, args) {
return this._run(meth).apply(this, args);
}
});
var CommandHive = Class("CommandHive", Contexts.Hive, {
@@ -849,10 +865,12 @@ var Commands = Module("commands", {
COUNT_ALL: -2, // :%...
/** @property {Iterator(Command)} @private */
iterator: function iterator() iter.apply(null, this.hives.array)
.sort((a, b) => (a.serialGroup - b.serialGroup ||
a.name > b.name))
.iterValues(),
iterator: function iterator() {
return iter.apply(null, this.hives.array)
.sort((a, b) => (a.serialGroup - b.serialGroup ||
a.name > b.name))
.iterValues();
},
/** @property {string} The last executed Ex command line. */
repeat: null,
@@ -921,8 +939,10 @@ var Commands = Module("commands", {
* any of the command's names.
* @returns {Command}
*/
get: function get(name, full) iter(this.hives).map(([i, hive]) => hive.get(name, full))
.find(identity),
get: function get(name, full) {
return iter(this.hives).map(([i, hive]) => hive.get(name, full))
.find(identity);
},
/**
* Returns true if a command invocation contains a URL referring to the
@@ -1261,7 +1281,14 @@ var Commands = Module("commands", {
complete.advance(args.completeStart);
complete.keys = {
text: "names",
description: function (opt) messages.get(["command", params.name, "options", opt.names[0], "description"].join("."), opt.description)
description: function (opt) {
return messages.get(["command",
params.name,
"options",
opt.names[0],
"description"].join("."),
opt.description);
}
};
complete.title = ["Options"];
if (completeOpts)
@@ -1478,10 +1505,12 @@ var Commands = Module("commands", {
return [len - str.length, arg, quote];
},
quote: function quote(str) Commands.quoteArg[
/[\b\f\n\r\t]/.test(str) ? '"' :
/[\s"'\\]|^$|^-/.test(str) ? "'"
: ""](str)
quote: function quote(str) {
return Commands.quoteArg[
/[\b\f\n\r\t]/.test(str) ? '"' :
/[\s"'\\]|^$|^-/.test(str) ? "'"
: ""](str);
}
}, {
completion: function initCompletion(dactyl, modules, window) {
const { completion, contexts } = modules;
@@ -1557,7 +1586,10 @@ var Commands = Module("commands", {
args[i] = start + i + end;
let params = {
args: { __proto__: args, toString: function () this.join(" ") },
args: {
__proto__: args,
toString: function () { return this.join(" "); }
},
bang: args.bang ? "!" : "",
count: args.count
};
@@ -1611,7 +1643,9 @@ var Commands = Module("commands", {
_("group.cantChangeBuiltin", _("command.commands")));
let completer = args["-complete"];
let completerFunc = function (context, args) modules.completion.exMacro(context, args, this);
let completerFunc = function (context, args) {
return modules.completion.exMacro(context, args, this);
};
if (completer) {
if (/^custom,/.test(completer)) {
@@ -1637,14 +1671,18 @@ var Commands = Module("commands", {
let added = args["-group"].add(cmd.split(","),
args["-description"],
contexts.bindMacro(args, "-ex",
function makeParams(args, modifiers) ({
args: {
__proto__: args,
toString: function () this.string
},
bang: this.bang && args.bang ? "!" : "",
count: this.count && args.count
})),
function makeParams(args, modifiers) {
return {
args: {
__proto__: args,
toString: function () {
return this.string;
}
},
bang: this.bang && args.bang ? "!" : "",
count: this.count && args.count
};
}),
{
argCount: args["-nargs"],
bang: args["-bang"],
@@ -1782,13 +1820,15 @@ var Commands = Module("commands", {
name: ["listc[ommands]", "lc"],
description: "List all Ex commands along with their short descriptions",
index: "ex-cmd",
iterate: function (args) commands.iterator().map(cmd => ({
__proto__: cmd,
columns: [
cmd.hive == commands.builtin ? "" : ["span", { highlight: "Object", style: "padding-right: 1em;" },
cmd.hive.name]
]
})),
iterate: function (args) {
return commands.iterator().map(cmd => ({
__proto__: cmd,
columns: [
cmd.hive == commands.builtin ? "" : ["span", { highlight: "Object", style: "padding-right: 1em;" },
cmd.hive.name]
]
}));
},
iterateIndex: function (args) {
let tags = help.tags;
return this.iterate(args).filter(cmd => (cmd.hive === commands.builtin ||
@@ -1796,8 +1836,10 @@ var Commands = Module("commands", {
},
format: {
headings: ["Command", "Group", "Description"],
description: function (cmd) template.linkifyHelp(cmd.description + (cmd.replacementText ? ": " + cmd.action : "")),
help: function (cmd) ":" + cmd.name
description: function (cmd) {
return template.linkifyHelp(cmd.description + (cmd.replacementText ? ": " + cmd.action : ""));
},
help: function (cmd) { return ":" + cmd.name; }
}
});

View File

@@ -111,7 +111,9 @@ var CompletionContext = Class("CompletionContext", {
this.anchored = true;
this.forceAnchored = null;
this.compare = function compare(a, b) String.localeCompare(a.text, b.text);
this.compare = function compare(a, b) {
return String.localeCompare(a.text, b.text);
};
/**
* @property {function} This function is called when we close
* a completion window with Esc or Ctrl-c. Usually this callback
@@ -219,9 +221,11 @@ var CompletionContext = Class("CompletionContext", {
* Returns a key, as detailed in {@link #keys}.
* @function
*/
this.getKey = function getKey(item, key) (typeof self.keys[key] == "function") ? self.keys[key].call(this, item.item) :
this.getKey = function getKey(item, key) {
return (typeof self.keys[key] == "function") ? self.keys[key].call(this, item.item) :
key in self.keys ? item.item[self.keys[key]]
: item.item[key];
};
return this;
},
@@ -330,7 +334,9 @@ var CompletionContext = Class("CompletionContext", {
},
// Temporary
get longestAllSubstring() {
return this.allSubstrings.reduce(function r(a, b) a.length > b.length ? a : b, "");
return this.allSubstrings.reduce(function r(a, b) {
return a.length > b.length ? a : b, "";
});
},
get caret() { return this._caret - this.offset; },
@@ -536,12 +542,12 @@ var CompletionContext = Class("CompletionContext", {
// Item matchers
if (this.ignoreCase)
this.matchString = this.anchored ?
function matchString(filter, str) String.toLowerCase(str).indexOf(filter.toLowerCase()) == 0 :
function matchString(filter, str) String.toLowerCase(str).indexOf(filter.toLowerCase()) >= 0;
function matchString(filter, str) { return String.toLowerCase(str).indexOf(filter.toLowerCase()) == 0; } :
function matchString(filter, str) { return String.toLowerCase(str).indexOf(filter.toLowerCase()) >= 0; };
else
this.matchString = this.anchored ?
function matchString(filter, str) String.indexOf(str, filter) == 0 :
function matchString(filter, str) String.indexOf(str, filter) >= 0;
function matchString(filter, str) { return String.indexOf(str, filter) == 0; } :
function matchString(filter, str) { return String.indexOf(str, filter) >= 0; };
// Item formatters
this.processor = Array.slice(this.process);
@@ -571,7 +577,9 @@ var CompletionContext = Class("CompletionContext", {
filtered.sort(this.compare);
if (!this.anchored) {
let filter = this.filter;
filtered.sort(function s(a, b) b.text.startsWith(filter) - a.text.startsWith(filter));
filtered.sort(function s(a, b) {
return b.text.startsWith(filter) - a.text.startsWith(filter);
});
}
}
@@ -604,11 +612,11 @@ var CompletionContext = Class("CompletionContext", {
text = text.substr(0, 100);
if (this.anchored) {
var compare = function compare(text, s) text.substr(0, s.length) == s;
var compare = function compare(text, s) { return text.substr(0, s.length) == s; };
var substrings = [text];
}
else {
var compare = function compare(text, s) text.contains(s);
var compare = function compare(text, s) { return text.contains(s); };
var substrings = [];
let start = 0;
let idx;
@@ -619,8 +627,8 @@ var CompletionContext = Class("CompletionContext", {
}
}
substrings = items.reduce(function r(res, item)
res.map(function m(substring) {
substrings = items.reduce(function r(res, item) {
return res.map(function m(substring) {
// A simple binary search to find the longest substring
// of the given string which also matches the current
// item's text.
@@ -640,8 +648,8 @@ var CompletionContext = Class("CompletionContext", {
}
}
return len == substring.length ? substring : substring.substr(0, Math.max(len, 0));
}),
substrings);
});
}, substrings);
let quote = this.quote;
if (quote)
@@ -860,7 +868,9 @@ var CompletionContext = Class("CompletionContext", {
* @param {string} str The string to match.
* @returns {boolean} True if the string matches, false otherwise.
*/
match: function match(str) this.matchString(this.filter, str),
match: function match(str) {
return this.matchString(this.filter, str);
},
/**
* Pushes a new output processor onto the processor chain of
@@ -874,7 +884,9 @@ var CompletionContext = Class("CompletionContext", {
*/
pushProcessor: function pushProcess(index, func) {
let next = this.process[index];
this.process[index] = function process_(item, text) func(item, text, next);
this.process[index] = function process_(item, text) {
return func(item, text, next);
};
},
/**
@@ -887,7 +899,8 @@ var CompletionContext = Class("CompletionContext", {
throw Error();
this.offset = 0;
this.process = [template.icon, function process_1(item, k) k];
this.process = [template.icon,
function process_1(item, k) { return k; }];
this.filters = [CompletionContext.Filter.text];
this.tabPressed = false;
this.title = ["Completions"];
@@ -931,8 +944,10 @@ var CompletionContext = Class("CompletionContext", {
}
}, {
Sort: {
number: function S_number(a, b) parseInt(a.text) - parseInt(b.text)
|| String.localeCompare(a.text, b.text),
number: function S_number(a, b) {
return parseInt(a.text) - parseInt(b.text) ||
String.localeCompare(a.text, b.text);
},
unsorted: null
},
@@ -962,65 +977,67 @@ var Completion = Module("completion", {
get setFunctionCompleter() { return JavaScript.setCompleter; }, // Backward compatibility
Local: function Local(dactyl, modules, window) ({
urlCompleters: {},
Local: function Local(dactyl, modules, window) {
return {
urlCompleters: {},
get modules() { return modules; },
get options() { return modules.options; },
get modules() { return modules; },
get options() { return modules.options; },
// FIXME
_runCompleter: function _runCompleter(name, filter, maxItems, ...args) {
let context = modules.CompletionContext(filter);
context.maxItems = maxItems;
let res = apply(context, "fork", ["run", 0, this, name].concat(args));
if (res) {
if (Components.stack.caller.name === "runCompleter") // FIXME
return {
items: res.map(function m(i) {
return { item: i };
})
};
context.contexts["/run"].completions = res;
// FIXME
_runCompleter: function _runCompleter(name, filter, maxItems, ...args) {
let context = modules.CompletionContext(filter);
context.maxItems = maxItems;
let res = apply(context, "fork", ["run", 0, this, name].concat(args));
if (res) {
if (Components.stack.caller.name === "runCompleter") // FIXME
return {
items: res.map(function m(i) {
return { item: i };
})
};
context.contexts["/run"].completions = res;
}
context.wait(null, true);
return context.allItems;
},
runCompleter: function runCompleter(name, filter, maxItems) {
return apply(this, "_runCompleter", arguments)
.items.map(function m(i) { return i.item; });
},
listCompleter: function listCompleter(name, filter, maxItems, ...args) {
let context = modules.CompletionContext(filter || "");
context.maxItems = maxItems;
apply(context, "fork", ["list", 0, this, name].concat(args));
context = context.contexts["/list"];
context.wait(null, true);
let contexts = context.activeContexts;
if (!contexts.length)
contexts = context.contextList
.filter(function f(c) {
return c.hasItems;
})
.slice(0, 1);
if (!contexts.length)
contexts = context.contextList.slice(-1);
modules.commandline.commandOutput(
["div", { highlight: "Completions" },
template.map(contexts, function m(context) {
return [template.completionRow(context.title, "CompTitle"),
template.map(context.items,
function m(item) {
return context.createRow(item);
},
null,
100)];
})]);
}
context.wait(null, true);
return context.allItems;
},
runCompleter: function runCompleter(name, filter, maxItems) {
return apply(this, "_runCompleter", arguments)
.items.map(function m(i) { return i.item; });
},
listCompleter: function listCompleter(name, filter, maxItems, ...args) {
let context = modules.CompletionContext(filter || "");
context.maxItems = maxItems;
apply(context, "fork", ["list", 0, this, name].concat(args));
context = context.contexts["/list"];
context.wait(null, true);
let contexts = context.activeContexts;
if (!contexts.length)
contexts = context.contextList
.filter(function f(c) {
return c.hasItems;
})
.slice(0, 1);
if (!contexts.length)
contexts = context.contextList.slice(-1);
modules.commandline.commandOutput(
["div", { highlight: "Completions" },
template.map(contexts, function m(context) {
return [template.completionRow(context.title, "CompTitle"),
template.map(context.items,
function m(item) {
return context.createRow(item);
},
null,
100)];
})]);
}
}),
};
},
////////////////////////////////////////////////////////////////////////////////
////////////////////// COMPLETION TYPES ////////////////////////////////////////
@@ -1147,7 +1164,9 @@ var Completion = Module("completion", {
let contains = String.indexOf;
if (context.ignoreCase) {
compare = util.compareIgnoreCase;
contains = function contains_(a, b) a && a.toLowerCase().contains(b.toLowerCase());
contains = function contains_(a, b) {
return a && a.toLowerCase().contains(b.toLowerCase());
};
}
if (tags)
@@ -1191,8 +1210,12 @@ var Completion = Module("completion", {
}
let process = context.process;
context.process = [
function process_0(item, text) highlight.call(this, item, item.text, 0),
function process_1(item, text) highlight.call(this, item, text, 1)
function process_0(item, text) {
return highlight.call(this, item, item.text, 0);
},
function process_1(item, text) {
return highlight.call(this, item, text, 1);
}
];
});
}

View File

@@ -40,7 +40,7 @@ AboutHandler.prototype = {
return channel;
},
getURIFlags: function (uri) Ci.nsIAboutModule.ALLOW_SCRIPT
getURIFlags: function (uri) { return Ci.nsIAboutModule.ALLOW_SCRIPT; }
};
var ConfigBase = Class("ConfigBase", {
/**
@@ -74,14 +74,20 @@ var ConfigBase = Class("ConfigBase", {
services["dactyl:"].pages["dtd"] = () => [null, cache.get("config.dtd")];
update(services["dactyl:"].providers, {
"locale": function (uri, path) LocaleChannel("dactyl-locale", config.locale, path, uri),
"locale-local": function (uri, path) LocaleChannel("dactyl-local-locale", config.locale, path, uri)
"locale": function (uri, path) {
return LocaleChannel("dactyl-locale", config.locale, path, uri);
},
"locale-local": function (uri, path) {
return LocaleChannel("dactyl-local-locale", config.locale, path, uri);
}
});
},
get prefs() { return localPrefs; },
has: function (feature) this.features.has(feature),
has: function (feature) {
return this.features.has(feature);
},
configFiles: [
"resource://dactyl-common/config.json",
@@ -478,59 +484,61 @@ var ConfigBase = Class("ConfigBase", {
this.helpStyled = true;
},
Local: function Local(dactyl, modules, { document, window }) ({
init: function init() {
this.loadConfig(document.documentURI);
Local: function Local(dactyl, modules, { document, window }) {
return {
init: function init() {
this.loadConfig(document.documentURI);
let append = [
["menupopup", { id: "viewSidebarMenu", xmlns: "xul" }],
["broadcasterset", { id: "mainBroadcasterSet", xmlns: "xul" }]];
let append = [
["menupopup", { id: "viewSidebarMenu", xmlns: "xul" }],
["broadcasterset", { id: "mainBroadcasterSet", xmlns: "xul" }]];
for (let [id, [name, key, uri]] of iter(this.sidebars)) {
append[0].push(
["menuitem", { observes: "pentadactyl-" + id + "Sidebar", label: name,
accesskey: key }]);
append[1].push(
["broadcaster", { id: "pentadactyl-" + id + "Sidebar", autoCheck: "false",
type: "checkbox", group: "sidebar", sidebartitle: name,
sidebarurl: uri,
oncommand: "toggleSidebar(this.id || this.observes);" }]);
}
for (let [id, [name, key, uri]] of iter(this.sidebars)) {
append[0].push(
["menuitem", { observes: "pentadactyl-" + id + "Sidebar", label: name,
accesskey: key }]);
append[1].push(
["broadcaster", { id: "pentadactyl-" + id + "Sidebar", autoCheck: "false",
type: "checkbox", group: "sidebar", sidebartitle: name,
sidebarurl: uri,
oncommand: "toggleSidebar(this.id || this.observes);" }]);
}
util.overlayWindow(window, { append: append });
},
util.overlayWindow(window, { append: append });
},
get window() { return window; },
get window() { return window; },
get document() { return document; },
get document() { return document; },
ids: Class.Update({
get commandContainer() { return document.documentElement.id; }
}),
ids: Class.Update({
get commandContainer() { return document.documentElement.id; }
}),
browser: Class.Memoize(() => window.gBrowser),
tabbrowser: Class.Memoize(() => window.gBrowser),
browser: Class.Memoize(() => window.gBrowser),
tabbrowser: Class.Memoize(() => window.gBrowser),
get browserModes() { return [modules.modes.NORMAL]; },
get browserModes() { return [modules.modes.NORMAL]; },
/**
* @property {string} The ID of the application's main XUL window.
*/
mainWindowId: document.documentElement.id,
/**
* @property {string} The ID of the application's main XUL window.
*/
mainWindowId: document.documentElement.id,
/**
* @property {number} The height (px) that is available to the output
* window.
*/
get outputHeight() {
return this.browser.mPanelContainer.boxObject.height;
},
/**
* @property {number} The height (px) that is available to the output
* window.
*/
get outputHeight() {
return this.browser.mPanelContainer.boxObject.height;
},
tabStrip: Class.Memoize(function () {
return document.getElementById("TabsToolbar") ||
this.tabbrowser.mTabContainer;
})
}),
tabStrip: Class.Memoize(function () {
return document.getElementById("TabsToolbar") ||
this.tabbrowser.mTabContainer;
})
};
},
/**
* @property {Object} A mapping of names and descriptions

View File

@@ -57,7 +57,7 @@ var Group = Class("Group", {
this.children.splice(0).forEach(this.contexts.bound.removeGroup);
},
argsExtra: function argsExtra() ({}),
argsExtra: function argsExtra() { return {}; },
makeArgs: function makeArgs(doc, context, args) {
let res = update({ doc: doc, context: context }, args);
@@ -78,7 +78,9 @@ var Group = Class("Group", {
}
return update(siteFilter, {
toString: function () this.filters.join(","),
toString: function () {
return this.filters.join(",");
},
toJSONXML: function (modules) {
let uri = modules && modules.buffer.uri;
@@ -112,118 +114,120 @@ var Contexts = Module("contexts", {
this.pluginModules = {};
},
Local: function Local(dactyl, modules, window) ({
init: function () {
const contexts = this;
this.modules = modules;
Local: function Local(dactyl, modules, window) {
return {
init: function () {
const contexts = this;
this.modules = modules;
Object.defineProperty(modules.plugins, "contexts", Const({}));
Object.defineProperty(modules.plugins, "contexts", Const({}));
this.groupList = [];
this.groupMap = {};
this.groupsProto = {};
this.hives = {};
this.hiveProto = {};
this.groupList = [];
this.groupMap = {};
this.groupsProto = {};
this.hives = {};
this.hiveProto = {};
this.builtin = this.addGroup("builtin", "Builtin items");
this.user = this.addGroup("user", "User-defined items", null, true);
this.builtinGroups = [this.builtin, this.user];
this.builtin.modifiable = false;
this.builtin = this.addGroup("builtin", "Builtin items");
this.user = this.addGroup("user", "User-defined items", null, true);
this.builtinGroups = [this.builtin, this.user];
this.builtin.modifiable = false;
this.GroupFlag = Class("GroupFlag", CommandOption, {
init: function (name) {
this.GroupFlag = Class("GroupFlag", CommandOption, {
init: function (name) {
this.name = name;
this.type = ArgType("group", group => {
return isString(group) ? contexts.getGroup(group, name)
: group[name];
});
},
get toStringParams() { return [this.name]; },
names: ["-group", "-g"],
description: "Group to which to add",
get default() {
return (contexts.context &&
contexts.context.group ||
contexts.user)[this.name];
},
completer: function (context) {
modules.completion.group(context);
}
});
memoize(modules, "userContext", () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, false]));
memoize(modules, "_userContext", () => modules.userContext);
},
cleanup: function () {
for (let hive of this.groupList.slice())
util.trapErrors("cleanup", hive, "shutdown");
},
destroy: function () {
for (let hive of this.groupList.slice())
util.trapErrors("destroy", hive, "shutdown");
for (let plugin of values(this.modules.plugins.contexts)) {
if (plugin && "onUnload" in plugin && callable(plugin.onUnload))
util.trapErrors("onUnload", plugin);
if (isinstance(plugin, ["Sandbox"]))
util.trapErrors("nukeSandbox", Cu, plugin);
}
},
signals: {
"browser.locationChange": function (webProgress, request, uri) {
this.flush();
}
},
Group: Class("Group", Group,
{ modules: modules,
get hiveMap() { return modules.contexts.hives; }}),
Hives: Class("Hives", Class.Property, {
init: function init(name, constructor) {
const { contexts } = modules;
if (this.Hive)
return {
enumerable: true,
get: () => Ary(contexts.groups[this.name])
};
this.Hive = constructor;
this.name = name;
memoize(contexts.Group.prototype, name, function () {
let group = constructor(this);
this.hives.push(group);
contexts.flush();
return group;
});
this.type = ArgType("group", group => {
return isString(group) ? contexts.getGroup(group, name)
: group[name];
memoize(contexts.hives, name,
() => Object.create(
Object.create(contexts.hiveProto,
{ _hive: { value: name } })));
memoize(contexts.groupsProto, name, function () {
return [group[name]
for (group of values(this.groups))
if (hasOwnProperty(group, name))];
});
},
get toStringParams() { return [this.name]; },
names: ["-group", "-g"],
description: "Group to which to add",
get default() {
return (contexts.context &&
contexts.context.group ||
contexts.user)[this.name];
},
completer: function (context) {
modules.completion.group(context);
}
});
memoize(modules, "userContext", () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, false]));
memoize(modules, "_userContext", () => modules.userContext);
},
cleanup: function () {
for (let hive of this.groupList.slice())
util.trapErrors("cleanup", hive, "shutdown");
},
destroy: function () {
for (let hive of this.groupList.slice())
util.trapErrors("destroy", hive, "shutdown");
for (let plugin of values(this.modules.plugins.contexts)) {
if (plugin && "onUnload" in plugin && callable(plugin.onUnload))
util.trapErrors("onUnload", plugin);
if (isinstance(plugin, ["Sandbox"]))
util.trapErrors("nukeSandbox", Cu, plugin);
}
},
signals: {
"browser.locationChange": function (webProgress, request, uri) {
this.flush();
}
},
Group: Class("Group", Group,
{ modules: modules,
get hiveMap() { return modules.contexts.hives; }}),
Hives: Class("Hives", Class.Property, {
init: function init(name, constructor) {
const { contexts } = modules;
if (this.Hive)
return {
enumerable: true,
get: () => Ary(contexts.groups[this.name])
};
this.Hive = constructor;
this.name = name;
memoize(contexts.Group.prototype, name, function () {
let group = constructor(this);
this.hives.push(group);
contexts.flush();
return group;
});
memoize(contexts.hives, name,
() => Object.create(
Object.create(contexts.hiveProto,
{ _hive: { value: name } })));
memoize(contexts.groupsProto, name, function () {
return [group[name]
for (group of values(this.groups))
if (hasOwnProperty(group, name))];
});
},
get toStringParams() { return [this.name, this.Hive]; }
})
}),
get toStringParams() { return [this.name, this.Hive]; }
})
};
},
Context: function Context(file, group, args) {
const { contexts, io, newContext, plugins, userContext } = this.modules;
@@ -292,7 +296,7 @@ var Contexts = Module("contexts", {
Object.defineProperty(plugins, self.NAME, {
configurable: true,
enumerable: true,
get: function () self,
get: function () { return self; },
set: function (val) {
util.dactyl(val).reportError(FailedAssertion(_("plugin.notReplacingContext", self.NAME), 3, false), true);
}
@@ -377,7 +381,7 @@ var Contexts = Module("contexts", {
Object.defineProperty(plugins, self.NAME, {
configurable: true,
enumerable: true,
get: function () self,
get: function () { return self; },
set: function (val) {
util.dactyl(val).reportError(FailedAssertion(_("plugin.notReplacingContext", self.NAME), 3, false), true);
}
@@ -413,9 +417,10 @@ var Contexts = Module("contexts", {
});
}),
matchingGroups: function (uri) Object.create(this.groupsProto, {
groups: { value: this.activeGroups(uri) }
}),
matchingGroups: function (uri) {
return Object.create(this.groupsProto,
{ groups: { value: this.activeGroups(uri) } });
},
activeGroups: function (uri) {
if (uri instanceof Ci.nsIDOMDocument)
@@ -525,8 +530,8 @@ var Contexts = Module("contexts", {
return Class.Property({
configurable: true,
enumerable: true,
get: function Proxy_get() process(obj[key]),
set: function Proxy_set(val) obj[key] = val
get: function Proxy_get() { return process(obj[key]); },
set: function Proxy_set(val) { obj[key] = val; }
});
}
@@ -592,11 +597,12 @@ var Contexts = Module("contexts", {
return action;
},
withContext: function withContext(defaults, callback, self)
this.withSavedValues(["context"], function () {
withContext: function withContext(defaults, callback, self) {
return this.withSavedValues(["context"], function () {
this.context = defaults && update({}, defaults);
return callback.call(self, this.context);
})
});
}
}, {
Hive: Class("Hive", {
init: function init(group) {

View File

@@ -22,7 +22,9 @@ var NS = "http://vimperator.org/namespaces/liberator";
function BooleanAttribute(attr) {
return {
get: function (elem) elem.getAttribute(attr) == "true",
get: function (elem) {
return elem.getAttribute(attr) == "true";
},
set: function (elem, val) {
if (val === "false" || !val)
elem.removeAttribute(attr);
@@ -86,7 +88,9 @@ var DOM = Class("DOM", {
yield this[i];
},
Empty: function Empty() this.constructor(null, this.document),
Empty: function Empty() {
return this.constructor(null, this.document);
},
nodes: Class.Memoize(() => ({})),
@@ -117,7 +121,10 @@ var DOM = Class("DOM", {
}
},
matcher: function matcher(sel) elem => (elem.mozMatchesSelector && elem.mozMatchesSelector(sel)),
matcher: function matcher(sel) {
return elem => (elem.mozMatchesSelector &&
elem.mozMatchesSelector(sel));
},
each: function each(fn, self) {
let obj = self || this.Empty();
@@ -292,7 +299,9 @@ var DOM = Class("DOM", {
let self = this;
return {
toString: function () self[0].className,
toString: function () {
return self[0].className;
},
get list() { return Array.slice(self[0].classList); },
set list(val) { self.attr("class", val.join(" ")); },
@@ -303,8 +312,10 @@ var DOM = Class("DOM", {
});
},
add: function add(cls) this.each("add", cls),
remove: function remove(cls) this.each("remove", cls),
add: function add(cls) { return this.each("add", cls); },
remove: function remove(cls) {
return this.each("remove", cls);
},
toggle: function toggle(cls, val, thisObj) {
if (callable(val))
return self.each(function (elem, i) {
@@ -313,7 +324,9 @@ var DOM = Class("DOM", {
return this.each(val == null ? "toggle" : val ? "add" : "remove", cls);
},
has: function has(cls) this[0].classList.has(cls)
has: function has(cls) {
return this[0].classList.has(cls);
}
};
},
@@ -321,7 +334,9 @@ var DOM = Class("DOM", {
let self = this;
return {
toString: function () self.attrNS(NS, "highlight") || "",
toString: function () {
return self.attrNS(NS, "highlight") || "";
},
get list() {
let s = this.toString().trim();
@@ -334,31 +349,39 @@ var DOM = Class("DOM", {
self.attrNS(NS, "highlight", str || null);
},
has: function has(hl) ~this.list.indexOf(hl),
has: function has(hl) {
return ~this.list.indexOf(hl);
},
add: function add(hl) self.each(function () {
highlight.loaded[hl] = true;
this.highlight.list = this.highlight.list.concat(hl);
}),
add: function add(hl) {
self.each(function () {
highlight.loaded[hl] = true;
this.highlight.list = this.highlight.list.concat(hl);
});
},
remove: function remove(hl) self.each(function () {
this.highlight.list = this.highlight.list.filter(h => h != hl);
}),
remove: function remove(hl) {
self.each(function () {
this.highlight.list = this.highlight.list.filter(h => h != hl);
});
},
toggle: function toggle(hl, val, thisObj) self.each(function (elem, i) {
let { highlight } = this;
let v = callable(val) ? val.call(thisObj || this, elem, i) : val;
toggle: function toggle(hl, val, thisObj) {
self.each(function (elem, i) {
let { highlight } = this;
let v = callable(val) ? val.call(thisObj || this, elem, i) : val;
highlight[(v == null ? highlight.has(hl) : !v) ? "remove" : "add"](hl);
})
highlight[(v == null ? highlight.has(hl) : !v) ? "remove" : "add"](hl);
});
}
};
},
get rect() {
return this[0] instanceof Ci.nsIDOMWindow ? { width: this[0].scrollMaxX + this[0].innerWidth,
height: this[0].scrollMaxY + this[0].innerHeight,
get right() this.width + this.left,
get bottom() this.height + this.top,
get right() { return this.width + this.left; },
get bottom() { return this.height + this.top; },
top: -this[0].scrollY,
left: -this[0].scrollX } :
this[0] ? this[0].getBoundingClientRect() : {};
@@ -712,9 +735,13 @@ var DOM = Class("DOM", {
return this[0].style[css.property(key)];
}, {
name: function (property) property.replace(/[A-Z]/g, m0 => "-" + m0.toLowerCase()),
name: function (property) {
return property.replace(/[A-Z]/g, m0 => "-" + m0.toLowerCase());
},
property: function (name) name.replace(/-(.)/g, (m0, m1) => m1.toUpperCase())
property: function (name) {
return name.replace(/-(.)/g, (m0, m1) => m1.toUpperCase());
}
}),
append: function append(val) {
@@ -789,8 +816,9 @@ var DOM = Class("DOM", {
return this;
},
clone: function clone(deep)
this.map(elem => elem.cloneNode(deep)),
clone: function clone(deep) {
return this.map(elem => elem.cloneNode(deep));
},
toggle: function toggle(val, self) {
if (callable(val))
@@ -824,11 +852,13 @@ var DOM = Class("DOM", {
}, this);
},
createContents: function createContents()
this.each(DOM.createContents, this),
createContents: function createContents() {
return this.each(DOM.createContents, this);
},
isScrollable: function isScrollable(direction)
this.length && DOM.isScrollable(this[0], direction),
isScrollable: function isScrollable(direction) {
return this.length && DOM.isScrollable(this[0], direction);
},
getSet: function getSet(args, get, set) {
if (!args.length)
@@ -1455,16 +1485,19 @@ var DOM = Class("DOM", {
? (elem, dir) => services.dactyl.getScrollable(elem) & (dir ? services.dactyl["DIRECTION_" + dir.toUpperCase()] : ~0)
: (elem, dir) => true),
isJSONXML: function isJSONXML(val) isArray(val) && isinstance(val[0], ["String", "Array", "XML", DOM.DOMString])
|| isObject(val) && "toDOM" in val,
isJSONXML: function isJSONXML(val) {
return isArray(val) &&
isinstance(val[0], ["String", "Array", "XML", DOM.DOMString]) ||
isObject(val) && "toDOM" in val;
},
DOMString: function DOMString(val) ({
__proto__: DOMString.prototype,
toDOM: function toDOM(doc) doc.createTextNode(val),
toString: function () val
}),
DOMString: function DOMString(val) {
return {
__proto__: DOMString.prototype,
toDOM: function toDOM(doc) { return doc.createTextNode(val); },
toString: function () { return val; }
};
},
/**
* The set of input element type attribute values that mark the element as
@@ -1889,10 +1922,12 @@ var DOM = Class("DOM", {
);
let res = {
iterateNext: function () result.iterateNext(),
iterateNext: function () { return result.iterateNext(); },
get resultType() { return result.resultType; },
get snapshotLength() { return result.snapshotLength; },
snapshotItem: function (i) result.snapshotItem(i)
snapshotItem: function (i) {
return result.snapshotItem(i);
}
};
if (asIterator)
res[Symbol.iterator] = function* () {
@@ -1912,7 +1947,9 @@ var DOM = Class("DOM", {
}
},
{
resolver: function lookupNamespaceURI(prefix) (DOM.namespaces[prefix] || null)
resolver: function lookupNamespaceURI(prefix) {
return DOM.namespaces[prefix] || null;
}
}),
/**

View File

@@ -76,7 +76,9 @@ var Download = Class("Download", {
get status() { return states[this.state]; },
inState: function inState(states) states.indexOf(this.status) >= 0,
inState: function inState(states) {
return states.indexOf(this.status) >= 0;
},
allowedCommands: Class.Memoize(function () {
let self = this;
@@ -161,11 +163,12 @@ var Download = Class("Download", {
url: (a, b) => String.localeCompare(a.source.url, b.source.url)
},
compare: function compare(other) values(this.list.sortOrder).map(function (order) {
let val = this._compare[order.substr(1)](this, other);
return (order[0] == "-") ? -val : val;
}, this).find(identity) || 0,
compare: function compare(other) {
return values(this.list.sortOrder).map(function (order) {
let val = this._compare[order.substr(1)](this, other);
return (order[0] == "-") ? -val : val;
}, this).find(identity) || 0;
},
timeRemaining: Infinity,
@@ -344,7 +347,9 @@ var DownloadList = Class("DownloadList",
this.nodes.list.childNodes[i + 1]);
},
shouldSort: function shouldSort() Array.some(arguments, val => this.sortOrder.some(v => v.substr(1) == val)),
shouldSort: function shouldSort() {
return Array.some(arguments, val => this.sortOrder.some(v => v.substr(1) == val));
},
update: function update() {
for (let node of values(this.nodes))
@@ -427,8 +432,8 @@ var DownloadList = Class("DownloadList",
"tryToKeepPartialData"].forEach(key => {
if (!(key in Download.prototype))
Object.defineProperty(Download.prototype, key, {
get: function get() this.download[key],
set: function set(val) this.download[key] = val,
get: function get() { return this.download[key]; },
set: function set(val) { this.download[key] = val; },
configurable: true
});
});

View File

@@ -23,32 +23,34 @@ function equals(a, b) {
/** @instance rangefinder */
var RangeFinder = Module("rangefinder", {
Local: function (dactyl, modules, window) ({
init: function () {
this.dactyl = dactyl;
this.modules = modules;
this.window = window;
this.lastFindPattern = "";
},
Local: function (dactyl, modules, window) {
return {
init: function () {
this.dactyl = dactyl;
this.modules = modules;
this.window = window;
this.lastFindPattern = "";
},
get content() {
let { window } = this.modes.getStack(0).params;
return window || this.window.content;
},
get content() {
let { window } = this.modes.getStack(0).params;
return window || this.window.content;
},
get rangeFind() {
let find = overlay.getData(this.content.document,
"range-find", null);
get rangeFind() {
let find = overlay.getData(this.content.document,
"range-find", null);
if (!isinstance(find, RangeFind) || find.stale)
return this.rangeFind = null;
return find;
},
set rangeFind(val) {
overlay.setData(this.content.document,
"range-find", val);
}
}),
if (!isinstance(find, RangeFind) || find.stale)
return this.rangeFind = null;
return find;
},
set rangeFind(val) {
overlay.setData(this.content.document,
"range-find", val);
}
};
},
init: function init() {
prefs.safeSet("accessibility.typeaheadfind.autostart", false);
@@ -754,7 +756,9 @@ var RangeFind = Class("RangeFind", {
return util.docShell(this.window);
}),
intersects: function (range) RangeFind.intersects(this.range, range),
intersects: function (range) {
return RangeFind.intersects(this.range, range);
},
save: function save() {
this.scroll = Point(this.window.pageXOffset, this.window.pageYOffset);
@@ -802,7 +806,10 @@ var RangeFind = Class("RangeFind", {
return false;
}
},
containsNode: function containsNode(range, n, quiet) n.ownerDocument && this.contains(range, RangeFind.nodeRange(n), quiet),
containsNode: function containsNode(range, n, quiet) {
return n.ownerDocument &&
this.contains(range, RangeFind.nodeRange(n), quiet);
},
intersects: function intersects(range, r) {
try {
return r.compareBoundaryPoints(range.START_TO_END, range) >= 0 &&

View File

@@ -43,11 +43,13 @@ var HelpBuilder = Class("HelpBuilder", {
}
},
toJSON: function toJSON() ({
files: this.files,
overlays: this.overlays,
tags: this.tags
}),
toJSON: function toJSON() {
return {
files: this.files,
overlays: this.overlays,
tags: this.tags
};
},
// Find the tags in the document.
addTags: function addTags(file, doc) {
@@ -222,189 +224,196 @@ var Help = Module("Help", {
get overlays() { return this.data.overlays; },
get tags() { return this.data.tags; },
Local: function Local(dactyl, modules, window) ({
init: function init() {
dactyl.commands["dactyl.help"] = event => {
let elem = event.originalTarget;
modules.help.help(elem.getAttribute("tag") || elem.textContent);
};
},
Local: function Local(dactyl, modules, window) {
return {
init: function init() {
dactyl.commands["dactyl.help"] = event => {
let elem = event.originalTarget;
modules.help.help(elem.getAttribute("tag") || elem.textContent);
};
},
/**
* Returns the URL of the specified help *topic* if it exists.
*
* @param {string} topic The help topic to look up.
* @param {boolean} consolidated Whether to search the consolidated help page.
* @returns {string}
*/
findHelp: function (topic, consolidated) {
if (!consolidated && hasOwnProperty(help.files, topic))
return topic;
let items = modules.completion._runCompleter("help", topic, null, !!consolidated).items;
let partialMatch = null;
/**
* Returns the URL of the specified help *topic* if it exists.
*
* @param {string} topic The help topic to look up.
* @param {boolean} consolidated Whether to search the consolidated help page.
* @returns {string}
*/
findHelp: function (topic, consolidated) {
if (!consolidated && hasOwnProperty(help.files, topic))
return topic;
let items = modules.completion._runCompleter("help", topic, null, !!consolidated).items;
let partialMatch = null;
function format(item) {
return item.description + "#" + encodeURIComponent(item.text);
}
for (let item of items) {
if (item.text == topic)
return format(item);
else if (!partialMatch && topic)
partialMatch = item;
}
if (partialMatch)
return format(partialMatch);
return null;
},
/**
* Opens the help page containing the specified *topic* if it exists.
*
* @param {string} topic The help topic to open.
* @param {boolean} consolidated Whether to use the consolidated help page.
*/
help: function (topic, consolidated) {
dactyl.initHelp();
if (!topic) {
let helpFile = consolidated ? "all" : modules.options["helpfile"];
if (hasOwnProperty(help.files, helpFile))
dactyl.open("dactyl://help/" + helpFile, { from: "help" });
else
dactyl.echomsg(_("help.noFile", JSON.stringify(helpFile)));
return;
}
let page = this.findHelp(topic, consolidated);
dactyl.assert(page != null, _("help.noTopic", topic));
dactyl.open("dactyl://help/" + page, { from: "help" });
},
exportHelp: function (path) {
const FILE = io.File(path);
const PATH = FILE.leafName.replace(/\..*/, "") + "/";
const TIME = Date.now();
if (!FILE.exists() && (/\/$/.test(path) && !/\./.test(FILE.leafName)))
FILE.create(FILE.DIRECTORY_TYPE, 0o755);
dactyl.initHelp();
if (FILE.isDirectory()) {
var addDataEntry = function addDataEntry(file, data) FILE.child(file).write(data);
var addURIEntry = function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText);
}
else {
var zip = services.ZipWriter(FILE.file, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
addURIEntry = function addURIEntry(file, uri)
zip.addEntryChannel(PATH + file, TIME, 9,
services.io.newChannel(uri, null, null), false);
addDataEntry = function addDataEntry(file, data) // Unideal to an extreme.
addURIEntry(file, "data:text/plain;charset=UTF-8," + encodeURI(data));
}
let empty = new RealSet("area base basefont br col frame hr img input isindex link meta param"
.split(" "));
function fix(node) {
switch (node.nodeType) {
case Ci.nsIDOMNode.ELEMENT_NODE:
if (isinstance(node, [Ci.nsIDOMHTMLBaseElement]))
return;
data.push("<", node.localName);
if (node instanceof Ci.nsIDOMHTMLHtmlElement)
data.push(" xmlns=" + JSON.stringify(XHTML),
" xmlns:dactyl=" + JSON.stringify(NS));
for (let { name, value } of node.attributes) {
if (name == "dactyl:highlight") {
styles.add(value);
name = "class";
value = "hl-" + value;
}
if (name == "href") {
value = node.href || value;
if (value.startsWith("dactyl://help-tag/")) {
try {
let uri = services.io.newChannel(value, null, null).originalURI;
value = uri.spec == value ? "javascript:;" : uri.path.substr(1);
}
catch (e) {
util.dump("Magical tag thingy failure for: " + value);
dactyl.reportError(e);
}
}
if (!/^#|[\/](#|$)|^[a-z]+:/.test(value))
value = value.replace(/(#|$)/, ".xhtml$1");
}
if (name == "src" && value.indexOf(":") > 0) {
chromeFiles[value] = value.replace(/.*\//, "");
value = value.replace(/.*\//, "");
}
data.push(" ", name, '="', DOM.escapeHTML(value), '"');
}
if (empty.has(node.localName))
data.push(" />");
else {
data.push(">");
if (node instanceof Ci.nsIDOMHTMLHeadElement)
data.push('<link rel="stylesheet" type="text/css" href="help.css"/>');
Array.map(node.childNodes, fix);
data.push("</", node.localName, ">");
}
break;
case Ci.nsIDOMNode.TEXT_NODE:
data.push(DOM.escapeHTML(node.textContent, true));
function format(item) {
return item.description + "#" + encodeURIComponent(item.text);
}
for (let item of items) {
if (item.text == topic)
return format(item);
else if (!partialMatch && topic)
partialMatch = item;
}
if (partialMatch)
return format(partialMatch);
return null;
},
/**
* Opens the help page containing the specified *topic* if it exists.
*
* @param {string} topic The help topic to open.
* @param {boolean} consolidated Whether to use the consolidated help page.
*/
help: function (topic, consolidated) {
dactyl.initHelp();
if (!topic) {
let helpFile = consolidated ? "all" : modules.options["helpfile"];
if (hasOwnProperty(help.files, helpFile))
dactyl.open("dactyl://help/" + helpFile, { from: "help" });
else
dactyl.echomsg(_("help.noFile", JSON.stringify(helpFile)));
return;
}
let page = this.findHelp(topic, consolidated);
dactyl.assert(page != null, _("help.noTopic", topic));
dactyl.open("dactyl://help/" + page, { from: "help" });
},
exportHelp: function (path) {
const FILE = io.File(path);
const PATH = FILE.leafName.replace(/\..*/, "") + "/";
const TIME = Date.now();
if (!FILE.exists() && (/\/$/.test(path) && !/\./.test(FILE.leafName)))
FILE.create(FILE.DIRECTORY_TYPE, 0o755);
dactyl.initHelp();
if (FILE.isDirectory()) {
var addDataEntry = function addDataEntry(file, data) {
FILE.child(file).write(data);
};
var addURIEntry = function addURIEntry(file, uri) {
addDataEntry(file, util.httpGet(uri).responseText);
};
}
else {
var zip = services.ZipWriter(FILE.file, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
addURIEntry = function addURIEntry(file, uri) {
zip.addEntryChannel(PATH + file, TIME, 9,
services.io.newChannel(uri, null, null), false);
};
addDataEntry = function addDataEntry(file, data) {// Unideal to an extreme.
addURIEntry(file, "data:text/plain;charset=UTF-8," + encodeURI(data));
};
}
let empty = new RealSet("area base basefont br col frame hr img input isindex link meta param"
.split(" "));
function fix(node) {
switch (node.nodeType) {
case Ci.nsIDOMNode.ELEMENT_NODE:
if (isinstance(node, [Ci.nsIDOMHTMLBaseElement]))
return;
data.push("<", node.localName);
if (node instanceof Ci.nsIDOMHTMLHtmlElement)
data.push(" xmlns=" + JSON.stringify(XHTML),
" xmlns:dactyl=" + JSON.stringify(NS));
for (let { name, value } of node.attributes) {
if (name == "dactyl:highlight") {
styles.add(value);
name = "class";
value = "hl-" + value;
}
if (name == "href") {
value = node.href || value;
if (value.startsWith("dactyl://help-tag/")) {
try {
let uri = services.io.newChannel(value, null, null).originalURI;
value = uri.spec == value ? "javascript:;" : uri.path.substr(1);
}
catch (e) {
util.dump("Magical tag thingy failure for: " + value);
dactyl.reportError(e);
}
}
if (!/^#|[\/](#|$)|^[a-z]+:/.test(value))
value = value.replace(/(#|$)/, ".xhtml$1");
}
if (name == "src" && value.indexOf(":") > 0) {
chromeFiles[value] = value.replace(/.*\//, "");
value = value.replace(/.*\//, "");
}
data.push(" ", name, '="', DOM.escapeHTML(value), '"');
}
if (empty.has(node.localName))
data.push(" />");
else {
data.push(">");
if (node instanceof Ci.nsIDOMHTMLHeadElement)
data.push('<link rel="stylesheet" type="text/css" href="help.css"/>');
Array.map(node.childNodes, fix);
data.push("</", node.localName, ">");
}
break;
case Ci.nsIDOMNode.TEXT_NODE:
data.push(DOM.escapeHTML(node.textContent, true));
}
}
let { buffer, content, events } = modules;
let chromeFiles = {};
let styles = new RealSet;
for (let [file, ] of iter(help.files)) {
let url = "dactyl://help/" + file;
dactyl.open(url);
util.waitFor(() => (content.location.href == url && buffer.loaded &&
content.document.documentElement instanceof Ci.nsIDOMHTMLHtmlElement),
15000);
events.waitForPageLoad();
var data = [
'<?xml version="1.0" encoding="UTF-8"?>\n',
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n',
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
];
fix(content.document.documentElement);
addDataEntry(file + ".xhtml", data.join(""));
}
data = [h for (h of highlight)
if (styles.has(h.class) || /^Help/.test(h.class))]
.map(h => h.selector
.replace(/^\[.*?=(.*?)\]/, ".hl-$1")
.replace(/html\|/g, "") + "\t" + "{" + h.cssText + "}")
.join("\n");
addDataEntry("help.css", data.replace(/chrome:[^ ")]+\//g, ""));
addDataEntry("tag-map.json", JSON.stringify(help.tags));
let m, re = /(chrome:[^ ");]+\/)([^ ");]+)/g;
while ((m = re.exec(data)))
chromeFiles[m[0]] = m[2];
for (let [uri, leaf] of iter(chromeFiles))
addURIEntry(leaf, uri);
if (zip)
zip.close();
}
let { buffer, content, events } = modules;
let chromeFiles = {};
let styles = new RealSet;
for (let [file, ] of iter(help.files)) {
let url = "dactyl://help/" + file;
dactyl.open(url);
util.waitFor(() => (content.location.href == url && buffer.loaded &&
content.document.documentElement instanceof Ci.nsIDOMHTMLHtmlElement),
15000);
events.waitForPageLoad();
var data = [
'<?xml version="1.0" encoding="UTF-8"?>\n',
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n',
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
];
fix(content.document.documentElement);
addDataEntry(file + ".xhtml", data.join(""));
}
data = [h for (h of highlight)
if (styles.has(h.class) || /^Help/.test(h.class))]
.map(h => h.selector
.replace(/^\[.*?=(.*?)\]/, ".hl-$1")
.replace(/html\|/g, "") + "\t" + "{" + h.cssText + "}")
.join("\n");
addDataEntry("help.css", data.replace(/chrome:[^ ")]+\//g, ""));
addDataEntry("tag-map.json", JSON.stringify(help.tags));
let m, re = /(chrome:[^ ");]+\/)([^ ");]+)/g;
while ((m = re.exec(data)))
chromeFiles[m[0]] = m[2];
for (let [uri, leaf] of iter(chromeFiles))
addURIEntry(leaf, uri);
if (zip)
zip.close();
}
})
};
}
}, {
}, {
commands: function initCommands(dactyl, modules, window) {
@@ -445,7 +454,10 @@ var Help = Module("Help", {
context.anchored = false;
context.completions = help.tags;
if (consolidated)
context.keys = { text: 0, description: function () "all" };
context.keys = {
text: 0,
description: function () { return "all"; }
};
};
},
javascript: function initJavascript(dactyl, modules, window) {

View File

@@ -97,9 +97,11 @@ update(Highlight.prototype, {
get cssText() { return this.inheritedCSS + this.value; },
toString: function () "Highlight(" + this.class + ")\n\t" +
[k + ": " + JSON.stringify(String(v))
for ([k, v] of this)].join("\n\t")
toString: function () {
return "Highlight(" + this.class + ")\n\t" +
[k + ": " + JSON.stringify(String(v))
for ([k, v] of this)].join("\n\t");
}
});
/**
@@ -113,10 +115,15 @@ var Highlights = Module("Highlight", {
this.loaded = {};
},
keys: function keys() Object.keys(this.highlight).sort(),
keys: function keys() {
return Object.keys(this.highlight).sort();
},
"@@iterator": function () values(this.highlight).sort((a, b) => String.localeCompare(a.class, b.class))
.iterValues(),
"@@iterator": function () {
return values(this.highlight)
.sort((a, b) => String.localeCompare(a.class, b.class))
.iterValues();
},
_create: function _create(agent, args) {
let obj = Highlight.apply(Highlight, args);
@@ -165,7 +172,9 @@ var Highlights = Module("Highlight", {
return obj;
},
get: function get(k) this.highlight[k],
get: function get(k) {
return this.highlight[k];
},
set: function set(key, newStyle, force, append, extend) {
let highlight = this.highlight[key] || this._create(false, [key]);
@@ -234,13 +243,13 @@ var Highlights = Module("Highlight", {
*
* @param {string} class
*/
selector: function selector(class_)
class_.replace(/(^|[>\s])([A-Z][\w-]+)\b/g,
(m, n1, hl) => {
if (this.highlight[hl] && this.highlight[hl].class != class_)
return n1 + this.highlight[hl].selector;
return n1 + "[dactyl|highlight~=" + hl + "]";
}),
selector: function selector(class_) {
return class_.replace(/(^|[>\s])([A-Z][\w-]+)\b/g, (m, n1, hl) => {
if (this.highlight[hl] && this.highlight[hl].class != class_)
return n1 + this.highlight[hl].selector;
return n1 + "[dactyl|highlight~=" + hl + "]";
});
},
groupRegexp: util.regexp(literal(function () /*
^

View File

@@ -300,8 +300,9 @@ var IO = Module("io", {
File: Class.Memoize(function () {
let io = this;
return Class("File", File, {
init: function init(path, checkCWD=true)
init.supercall(this, path, checkCWD && io.cwd)
init: function init(path, checkCWD=true) {
return init.supercall(this, path, checkCWD && io.cwd);
}
});
}),
@@ -530,11 +531,13 @@ var IO = Module("io", {
function result(status, output) {
return {
__noSuchMethod__: function (meth, args) apply(this.output, meth, args),
valueOf: function () this.output,
__noSuchMethod__: function (meth, args) {
return apply(this.output, meth, args);
},
valueOf: function () { return this.output; },
output: output.replace(/^(.*)\n$/, "$1"),
returnValue: status,
toString: function () this.output
toString: function () { return this.output; }
};
}

View File

@@ -34,14 +34,16 @@ var JavaScript = Module("javascript", {
this._nullSandbox = Cu.Sandbox("about:blank");
},
Local: function (dactyl, modules, window) ({
init: function init() {
this.modules = modules;
this.window = window;
Local: function (dactyl, modules, window) {
return {
init: function init() {
this.modules = modules;
this.window = window;
init.supercall(this);
}
}),
init.supercall(this);
}
};
},
globals: Class.Memoize(function () {
return [
@@ -57,8 +59,10 @@ var JavaScript = Module("javascript", {
lazyInit: true,
newContext: function () this.modules.newContext(this.modules.userContext, false,
"Dactyl JS Temp Context"),
newContext: function () {
return this.modules.newContext(this.modules.userContext, false,
"Dactyl JS Temp Context");
},
completers: Class.Memoize(() => Object.create(JavaScript.completers)),
@@ -354,8 +358,9 @@ var JavaScript = Module("javascript", {
}
if (!compl) {
base.process[1] = function highlight(item, v)
template.highlight(typeof v == "xml" ? new String(v.toXMLString()) : v, true, 200);
base.process[1] = function highlight(item, v) {
return template.highlight(typeof v == "xml" ? new String(v.toXMLString()) : v, true, 200);
};
// Sort in a logical fashion for object keys:
// Numbers are sorted as numbers, rather than strings, and appear first.
@@ -376,7 +381,9 @@ var JavaScript = Module("javascript", {
base.keys = {
text: prefix ? text => text.substr(prefix.length)
: text => text,
description: function (item) self.getKey(this.obj, item),
description: function (item) {
return self.getKey(this.obj, item);
},
key: function (item) {
if (!isNaN(key))
return parseInt(key);
@@ -769,7 +776,9 @@ var JavaScript = Module("javascript", {
return this.rootNode;
}),
__noSuchMethod__: function (meth, args) apply(Buffer, meth, [this.rootNode].concat(args))
__noSuchMethod__: function (meth, args) {
return apply(Buffer, meth, [this.rootNode].concat(args));
}
});
modules.CommandREPLMode = Class("CommandREPLMode", modules.CommandMode, {

View File

@@ -26,7 +26,9 @@ var ModuleBase = Class("ModuleBase", {
*/
requires: [],
toString: function () "[module " + this.constructor.className + "]"
toString: function () {
return "[module " + this.constructor.className + "]";
}
});
var _id = 0;

View File

@@ -29,9 +29,9 @@ var Messages = Module("messages", {
}
return self.get(message);
}),
valueOf: function valueOf() this.message,
toString: function toString() this.message,
toJSON: function toJSON() this.message
valueOf: function valueOf() { return this.message; },
toString: function toString() { return this.message; },
toJSON: function toJSON() { return this.message; }
});
},
@@ -200,7 +200,7 @@ var Messages = Module("messages", {
return Class.replaceProperty(this, prop, value);
},
set: function set(val) this[_prop] = val
set: function set(val) { this[_prop] = val; }
};
}
this.default = prop;

View File

@@ -107,9 +107,13 @@ var Option = Class("Option", {
* @param {value} value The option value.
* @returns {value|[string]}
*/
parse: function parse(value) Option.dequote(value),
parse: function parse(value) {
return Option.dequote(value);
},
parseKey: function parseKey(value) value,
parseKey: function parseKey(value) {
return value;
},
/**
* Returns *values* packed in the appropriate format for the option type.
@@ -117,7 +121,9 @@ var Option = Class("Option", {
* @param {value|[string]} values The option value.
* @returns {value}
*/
stringify: function stringify(vals) Commands.quote(vals),
stringify: function stringify(vals) {
return Commands.quote(vals);
},
/**
* Returns the option's value as an array of parsed values if the option
@@ -203,7 +209,9 @@ var Option = Class("Option", {
get stringDefaultValue() { return this.stringify(this.defaultValue); },
set stringDefaultValue(val) { this.defaultValue = this.parse(val); },
getKey: function getKey(key) undefined,
getKey: function getKey(key) {
return undefined;
},
/**
* Returns whether the option value contains one or more of the specified
@@ -211,7 +219,9 @@ var Option = Class("Option", {
*
* @returns {boolean}
*/
has: function has() Array.some(arguments, val => this.value.indexOf(val) >= 0),
has: function has() {
return Array.some(arguments, val => this.value.indexOf(val) >= 0);
},
/**
* Returns whether this option is identified by *name*.
@@ -219,16 +229,22 @@ var Option = Class("Option", {
* @param {string} name
* @returns {boolean}
*/
hasName: function hasName(name) this.names.indexOf(name) >= 0,
hasName: function hasName(name) {
return this.names.indexOf(name) >= 0;
},
/**
* Returns whether the specified *values* are valid for this option.
* @see Option#validator
*/
isValidValue: function isValidValue(values) this.validator(values),
isValidValue: function isValidValue(values) {
return this.validator(values);
},
invalidArgument: function invalidArgument(arg, op) _("error.invalidArgument",
this.name + (op || "").replace(/=?$/, "=") + arg),
invalidArgument: function invalidArgument(arg, op) {
return _("error.invalidArgument",
this.name + (op || "").replace(/=?$/, "=") + arg);
},
/**
* Resets the option to its default value.
@@ -325,8 +341,9 @@ var Option = Class("Option", {
* @property {function(host, values)} A function which should strip
* references to a given domain from the given values.
*/
filterDomain: function filterDomain(host, values)
Array.filter(values, val => !this.domains([val]).some(val => util.isSubdomain(val, host))),
filterDomain: function filterDomain(host, values) {
return Array.filter(values, val => !this.domains([val]).some(val => util.isSubdomain(val, host)));
},
/**
* @property {value} The option's default value. This value will be used
@@ -388,7 +405,9 @@ var Option = Class("Option", {
*/
setter: null,
testValues: function testValues(values, validator) validator(values),
testValues: function testValues(values, validator) {
return validator(values);
},
/**
* @property {function} The function called to validate the option's value
@@ -445,7 +464,9 @@ var Option = Class("Option", {
SCOPE_BOTH: 3,
has: {
toggleAll: function toggleAll() toggleAll.supercall(this, "all") ^ !!toggleAll.superapply(this, arguments)
toggleAll: function toggleAll() {
return toggleAll.supercall(this, "all") ^ !!toggleAll.superapply(this, arguments);
}
},
parseRegexp: function parseRegexp(value, result, flags) {
@@ -467,8 +488,10 @@ var Option = Class("Option", {
return re;
},
unparseRegexp: function unparseRegexp(re, quoted) re.bang + Option.quote(util.regexp.getSource(re), /^!|:/) +
(typeof re.result === "boolean" ? "" : ":" + (quoted ? re.result : Option.quote(re.result, /:/))),
unparseRegexp: function unparseRegexp(re, quoted) {
return re.bang + Option.quote(util.regexp.getSource(re), /^!|:/) +
(typeof re.result === "boolean" ? "" : ":" + (quoted ? re.result : Option.quote(re.result, /:/)));
},
parseSite: function parseSite(pattern, result, rest) {
if (isArray(rest)) // Called by Array.map
@@ -484,13 +507,17 @@ var Option = Class("Option", {
bang: bang,
filter: filter,
result: result !== undefined ? result : !bang,
toString: function toString() this.bang + Option.quote(this.filter, /:/) +
(typeof this.result === "boolean" ? "" : ":" + quote(this.result))
toString: function toString() {
return this.bang + Option.quote(this.filter, /:/) +
(typeof this.result === "boolean" ? "" : ":" + quote(this.result));
}
});
},
getKey: {
stringlist: function stringlist(k) this.value.indexOf(k) >= 0,
stringlist: function stringlist(k) {
return this.value.indexOf(k) >= 0;
},
get charlist() { return this.stringlist; },
regexplist: function regexplist(k, default_=null) {
@@ -505,40 +532,58 @@ var Option = Class("Option", {
},
domains: {
sitelist: function (vals) Ary.compact(vals.map(site => util.getHost(site.filter))),
sitelist: function (vals) {
return Ary.compact(vals.map(site => util.getHost(site.filter)));
},
get sitemap() { return this.sitelist; }
},
stringify: {
charlist: function (vals) Commands.quote(vals.join("")),
charlist: function (vals) {
return Commands.quote(vals.join(""));
},
stringlist: function (vals) vals.map(Option.quote).join(","),
stringlist: function (vals) {
return vals.map(Option.quote).join(",");
},
stringmap: function (vals) [Option.quote(k, /:/) + ":" + Option.quote(v, /:/) for ([k, v] of iter(vals))].join(","),
stringmap: function (vals) {
return [Option.quote(k, /:/) + ":" + Option.quote(v, /:/) for ([k, v] of iter(vals))].join(",");
},
regexplist: function (vals) vals.join(","),
regexplist: function (vals) { return vals.join(","); },
get regexpmap() { return this.regexplist; },
get sitelist() { return this.regexplist; },
get sitemap() { return this.regexplist; }
},
parse: {
number: function (value) {
number: function (value) {
let val = Option.dequote(value);
return (Option.validIf(Number(val) % 1 == 0,
_("option.intRequired")) &&
parseInt(val));
},
boolean: function boolean(value) Option.dequote(value) == "true" || value == true ? true : false,
boolean: function boolean(value) {
return Option.dequote(value) == "true" || value == true ? true : false;
},
charlist: function charlist(value) Array.slice(Option.dequote(value)),
charlist: function charlist(value) {
return Array.slice(Option.dequote(value));
},
stringlist: function stringlist(value) (value === "") ? [] : Option.splitList(value),
stringlist: function stringlist(value) {
return (value === "") ? [] : Option.splitList(value);
},
regexplist: function regexplist(value) (value === "") ? [] :
Option.splitList(value, true)
.map(re => Option.parseRegexp(re, undefined, this.regexpFlags)),
regexplist: function regexplist(value) {
if (value === "")
return [];
else
return Option.splitList(value, true)
.map(re => Option.parseRegexp(re, undefined, this.regexpFlags));
},
sitelist: function sitelist(value) {
if (value === "")
@@ -548,15 +593,20 @@ var Option = Class("Option", {
return value.map(Option.parseSite, this);
},
stringmap: function stringmap(value) Ary.toObject(
Option.splitList(value, true).map(function (v) {
stringmap: function stringmap(value) {
return Ary.toObject(Option.splitList(value, true).map(v => {
let [count, key, quote] = Commands.parseArg(v, /:/);
return [key, Option.dequote(v.substr(count + 1))];
})),
}));
},
regexpmap: function regexpmap(value) Option.parse.list.call(this, value, Option.parseRegexp),
regexpmap: function regexpmap(value) {
return Option.parse.list.call(this, value, Option.parseRegexp);
},
sitemap: function sitemap(value) Option.parse.list.call(this, value, Option.parseSite),
sitemap: function sitemap(value) {
return Option.parse.list.call(this, value, Option.parseSite);
},
list: function list(value, parse) {
let prev = null;
@@ -580,14 +630,22 @@ var Option = Class("Option", {
parseKey: {
number: Number,
boolean: function boolean(value) value == "true" || value == true ? true : false
boolean: function boolean(value) {
return value == "true" || value == true ? true : false;
}
},
testValues: {
regexpmap: function regexpmap(vals, validator) vals.every(re => validator(re.result)),
regexpmap: function regexpmap(vals, validator) {
return vals.every(re => validator(re.result));
},
get sitemap() { return this.regexpmap; },
stringlist: function stringlist(vals, validator) vals.every(validator, this),
stringmap: function stringmap(vals, validator) values(vals).every(validator, this)
stringlist: function stringlist(vals, validator) {
return vals.every(validator, this);
},
stringmap: function stringmap(vals, validator) {
return values(vals).every(validator, this);
}
},
dequote: function dequote(value) {
@@ -613,10 +671,13 @@ var Option = Class("Option", {
return res;
},
quote: function quote(str, re) isArray(str) ? str.map(s => quote(s, re)).join(",") :
Commands.quoteArg[/[\s|"'\\,]|^$/.test(str) || re && re.test && re.test(str)
? (/[\b\f\n\r\t]/.test(str) ? '"' : "'")
: ""](str, re),
// XXX
quote: function quote(str, re) {
return isArray(str) ? str.map(s => quote(s, re)).join(",") :
Commands.quoteArg[/[\s|"'\\,]|^$/.test(str) || re && re.test && re.test(str)
? (/[\b\f\n\r\t]/.test(str) ? '"' : "'")
: ""](str, re);
},
ops: {
boolean: function boolean(operator, values, scope, invert) {
@@ -1002,8 +1063,9 @@ var Options = Module("options", {
},
/** @property {Iterator(Option)} @private */
"@@iterator": function __iterator__()
values(this._options.sort((a, b) => String.localeCompare(a.name, b.name))),
"@@iterator": function __iterator__() {
return values(this._options.sort((a, b) => String.localeCompare(a.name, b.name)));
},
allPrefs: deprecated("prefs.getNames", function allPrefs() apply(prefs, "getNames", arguments)),
getPref: deprecated("prefs.get", function getPref() apply(prefs, "get", arguments)),
@@ -1130,16 +1192,18 @@ var Options = Module("options", {
name: ["listo[ptions]", "lo"],
description: "List all options along with their short descriptions",
index: "option",
iterate: function (args) options,
iterate: function (args) { return options; },
format: {
description: function (opt) [
description: function (opt) {
return [
opt.scope == Option.SCOPE_LOCAL
? ["span", { highlight: "URLExtra" },
"(" + _("option.bufferLocal") + ")"]
: "",
template.linkifyHelp(opt.description)
],
help: function (opt) "'" + opt.name + "'"
];
},
help: function (opt) { return "'" + opt.name + "'"; }
}
});
@@ -1439,24 +1503,28 @@ var Options = Module("options", {
update({
bang: true,
completer: setCompleter,
domains: function domains(args) Ary.flatten(args.map(function (spec) {
try {
let opt = modules.options.parseOpt(spec);
if (opt.option && opt.option.domains)
return opt.option.domains(opt.values);
}
catch (e) {
util.reportError(e);
}
return [];
})),
domains: function domains(args) {
return Ary.flatten(args.map(function (spec) {
try {
let opt = modules.options.parseOpt(spec);
if (opt.option && opt.option.domains)
return opt.option.domains(opt.values);
}
catch (e) {
util.reportError(e);
}
return [];
}));
},
keepQuotes: true,
privateData: function privateData(args) args.some(function (spec) {
let opt = modules.options.parseOpt(spec);
return opt.option && opt.option.privateData &&
(!callable(opt.option.privateData) ||
opt.option.privateData(opt.values));
})
privateData: function privateData(args) {
return args.some(function (spec) {
let opt = modules.options.parseOpt(spec);
return opt.option && opt.option.privateData &&
(!callable(opt.option.privateData) ||
opt.option.privateData(opt.values));
});
}
}, params.extra || {}));
});

View File

@@ -13,8 +13,9 @@ defineModule("overlay", {
lazyRequire("highlight", ["highlight"]);
var getAttr = function getAttr(elem, ns, name)
elem.hasAttributeNS(ns, name) ? elem.getAttributeNS(ns, name) : null;
var getAttr = function getAttr(elem, ns, name) {
return elem.hasAttributeNS(ns, name) ? elem.getAttributeNS(ns, name) : null;
};
var setAttr = function setAttr(elem, ns, name, val) {
if (val == null)
elem.removeAttributeNS(ns, name);
@@ -34,7 +35,7 @@ var Overlay = Class("Overlay", {
get win() { return this.window; },
$: function $(sel, node) DOM(sel, node || this.doc),
$: function $(sel, node) { return DOM(sel, node || this.doc); },
cleanup: function cleanup(window, reason) {
for (let fn of this.cleanups)

View File

@@ -80,7 +80,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @param {string} branch The sub-branch to branch to.
* @returns {Prefs}
*/
Branch: function Branch(branch) Prefs(this.root + branch),
Branch: function Branch(branch) { return Prefs(this.root + branch); },
/**
* Clears the entire branch.
@@ -143,21 +143,27 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @param {string} branch The sub-branch for which to return preferences.
* @optional
*/
getNames: function getNames(branch) this.branch.getChildList(branch || "", { value: 0 }),
getNames: function getNames(branch) {
return this.branch.getChildList(branch || "", { value: 0 });
},
/**
* Returns true if the given preference exists in this branch.
*
* @param {string} name The name of the preference to check.
*/
has: function has(name) this.branch.getPrefType(name) !== 0,
has: function has(name) {
return this.branch.getPrefType(name) !== 0;
},
/**
* Returns true if the given preference is set to its default value.
*
* @param {string} name The name of the preference to check.
*/
isDefault: function isDefault(name) !this.branch.prefHasUserValue(name),
isDefault: function isDefault(name) {
return !this.branch.prefHasUserValue(name);
},
_checkSafe: function _checkSafe(name, message, value) {
let curval = this.get(name, null);
@@ -382,7 +388,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
if (!this._observers[pref])
this._observers[pref] = [];
this._observers[pref].push(!strong ? util.weakReference(callback)
: { get: function () callback });
: { get: function () { return callback; } });
},
/**
@@ -429,8 +435,10 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
modules.completion.preference = function preference(context) {
context.anchored = false;
context.title = [config.host + " Preference", "Value"];
context.keys = { text: function (item) item,
description: function (item) prefs.get(item) };
context.keys = {
text: function (item) { return item; },
description: function (item) { return prefs.get(item); }
};
context.completions = prefs.getNames();
};
},

View File

@@ -86,7 +86,9 @@ function ProtocolBase() {
this.pages = {};
this.providers = {
"content": function (uri, path) this.pages[path] || this.contentBase + path,
"content": function (uri, path) {
return this.pages[path] || this.contentBase + path;
},
"data": function (uri) {
var channel = services.io.newChannel(uri.path.replace(/^\/(.*)(?:#.*)?/, "data:$1"),
@@ -116,7 +118,7 @@ ProtocolBase.prototype = {
},
defaultPort: -1,
allowPort: function (port, scheme) false,
allowPort: function (port, scheme) { return false; },
protocolFlags: 0
| Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE
| Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE,

View File

@@ -52,8 +52,8 @@ var Item = Class("SanitizeItem", {
},
// Hack for completion:
"0": Class.Property({ get: function () this.name }),
"1": Class.Property({ get: function () this.description }),
"0": Class.Property({ get: function () { return this.name; } }),
"1": Class.Property({ get: function () { return this.description; } }),
description: Messages.Localized(""),
@@ -66,8 +66,10 @@ var Item = Class("SanitizeItem", {
get cpd() { return prefs.get(this.cpdPref); },
get shutdown() { return prefs.get(this.shutdownPref); },
shouldSanitize: function (shutdown) (!shutdown || this.builtin || this.persistent) &&
prefs.get(shutdown ? this.shutdownPref : this.pref)
shouldSanitize: function (shutdown) {
return (!shutdown || this.builtin || this.persistent) &&
prefs.get(shutdown ? this.shutdownPref : this.pref);
}
}, {
PREFIX: config.prefs.branch.root,
BRANCH: "privacy.cpd.",
@@ -89,7 +91,10 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
this.itemMap = {};
this.addItem("all", { description: "Sanitize all items", shouldSanitize: function () false });
this.addItem("all", {
description: "Sanitize all items",
shouldSanitize: function () { return false; }
});
// Builtin items
this.addItem("cache", { builtin: true, description: "Cache" });
this.addItem("downloads", { builtin: true, description: "Download history" });
@@ -344,8 +349,8 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
prefs.set("privacy.sanitize.sanitizeOnShutdown", Boolean(val));
},
sanitize: function sanitize(items, range)
this.withSavedValues(["sanitizing"], function () {
sanitize: function sanitize(items, range) {
return this.withSavedValues(["sanitizing"], function () {
this.sanitizing = true;
let errors = this.sanitizeItems(items, range, null);
@@ -366,10 +371,11 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
}
}
return errors;
}),
});
},
sanitizeItems: function sanitizeItems(items, range, host, key)
this.withSavedValues(["sanitizing"], function () {
sanitizeItems: function sanitizeItems(items, range, host, key) {
return this.withSavedValues(["sanitizing"], function () {
this.sanitizing = true;
if (items == null)
items = Object.keys(this.itemMap);
@@ -387,7 +393,8 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
util.reportError(e);
}
return errors;
})
});
}
}, {
PERMS: {
unset: 0,
@@ -415,8 +422,12 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
offlineapps: "offlineApps",
sitesettings: "siteSettings"
},
argToPref: function (arg) Sanitizer.argPrefMap[arg] || arg,
prefToArg: function (pref) pref.replace(/.*\./, "").toLowerCase(),
argToPref: function (arg) {
return Sanitizer.argPrefMap[arg] || arg;
},
prefToArg: function (pref) {
return pref.replace(/.*\./, "").toLowerCase();
},
iterCookies: function* iterCookies(host) {
for (let c of iter(services.cookies, Ci.nsICookie2))
@@ -664,10 +675,14 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
for (i of values(sanitizer.itemMap))
if (i.persistent || i.builtin)];
},
getter: function () !sanitizer.runAtShutdown ? [] : [
item.name for (item of values(sanitizer.itemMap))
if (item.shouldSanitize(true))
],
getter: function () {
if (!sanitizer.runAtShutdown)
return [];
else
return [item.name
for (item of values(sanitizer.itemMap))
if (item.shouldSanitize(true))];
},
setter: function (value) {
if (value.length === 0)
sanitizer.runAtShutdown = false;

View File

@@ -208,8 +208,11 @@ var Services = Module("Services", {
*
* @param {string} name The service's cache key.
*/
has: function has(name) hasOwnProperty(this.services, name) && this.services[name].class in Cc &&
this.services[name].interfaces.every(iface => iface in Ci)
has: function has(name) {
return hasOwnProperty(this.services, name) &&
this.services[name].class in Cc &&
this.services[name].interfaces.every(iface => iface in Ci);
}
});
endModule();

View File

@@ -139,7 +139,10 @@ var ArrayStore = Class("ArrayStore", StoreBase, {
this.fireEvent("change", null);
},
get: function get(index) index >= 0 ? this._object[index] : this._object[this._object.length + index]
get: function get(index) {
return index >= 0 ? this._object[index] :
this._object[this._object.length + index];
}
});
var ObjectStore = Class("ObjectStore", StoreBase, {
@@ -156,9 +159,13 @@ var ObjectStore = Class("ObjectStore", StoreBase, {
undefined;
},
has: function has(key) hasOwnProperty(this._object, key),
has: function has(key) {
return hasOwnProperty(this._object, key);
},
keys: function keys() Object.keys(this._object),
keys: function keys() {
return Object.keys(this._object);
},
remove: function remove(key) {
var res = this._object[key];
@@ -182,11 +189,13 @@ var ObjectStore = Class("ObjectStore", StoreBase, {
var sessionGlobal = Cu.import("resource://gre/modules/Services.jsm", {});
var Storage = Module("Storage", {
Local: function Local(dactyl, modules, window) ({
init: function init() {
this.privateMode = PrivateBrowsingUtils.isWindowPrivate(window);
}
}),
Local: function Local(dactyl, modules, window) {
return {
init: function init() {
this.privateMode = PrivateBrowsingUtils.isWindowPrivate(window);
}
};
},
alwaysReload: {},
@@ -381,7 +390,9 @@ var Storage = Module("Storage", {
}
}, {
Replacer: {
skipXpcom: function skipXpcom(key, val) val instanceof Ci.nsISupports ? null : val
skipXpcom: function skipXpcom(key, val) {
return val instanceof Ci.nsISupports ? null : val;
}
}
}, {
cleanup: function (dactyl, modules, window) {
@@ -616,31 +627,38 @@ var File = Class("File", {
},
// Wrapped native methods:
copyTo: function copyTo(dir, name)
this.file.copyTo(this.constructor(dir).file,
name),
copyTo: function copyTo(dir, name) {
return this.file.copyTo(this.constructor(dir).file,
name);
},
copyToFollowingLinks: function copyToFollowingLinks(dir, name)
this.file.copyToFollowingLinks(this.constructor(dir).file,
name),
copyToFollowingLinks: function copyToFollowingLinks(dir, name) {
return this.file.copyToFollowingLinks(this.constructor(dir).file,
name);
},
moveTo: function moveTo(dir, name)
this.file.moveTo(this.constructor(dir).file,
name),
moveTo: function moveTo(dir, name) {
return this.file.moveTo(this.constructor(dir).file,
name);
},
equals: function equals(file)
this.file.equals(this.constructor(file).file),
equals: function equals(file) {
return this.file.equals(this.constructor(file).file);
},
contains: function contains(dir, recur)
this.file.contains(this.constructor(dir).file,
recur),
contains: function contains(dir, recur) {
return this.file.contains(this.constructor(dir).file,
recur);
},
getRelativeDescriptor: function getRelativeDescriptor(file)
this.file.getRelativeDescriptor(this.constructor(file).file),
getRelativeDescriptor: function getRelativeDescriptor(file) {
return this.file.getRelativeDescriptor(this.constructor(file).file);
},
setRelativeDescriptor: function setRelativeDescriptor(file, path)
setRelativeDescriptor: function setRelativeDescriptor(file, path) {
this.file.setRelativeDescriptor(this.constructor(file).file,
path)
path);
}
}, {
/**
* @property {number} Open for reading only.
@@ -705,14 +723,16 @@ var File = Class("File", {
"g");
}),
DoesNotExist: function DoesNotExist(path, error) ({
__proto__: DoesNotExist.prototype,
path: path,
exists: function () false,
__noSuchMethod__: function () {
throw error || Error("Does not exist");
}
}),
DoesNotExist: function DoesNotExist(path, error) {
return {
__proto__: DoesNotExist.prototype,
path: path,
exists: function () { return false; },
__noSuchMethod__: function () {
throw error || Error("Does not exist");
}
};
},
defaultEncoding: "UTF-8",
@@ -757,7 +777,9 @@ var File = Class("File", {
return OS.Path.normalize(path.replace(/\//g, File.PATH_SEP));
},
expandPathList: function (list) list.map(this.expandPath),
expandPathList: function (list) {
return list.map(this.expandPath);
},
readURL: function readURL(url, encoding) {
let channel = services.io.newChannel(url, null, null);
@@ -808,7 +830,9 @@ var File = Class("File", {
}
},
replacePathSep: function replacePathSep(path) path.split("/").join(File.PATH_SEP),
replacePathSep: function replacePathSep(path) {
return path.split("/").join(File.PATH_SEP);
},
joinPaths: function joinPaths(head, tail, cwd) {
let path = this(head, cwd);
@@ -840,7 +864,7 @@ var File = Class("File", {
else
Object.defineProperty(File.prototype, prop, {
configurable: true,
get: function wrap_get() this.file[prop],
get: function wrap_get() { return this.file[prop]; },
set: function wrap_set(val) { this.file[prop] = val; }
});
}

View File

@@ -33,10 +33,11 @@ Sheet.liveProperty("agent");
Sheet.liveProperty("css");
Sheet.liveProperty("sites");
update(Sheet.prototype, {
formatSites: function (uris)
template.map(this.sites,
filter => ["span", { highlight: uris.some(Styles.matchFilter(filter)) ? "Filter" : "" }, filter],
","),
formatSites: function (uris) {
return template.map(this.sites,
filter => ["span", { highlight: uris.some(Styles.matchFilter(filter)) ? "Filter" : "" }, filter],
",");
},
remove: function () { this.hive.remove(this); },
@@ -119,7 +120,9 @@ var Hive = Class("Hive", {
});
},
"@@iterator": function () iter(this.sheets),
"@@iterator": function () {
return iter(this.sheets);
},
get sites() {
return Ary(this.sheets).map(s => s.sites)
@@ -259,9 +262,9 @@ var Hive = Class("Hive", {
* @author Kris Maglione <maglione.k@gmail.com>
*/
var Styles = Module("Styles", {
Local: function (dactyl, modules, window) ({
cleanup: function () {}
}),
Local: function (dactyl, modules, window) {
return { cleanup: function () {} };
},
init: function () {
this._id = 0;
@@ -298,7 +301,9 @@ var Styles = Module("Styles", {
return hive;
},
"@@iterator": function () iter(this.user.sheets.concat(this.system.sheets)),
"@@iterator": function () {
return iter(this.user.sheets.concat(this.system.sheets));
},
_proxy: function (name, args) {
let obj = this[args[0] ? "system" : "user"];
@@ -677,24 +682,30 @@ var Styles = Module("Styles", {
{
name: ["stylee[nable]", "stye[nable]"],
desc: "Enable a user style sheet",
action: function (sheet) sheet.enabled = true,
filter: function (sheet) !sheet.enabled
action: function (sheet) {
sheet.enabled = true;
},
filter: function (sheet) { return !sheet.enabled; }
},
{
name: ["styled[isable]", "styd[isable]"],
desc: "Disable a user style sheet",
action: function (sheet) sheet.enabled = false,
filter: function (sheet) sheet.enabled
action: function (sheet) {
sheet.enabled = false;
},
filter: function (sheet) { return sheet.enabled; }
},
{
name: ["stylet[oggle]", "styt[oggle]"],
desc: "Toggle a user style sheet",
action: function (sheet) sheet.enabled = !sheet.enabled
action: function (sheet) {
sheet.enabled = !sheet.enabled;
}
},
{
name: ["dels[tyle]"],
desc: "Remove a user style sheet",
action: function (sheet) sheet.remove()
action: function (sheet) { sheet.remove(); }
}
].forEach(function (cmd) {
commands.add(cmd.name, cmd.desc,
@@ -752,8 +763,10 @@ var Styles = Module("Styles", {
const names = Array.slice(DOM(["div"], window.document).style);
modules.completion.css = context => {
context.title = ["CSS Property"];
context.keys = { text: function (p) p + ":",
description: function () "" };
context.keys = {
text: function (p) { return p + ":"; },
description: function () { return ""; }
};
for (let match of Styles.propertyIter(context.filter, true))
var lastMatch = match;
@@ -767,10 +780,10 @@ var Styles = Module("Styles", {
javascript: function initJavascript(dactyl, modules, window) {
modules.JavaScript.setCompleter(["get", "add", "remove", "find"].map(m => Hive.prototype[m]),
[ // Prototype: (name, filter, css, index)
function (context, obj, args) this.names,
function (context, obj, args) { return this.names; },
(context, obj, args) => Styles.completeSite(context, window.content),
null,
function (context, obj, args) this.sheets
function (context, obj, args) { return this.sheets; }
]);
},
template: function initTemplate() {

View File

@@ -49,14 +49,16 @@ var Binding = Class("Binding", {
}.call(this);
},
bind: function bind(func) function bound() {
try {
return func.apply(this.dactylBinding, arguments);
}
catch (e) {
util.reportError(e);
throw e;
}
bind: function bind(func) {
return function bound() {
try {
return func.apply(this.dactylBinding, arguments);
}
catch (e) {
util.reportError(e);
throw e;
}
};
},
events: Class.Memoize(function () {
@@ -88,7 +90,7 @@ var Binding = Class("Binding", {
Object.defineProperty(Binding.prototype, key, {
configurable: true,
enumerable: false,
value: function () apply(this.node, key, arguments),
value: function () { return apply(this.node, key, arguments); },
writable: true
});
});
@@ -174,22 +176,26 @@ var Template = Module("Template", {
return res;
},
bookmarkDescription: function (item, text) [
!(item.extra && item.extra.length) ? [] :
["span", { highlight: "URLExtra" },
" (",
template.map(item.extra, e =>
["", e[0], ": ",
["span", { highlight: e[2] }, e[1]]],
"\u00a0"),
")\u00a0"],
["a", { identifier: item.id == null ? "" : item.id,
"dactyl:command": item.command || "",
href: item.item.url, highlight: "URL" },
text || ""]
],
bookmarkDescription: function (item, text) {
return [
!(item.extra && item.extra.length) ? [] :
["span", { highlight: "URLExtra" },
" (",
template.map(item.extra, e =>
["", e[0], ": ",
["span", { highlight: e[2] }, e[1]]],
"\u00a0"),
")\u00a0"],
["a", { identifier: item.id == null ? "" : item.id,
"dactyl:command": item.command || "",
href: item.item.url, highlight: "URL" },
text || ""]
];
},
filter: function (str) ["span", { highlight: "Filter" }, str],
filter: function (str) {
return ["span", { highlight: "Filter" }, str];
},
completionRow: function completionRow(item, highlightGroup) {
if (typeof icon == "function")
@@ -378,12 +384,14 @@ var Template = Module("Template", {
return str;
},
icon: function (item, text) [
["span", { highlight: "CompIcon" },
item.icon ? ["img", { src: item.icon }] : []],
["span", { class: "td-strut" }],
text
],
icon: function (item, text) {
return [
["span", { highlight: "CompIcon" },
item.icon ? ["img", { src: item.icon }] : []],
["span", { class: "td-strut" }],
text
];
},
jumps: function jumps(index, elems) {
return ["table", {},

View File

@@ -24,7 +24,7 @@ var Magic = Class("Magic", {
get message() { return this.str; },
toString: function () this.str
toString: function () { return this.str; }
});
var FailedAssertion = Class("FailedAssertion", ErrorBase, {
@@ -119,7 +119,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
}
};
}, {
__noSuchMethod__: function __noSuchMethod__() this().__noSuchMethod__.apply(null, arguments)
__noSuchMethod__: function __noSuchMethod__() {
return this().__noSuchMethod__.apply(null, arguments);
}
}),
/**
@@ -186,15 +188,18 @@ 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,
(m, m1) => m1.toUpperCase()),
camelCase: function camelCase(name) {
return String.replace(name, /-(.)/g, (m, m1) => m1.toUpperCase());
},
/**
* Capitalizes the first character of the given string.
* @param {string} str The string to capitalize
* @returns {string}
*/
capitalize: function capitalize(str) str && str[0].toUpperCase() + str.slice(1).toLowerCase(),
capitalize: function capitalize(str) {
return str && str[0].toUpperCase() + str.slice(1).toLowerCase();
},
/**
* Returns a RegExp object that matches characters specified in the range
@@ -255,7 +260,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @param {string} b
* @returns {number}
*/
compareIgnoreCase: function compareIgnoreCase(a, b) String.localeCompare(a.toLowerCase(), b.toLowerCase()),
compareIgnoreCase: function compareIgnoreCase(a, b) {
return String.localeCompare(a.toLowerCase(), b.toLowerCase());
},
compileFormat: function compileFormat(format) {
let stack = [frame()];
@@ -272,7 +279,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
}, {
elements: [],
seen: new RealSet,
valid: function valid(obj) this.elements.every(e => !e.test || e.test(obj))
valid: function valid(obj) {
return this.elements.every(e => !e.test || e.test(obj));
}
});
}
@@ -296,15 +305,15 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
util.assert(stack.length, /*L*/"Unmatched %] in format");
}
else {
let quote = function quote(obj, char) obj[char];
let quote = function quote(obj, char) { return obj[char]; };
if (char !== char.toLowerCase())
quote = function quote(obj, char) Commands.quote(obj[char]);
quote = function quote(obj, char) { return Commands.quote(obj[char]); };
char = char.toLowerCase();
stack.top.elements.push(update(
obj => obj[char] != null ? quote(obj, char)
: "",
{ test: function test(obj) obj[char] != null }));
{ test: function test(obj) { return obj[char] != null; } }));
for (let elem of stack)
elem.seen[char] = true;
@@ -362,7 +371,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
}, {
elements: [],
seen: new RealSet,
valid: function valid(obj) this.elements.every(e => !e.test || e.test(obj))
valid: function valid(obj) {
return this.elements.every(e => !e.test || e.test(obj));
}
});
}
@@ -415,9 +426,12 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
obj => obj[name] != null && idx in obj[name] ? quote(obj[name][idx])
: hasOwnProperty(obj, name) ? "" : unknown(full),
{
test: function test(obj) obj[name] != null && idx in obj[name]
&& obj[name][idx] !== false
&& (!flags.e || obj[name][idx] != "")
test: function test(obj) {
return obj[name] != null &&
idx in obj[name] &&
obj[name][idx] !== false &&
(!flags.e || obj[name][idx] != "");
}
}));
}
else {
@@ -425,9 +439,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
obj => obj[name] != null ? quote(obj[name])
: hasOwnProperty(obj, name) ? "" : unknown(full),
{
test: function test(obj) obj[name] != null
&& obj[name] !== false
&& (!flags.e || obj[name] != "")
test: function test(obj) {
return obj[name] != null &&
obj[name] !== false &&
(!flags.e || obj[name] != "");
}
}));
}
@@ -554,8 +570,10 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @param {string} chars The characters to unquote.
* @returns {string}
*/
dequote: function dequote(pattern, chars)
pattern.replace(/\\(.)/, (m0, m1) => chars.contains(m1) ? m1 : m0),
dequote: function dequote(pattern, chars) {
return pattern.replace(/\\(.)/,
(m0, m1) => chars.contains(m1) ? m1 : m0);
},
/**
* Returns the nsIDocShell for the given window.
@@ -564,9 +582,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @returns {nsIDocShell}
*/
docShell: function docShell(win)
win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell),
docShell: function docShell(win) {
return win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);
},
/**
* Prints a message to the console. If *msg* is an object it is pretty
@@ -799,7 +819,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
if (params.method == "HEAD" && !params.notificationCallbacks)
params.notificationCallbacks = Class(XPCOM([Ci.nsIChannelEventSink, Ci.nsIInterfaceRequestor]), {
getInterface: function getInterface(iid) this.QueryInterface(iid),
getInterface: function getInterface(iid) {
return this.QueryInterface(iid);
},
asyncOnChannelRedirect: function (oldChannel, newChannel, flags, callback) {
if (newChannel instanceof Ci.nsIHttpChannel)
@@ -860,14 +882,16 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @param {Object} r2
* @returns {Object}
*/
intersection: function intersection(r1, r2) ({
get width() { return this.right - this.left; },
get height() { return this.bottom - this.top; },
left: Math.max(r1.left, r2.left),
right: Math.min(r1.right, r2.right),
top: Math.max(r1.top, r2.top),
bottom: Math.min(r1.bottom, r2.bottom)
}),
intersection: function intersection(r1, r2) {
return {
get width() { return this.right - this.left; },
get height() { return this.bottom - this.top; },
left: Math.max(r1.left, r2.left),
right: Math.min(r1.right, r2.right),
top: Math.max(r1.top, r2.top),
bottom: Math.min(r1.bottom, r2.bottom)
};
},
/**
* Returns true if the given stack frame resides in Dactyl code.
@@ -888,7 +912,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @param {string} domain
* @returns {boolean}
*/
isDomainURL: function isDomainURL(url, domain) util.isSubdomain(util.getHost(url), domain),
isDomainURL: function isDomainURL(url, domain) {
return util.isSubdomain(util.getHost(url), domain);
},
/**
* Returns true if *host* is a subdomain of *domain*.
@@ -1010,7 +1036,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* Removes leading garbage prepended to URIs by the subscript
* loader.
*/
fixURI: function fixURI(url) String.replace(url, /.* -> /, ""),
fixURI: function fixURI(url) {
return String.replace(url, /.* -> /, "");
},
/**
* Pretty print a JavaScript object. Use HTML markup to color certain items
@@ -1302,7 +1330,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
bound: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "bound")),
closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "bound")),
dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"],
iterate: function iterate(str, idx) util.regexp.iterate(this, str, idx)
iterate: function iterate(str, idx) {
return util.regexp.iterate(this, str, idx);
}
});
// Return a struct with properties for named parameters if we
@@ -1325,7 +1355,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @param {string} str
* @returns {string}
*/
escape: function regexp_escape(str) str.replace(/([\\{}()[\]^$.?*+|])/g, "\\$1"),
escape: function regexp_escape(str) {
return str.replace(/([\\{}()[\]^$.?*+|])/g, "\\$1");
},
/**
* Given a RegExp, returns its source in the form showable to the user.
@@ -1333,9 +1365,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @param {RegExp} re The regexp showable source of which is to be returned.
* @returns {string}
*/
getSource: function regexp_getSource(re) re.source.replace(/\\(.)/g,
(m0, m1) => m1 === "/" ? m1
: m0),
getSource: function regexp_getSource(re) {
return re.source.replace(/\\(.)/g,
(m0, m1) => m1 === "/" ? m1
: m0);
},
/**
* Iterates over all matches of the given regexp in the given
@@ -1406,7 +1440,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
this.errorCount++;
let obj = update({}, error, {
toString: function () String(error),
toString: function () { return String(error); },
stack: Magic(util.stackLines(String(error.stack || Error().stack)).join("\n").replace(/^/mg, "\t"))
});
@@ -1463,16 +1497,21 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @param {Window} window
* @returns {nsISelectionController}
*/
selectionController: function selectionController(win)
win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsISelectionDisplay)
.QueryInterface(Ci.nsISelectionController),
selectionController: function selectionController(win) {
return win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsISelectionDisplay)
.QueryInterface(Ci.nsISelectionController);
},
/**
* Escapes a string against shell meta-characters and argument
* separators.
*/
shellEscape: function shellEscape(str) '"' + String.replace(str, /[\\"$`]/g, "\\$&") + '"',
shellEscape: function shellEscape(str) {
return '"' + String.replace(str, /[\\"$`]/g, "\\$&") + '"';
},
/**
* Suspend execution for at least *delay* milliseconds. Functions by
@@ -1634,8 +1673,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @returns {function} A new function which may not execute
* synchronously.
*/
yieldable: deprecated("Task.spawn", function yieldable(func)
function magic() {
yieldable: deprecated("Task.spawn", function yieldable(func) {
return function magic() {
let gen = func.apply(this, arguments);
(function next() {
try {
@@ -1643,6 +1682,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
}
catch (e if e instanceof StopIteration) {};
})();
};
}),
/**
@@ -1663,10 +1703,13 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @param {Window} win The child window.
* @returns {Window} The top-level parent window.
*/
topWindow: function topWindow(win)
win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow),
topWindow: function topWindow(win) {
return win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
},
/**
* Traps errors in the called function, possibly reporting them.
@@ -1759,7 +1802,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
*/
weakReference: function weakReference(jsval) {
if (jsval == null)
return { get: function get() null };
return { get: function get() { return null; } };
return Cu.getWeakReference(jsval);
},
@@ -1797,7 +1840,9 @@ this.Math = update(Object.create(GlobalMath), {
* @param {number} max The maximum constraint.
* @returns {number}
*/
constrain: function constrain(value, min, max) Math.min(Math.max(min, value), max)
constrain: function constrain(value, min, max) {
return Math.min(Math.max(min, value), max);
}
});
endModule();