mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-11 17:15:46 +01:00
Replace expression closures (function expressions - named and dynamic this).
Expression closures are to be axed. See https://bugzil.la/1083458. Leaving deprecated() and literal() calls and method shorthand syntax conversions until after the ESR overlap.
This commit is contained in:
@@ -238,7 +238,9 @@ var Addon = Class("Addon", {
|
||||
|
||||
["cancelUninstall", "findUpdates", "getResourceURI", "hasResource", "isCompatibleWith",
|
||||
"uninstall"].forEach(function (prop) {
|
||||
Addon.prototype[prop] = function proxy() apply(this.addon, prop, arguments);
|
||||
Addon.prototype[prop] = function proxy() {
|
||||
return apply(this.addon, prop, arguments);
|
||||
};
|
||||
});
|
||||
|
||||
["aboutURL", "appDisabled", "applyBackgroundUpdates", "blocklistState", "contributors", "creator",
|
||||
|
||||
@@ -273,10 +273,12 @@ function apply(obj, meth, args) {
|
||||
* @default false
|
||||
* @returns {Generator}
|
||||
*/
|
||||
function prototype(obj)
|
||||
obj.__proto__ || Object.getPrototypeOf(obj) ||
|
||||
XPCNativeWrapper.unwrap(obj).__proto__ ||
|
||||
Object.getPrototypeOf(XPCNativeWrapper.unwrap(obj));
|
||||
function prototype(obj) {
|
||||
return obj.__proto__ ||
|
||||
Object.getPrototypeOf(obj) ||
|
||||
XPCNativeWrapper.unwrap(obj).__proto__ ||
|
||||
Object.getPrototypeOf(XPCNativeWrapper.unwrap(obj));
|
||||
}
|
||||
|
||||
function* properties(obj, prototypes) {
|
||||
let orig = obj;
|
||||
@@ -796,7 +798,9 @@ function update(target) {
|
||||
if (typeof desc.value === "function" && target.__proto__ && !(desc.value instanceof Ci.nsIDOMElement /* wtf? */)) {
|
||||
let func = desc.value.wrapped || desc.value;
|
||||
if (!func.superapply) {
|
||||
func.__defineGetter__("super", function get_super() Object.getPrototypeOf(target)[k]);
|
||||
func.__defineGetter__("super", function get_super() {
|
||||
return Object.getPrototypeOf(target)[k];
|
||||
});
|
||||
|
||||
func.superapply = function superapply(self, args) {
|
||||
let meth = Object.getPrototypeOf(target)[k];
|
||||
@@ -918,8 +922,10 @@ Class.objectGlobal = object => {
|
||||
*
|
||||
* @param {Object} desc The property descriptor.
|
||||
*/
|
||||
Class.Property = function Property(desc) update(
|
||||
Object.create(Property.prototype), desc || { configurable: true, writable: true });
|
||||
Class.Property = function Property(desc) {
|
||||
return update(Object.create(Property.prototype),
|
||||
desc || { configurable: true, writable: true });
|
||||
};
|
||||
Class.Property.prototype.init = () => {};
|
||||
/**
|
||||
* Extends a subclass with a superclass. The subclass's
|
||||
@@ -998,7 +1004,9 @@ Class.Memoize = function Memoize(getter, wait)
|
||||
}
|
||||
};
|
||||
|
||||
this.set = function s_Memoize(val) Class.replaceProperty(this.instance || this, key, val);
|
||||
this.set = function s_Memoize(val) {
|
||||
return Class.replaceProperty(this.instance || this, key, val);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1006,8 +1014,8 @@ Class.Memoize = function Memoize(getter, wait)
|
||||
* Updates the given object with the object in the target class's
|
||||
* prototype.
|
||||
*/
|
||||
Class.Update = function Update(obj)
|
||||
Class.Property({
|
||||
Class.Update = function Update(obj) {
|
||||
return Class.Property({
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
@@ -1015,12 +1023,15 @@ Class.Update = function Update(obj)
|
||||
this.value = update({}, target[key], obj);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Class.replaceProperty = function replaceProperty(obj, prop, value) {
|
||||
Object.defineProperty(obj, prop, { configurable: true, enumerable: true, value: value, writable: true });
|
||||
return value;
|
||||
};
|
||||
Class.toString = function toString() "[class " + this.className + "]";
|
||||
Class.toString = function toString() {
|
||||
return "[class " + this.className + "]";
|
||||
};
|
||||
Class.prototype = {
|
||||
/**
|
||||
* Initializes new instances of this class. Called automatically
|
||||
@@ -1353,8 +1364,12 @@ function Struct(...args) {
|
||||
members: Ary(args).map((v, k) => [v, k]).toObject()
|
||||
});
|
||||
args.forEach(function (name, i) {
|
||||
Struct.prototype.__defineGetter__(name, function () this[i]);
|
||||
Struct.prototype.__defineSetter__(name, function (val) { this[i] = val; });
|
||||
Struct.prototype.__defineGetter__(name, function () {
|
||||
return this[i];
|
||||
});
|
||||
Struct.prototype.__defineSetter__(name, function (val) {
|
||||
this[i] = val;
|
||||
});
|
||||
});
|
||||
return Struct;
|
||||
}
|
||||
@@ -1401,9 +1416,12 @@ var StructBase = Class("StructBase", Array, {
|
||||
*/
|
||||
defaultValue: function defaultValue(key, val) {
|
||||
let i = this.prototype.members[key];
|
||||
this.prototype.__defineGetter__(i, function () (this[i] = val.call(this)));
|
||||
this.prototype.__defineSetter__(i, function (value)
|
||||
Class.replaceProperty(this, i, value));
|
||||
this.prototype.__defineGetter__(i, function () {
|
||||
return this[i] = val.call(this);
|
||||
});
|
||||
this.prototype.__defineSetter__(i, function (value) {
|
||||
return Class.replaceProperty(this, i, value);
|
||||
});
|
||||
return this;
|
||||
},
|
||||
|
||||
@@ -1728,7 +1746,9 @@ const Iter = Class("Iter", {
|
||||
this.iter = iter.__iterator__();
|
||||
|
||||
if (this.iter.finalize)
|
||||
this.finalize = function finalize() apply(this.iter, "finalize", arguments);
|
||||
this.finalize = function finalize() {
|
||||
return apply(this.iter, "finalize", arguments);
|
||||
};
|
||||
},
|
||||
|
||||
next: function next() this.iter.next(),
|
||||
|
||||
@@ -22,7 +22,9 @@ function newURI(url, charset, base) {
|
||||
|
||||
var Bookmark = Struct("url", "title", "icon", "post", "keyword", "tags", "charset", "id");
|
||||
var Keyword = Struct("keyword", "title", "icon", "url");
|
||||
Bookmark.defaultValue("icon", function () BookmarkCache.getFavicon(this.url));
|
||||
Bookmark.defaultValue("icon", function () {
|
||||
return BookmarkCache.getFavicon(this.url);
|
||||
});
|
||||
update(Bookmark.prototype, {
|
||||
get extra() {
|
||||
return [
|
||||
@@ -48,7 +50,7 @@ update(Bookmark.prototype, {
|
||||
|
||||
get folder() {
|
||||
let res = [];
|
||||
res.toString = function () this.join("/");
|
||||
res.toString = function () { return this.join("/"); };
|
||||
|
||||
let id = this.id, title;
|
||||
while ((id = services.bookmarks.getFolderIdForItem(id)) &&
|
||||
@@ -87,11 +89,13 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
|
||||
|
||||
"@@iterator": function () values(bookmarkcache.bookmarks),
|
||||
|
||||
bookmarks: Class.Memoize(function () this.load()),
|
||||
bookmarks: Class.Memoize(function () { return this.load(); }),
|
||||
|
||||
keywords: Class.Memoize(function () Ary.toObject([[b.keyword, b]
|
||||
for (b of this)
|
||||
if (b.keyword)])),
|
||||
keywords: Class.Memoize(function () {
|
||||
return Ary.toObject([[b.keyword, b]
|
||||
for (b of this)
|
||||
if (b.keyword)]);
|
||||
}),
|
||||
|
||||
rootFolders: ["toolbarFolder", "bookmarksMenuFolder", "unfiledBookmarksFolder"]
|
||||
.map(s => services.bookmarks[s]),
|
||||
|
||||
@@ -260,7 +260,9 @@ var Buffer = Module("Buffer", {
|
||||
get modules() { return this.topWindow.dactyl.modules; },
|
||||
set modules(val) {},
|
||||
|
||||
topWindow: Class.Memoize(function () util.topWindow(this.win)),
|
||||
topWindow: Class.Memoize(function () {
|
||||
return util.topWindow(this.win);
|
||||
}),
|
||||
|
||||
/**
|
||||
* @property {nsIURI} The current top-level document's URI.
|
||||
@@ -1042,7 +1044,9 @@ var Buffer = Module("Buffer", {
|
||||
.sort((a, b) => a[1] - b[1]);
|
||||
|
||||
if (offScreen && !reverse)
|
||||
elems = elems.filter(function (e) e[1] > this, this.topWindow.innerHeight);
|
||||
elems = elems.filter(function (e) {
|
||||
return e[1] > this, this.topWindow.innerHeight;
|
||||
});
|
||||
|
||||
let idx = Math.min((count || 1) - 1, elems.length);
|
||||
util.assert(idx in elems);
|
||||
|
||||
@@ -69,7 +69,9 @@ update(CommandOption, {
|
||||
* @property {object} The option accepts a boolean argument.
|
||||
* @final
|
||||
*/
|
||||
BOOL: ArgType("boolean", function parseBoolArg(val) Commands.parseBool(val)),
|
||||
BOOL: ArgType("boolean", function parseBoolArg(val) {
|
||||
return Commands.parseBool(val);
|
||||
}),
|
||||
/**
|
||||
* @property {object} The option accepts a string argument.
|
||||
* @final
|
||||
@@ -84,12 +86,16 @@ update(CommandOption, {
|
||||
* @property {object} The option accepts an integer argument.
|
||||
* @final
|
||||
*/
|
||||
INT: ArgType("int", function parseIntArg(val) parseInt(val)),
|
||||
INT: ArgType("int", function parseIntArg(val) {
|
||||
return parseInt(val);
|
||||
}),
|
||||
/**
|
||||
* @property {object} The option accepts a float argument.
|
||||
* @final
|
||||
*/
|
||||
FLOAT: ArgType("float", function parseFloatArg(val) parseFloat(val)),
|
||||
FLOAT: ArgType("float", function parseFloatArg(val) {
|
||||
return parseFloat(val);
|
||||
}),
|
||||
/**
|
||||
* @property {object} The option accepts a string list argument.
|
||||
* E.g. "foo,bar"
|
||||
@@ -219,21 +225,29 @@ var Command = Class("Command", {
|
||||
* @property {[string]} All of this command's name specs. e.g., "com[mand]"
|
||||
*/
|
||||
specs: null,
|
||||
parsedSpecs: Class.Memoize(function () Command.parseSpecs(this.specs)),
|
||||
parsedSpecs: Class.Memoize(function () {
|
||||
return Command.parseSpecs(this.specs);
|
||||
}),
|
||||
|
||||
/** @property {[string]} All of this command's short names, e.g., "com" */
|
||||
shortNames: Class.Memoize(function () Ary.compact(this.parsedSpecs.map(n => n[1]))),
|
||||
shortNames: Class.Memoize(function () {
|
||||
return Ary.compact(this.parsedSpecs.map(n => n[1]));
|
||||
}),
|
||||
|
||||
/**
|
||||
* @property {[string]} All of this command's long names, e.g., "command"
|
||||
*/
|
||||
longNames: Class.Memoize(function () this.parsedSpecs.map(n => n[0])),
|
||||
longNames: Class.Memoize(function () {
|
||||
return this.parsedSpecs.map(n => n[0]);
|
||||
}),
|
||||
|
||||
/** @property {string} The command's canonical name. */
|
||||
name: Class.Memoize(function () this.longNames[0]),
|
||||
name: Class.Memoize(function () { return this.longNames[0]; }),
|
||||
|
||||
/** @property {[string]} All of this command's long and short names. */
|
||||
names: Class.Memoize(function () this.names = Ary.flatten(this.parsedSpecs)),
|
||||
names: Class.Memoize(function () {
|
||||
return this.names = Ary.flatten(this.parsedSpecs);
|
||||
}),
|
||||
|
||||
/** @property {string} This command's description, as shown in :listcommands */
|
||||
description: Messages.Localized(""),
|
||||
@@ -301,17 +315,20 @@ var Command = Class("Command", {
|
||||
* @property {Array} The options this command takes.
|
||||
* @see Commands@parseArguments
|
||||
*/
|
||||
options: Class.Memoize(function ()
|
||||
this._options.map(function (opt) {
|
||||
options: Class.Memoize(function () {
|
||||
return this._options.map(function (opt) {
|
||||
let option = CommandOption.fromArray(opt);
|
||||
option.localeName = ["command", this.name, option.names[0]];
|
||||
return option;
|
||||
}, this)),
|
||||
}, this);
|
||||
}),
|
||||
_options: [],
|
||||
|
||||
optionMap: Class.Memoize(function () Ary(this.options)
|
||||
.map(opt => opt.names.map(name => [name, opt]))
|
||||
.flatten().toObject()),
|
||||
optionMap: Class.Memoize(function () {
|
||||
return Ary(this.options)
|
||||
.map(opt => opt.names.map(name => [name, opt]))
|
||||
.flatten().toObject();
|
||||
}),
|
||||
|
||||
newArgs: function newArgs(base) {
|
||||
let res = Object.create(this.argsPrototype);
|
||||
@@ -582,7 +599,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
||||
}
|
||||
|
||||
for (let name of names) {
|
||||
ex.__defineGetter__(name, function () this._run(name));
|
||||
ex.__defineGetter__(name, function () { return this._run(name); });
|
||||
if (name in this._map && !this._map[name].isPlaceholder)
|
||||
this.remove(name);
|
||||
}
|
||||
@@ -1290,9 +1307,12 @@ var Commands = Module("commands", {
|
||||
*/$), /U/g, "\\u"), "x")
|
||||
}),
|
||||
|
||||
validName: Class.Memoize(function validName() util.regexp("^" + this.nameRegexp.source + "$")),
|
||||
validName: Class.Memoize(function validName() {
|
||||
return util.regexp("^" + this.nameRegexp.source + "$");
|
||||
}),
|
||||
|
||||
commandRegexp: Class.Memoize(function commandRegexp() util.regexp(literal(function () /*
|
||||
commandRegexp: Class.Memoize(function commandRegexp() {
|
||||
return util.regexp(literal(function () /*
|
||||
^
|
||||
(?P<spec>
|
||||
(?P<prespace> [:\s]*)
|
||||
@@ -1309,7 +1329,8 @@ var Commands = Module("commands", {
|
||||
$
|
||||
*/$), "x", {
|
||||
name: this.nameRegexp
|
||||
})),
|
||||
});
|
||||
}),
|
||||
|
||||
/**
|
||||
* Parses a complete Ex command.
|
||||
@@ -1783,12 +1804,18 @@ var Commands = Module("commands", {
|
||||
});
|
||||
},
|
||||
javascript: function initJavascript(dactyl, modules, window) {
|
||||
const { JavaScript } = modules;
|
||||
const { setCompleter } = modules.JavaScript;
|
||||
|
||||
JavaScript.setCompleter([CommandHive.prototype.get, CommandHive.prototype.remove],
|
||||
[function () [[c.names, c.description] for (c of this)]]);
|
||||
JavaScript.setCompleter([Commands.prototype.get],
|
||||
[function () [[c.names, c.description] for (c of this.iterator())]]);
|
||||
setCompleter([CommandHive.prototype.get,
|
||||
CommandHive.prototype.remove],
|
||||
[function () {
|
||||
return [[c.names, c.description] for (c of this)];
|
||||
}]);
|
||||
setCompleter([Commands.prototype.get],
|
||||
[function () {
|
||||
return [[c.names, c.description]
|
||||
for (c of this.iterator())];
|
||||
}]);
|
||||
},
|
||||
mappings: function initMappings(dactyl, modules, window) {
|
||||
const { commands, mappings, modes } = modules;
|
||||
|
||||
@@ -62,7 +62,9 @@ var CompletionContext = Class("CompletionContext", {
|
||||
["anchored", "compare", "editor", "_filter", "filterFunc", "forceAnchored", "top"]
|
||||
.forEach(key => self[key] = parent[key]);
|
||||
|
||||
self.__defineGetter__("value", function get_value() this.top.value);
|
||||
self.__defineGetter__("value", function get_value() {
|
||||
return this.top.value;
|
||||
});
|
||||
|
||||
self.offset = parent.offset;
|
||||
self.advance(offset);
|
||||
@@ -88,8 +90,12 @@ var CompletionContext = Class("CompletionContext", {
|
||||
if (self != this)
|
||||
return self;
|
||||
["_caret", "contextList", "maxItems", "onUpdate", "selectionTypes", "tabPressed", "updateAsync", "value"].forEach(function fe(key) {
|
||||
self.__defineGetter__(key, function () this.top[key]);
|
||||
self.__defineSetter__(key, function (val) this.top[key] = val);
|
||||
self.__defineGetter__(key, function () {
|
||||
return this.top[key];
|
||||
});
|
||||
self.__defineSetter__(key, function (val) {
|
||||
this.top[key] = val;
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
@@ -159,7 +165,7 @@ var CompletionContext = Class("CompletionContext", {
|
||||
* changes its completion list. Only called when
|
||||
* {@link #updateAsync} is true.
|
||||
*/
|
||||
this.onUpdate = function onUpdate() true;
|
||||
this.onUpdate = function onUpdate() { return true; };
|
||||
|
||||
this.runCount = 0;
|
||||
|
||||
@@ -167,12 +173,20 @@ var CompletionContext = Class("CompletionContext", {
|
||||
* @property {CompletionContext} The top-level completion context.
|
||||
*/
|
||||
this.top = this;
|
||||
this.__defineGetter__("incomplete", function get_incomplete() this._incomplete
|
||||
|| this.contextList.some(c => c.parent && c.incomplete));
|
||||
this.__defineGetter__("waitingForTab", function get_waitingForTab() this._waitingForTab
|
||||
|| this.contextList.some(c => c.parent && c.waitingForTab));
|
||||
this.__defineSetter__("incomplete", function get_incomplete(val) { this._incomplete = val; });
|
||||
this.__defineSetter__("waitingForTab", function get_waitingForTab(val) { this._waitingForTab = val; });
|
||||
this.__defineGetter__("incomplete", function get_incomplete() {
|
||||
return this._incomplete ||
|
||||
this.contextList.some(c => c.parent && c.incomplete);
|
||||
});
|
||||
this.__defineGetter__("waitingForTab", function get_waitingForTab() {
|
||||
return this._waitingForTab ||
|
||||
this.contextList.some(c => c.parent && c.waitingForTab);
|
||||
});
|
||||
this.__defineSetter__("incomplete", function get_incomplete(val) {
|
||||
this._incomplete = val;
|
||||
});
|
||||
this.__defineSetter__("waitingForTab", function get_waitingForTab(val) {
|
||||
this._waitingForTab = val;
|
||||
});
|
||||
this.reset();
|
||||
}
|
||||
/**
|
||||
@@ -211,9 +225,11 @@ var CompletionContext = Class("CompletionContext", {
|
||||
return this;
|
||||
},
|
||||
|
||||
__title: Class.Memoize(function __title() this._title.map(s =>
|
||||
typeof s == "string" ? messages.get("completion.title." + s, s)
|
||||
: s)),
|
||||
__title: Class.Memoize(function __title() {
|
||||
return this._title.map(s =>
|
||||
typeof s == "string" ? messages.get("completion.title." + s, s)
|
||||
: s);
|
||||
}),
|
||||
|
||||
set title(val) {
|
||||
delete this.__title;
|
||||
@@ -222,7 +238,9 @@ var CompletionContext = Class("CompletionContext", {
|
||||
get title() { return this.__title; },
|
||||
|
||||
get activeContexts() {
|
||||
return this.contextList.filter(function f(c) c.items.length);
|
||||
return this.contextList.filter(function f(c) {
|
||||
return c.items.length;
|
||||
});
|
||||
},
|
||||
|
||||
// Temporary
|
||||
@@ -238,12 +256,17 @@ var CompletionContext = Class("CompletionContext", {
|
||||
let self = this;
|
||||
|
||||
try {
|
||||
let allItems = this.contextList.map(function m(context) context.hasItems && context.items.length);
|
||||
let allItems = this.contextList.map(function m(context) {
|
||||
return context.hasItems && context.items.length;
|
||||
});
|
||||
if (this.cache.allItems && Ary.equals(this.cache.allItems, allItems))
|
||||
return this.cache.allItemsResult;
|
||||
this.cache.allItems = allItems;
|
||||
|
||||
let minStart = apply(Math, "min", this.activeContexts.map(function m(c) c.offset));
|
||||
let minStart = apply(Math, "min",
|
||||
this.activeContexts.map(function m(c) {
|
||||
return c.offset;
|
||||
}));
|
||||
if (minStart == Infinity)
|
||||
minStart = 0;
|
||||
|
||||
@@ -256,11 +279,13 @@ var CompletionContext = Class("CompletionContext", {
|
||||
return Ary.flatten(self.activeContexts.map(function m(context) {
|
||||
let prefix = self.value.substring(minStart, context.offset);
|
||||
|
||||
return context.items.map(function m(item) ({
|
||||
text: prefix + item.text,
|
||||
result: prefix + item.result,
|
||||
__proto__: item
|
||||
}));
|
||||
return context.items.map(function m(item) {
|
||||
return {
|
||||
text: prefix + item.text,
|
||||
result: prefix + item.result,
|
||||
__proto__: item
|
||||
};
|
||||
});
|
||||
}));
|
||||
}
|
||||
});
|
||||
@@ -275,18 +300,30 @@ var CompletionContext = Class("CompletionContext", {
|
||||
// Temporary
|
||||
get allSubstrings() {
|
||||
let contexts = this.activeContexts;
|
||||
let minStart = apply(Math, "min", contexts.map(function m(c) c.offset));
|
||||
let minStart = apply(Math, "min",
|
||||
contexts.map(function m(c) {
|
||||
return c.offset;
|
||||
}));
|
||||
let lists = contexts.map(function m(context) {
|
||||
let prefix = context.value.substring(minStart, context.offset);
|
||||
return context.substrings.map(function m(s) prefix + s);
|
||||
return context.substrings.map(function m(s) {
|
||||
return prefix + s;
|
||||
});
|
||||
});
|
||||
|
||||
/* TODO: Deal with sub-substrings for multiple contexts again.
|
||||
* Possibly.
|
||||
*/
|
||||
let substrings = lists.reduce(
|
||||
function r(res, list) res.filter(function f(str) list.some(function s_(s) s.substr(0, str.length) == str)),
|
||||
lists.pop());
|
||||
function r(res, list) {
|
||||
return res.filter(function f(str) {
|
||||
return list.some(function s_(s) {
|
||||
return s.substr(0, str.length) == str;
|
||||
});
|
||||
});
|
||||
},
|
||||
lists.pop());
|
||||
|
||||
if (!substrings) // FIXME: How is this undefined?
|
||||
return [];
|
||||
return Ary.uniq(Array.slice(substrings));
|
||||
@@ -299,7 +336,9 @@ var CompletionContext = Class("CompletionContext", {
|
||||
get caret() { return this._caret - this.offset; },
|
||||
set caret(val) { this._caret = val + this.offset; },
|
||||
|
||||
get compare() { return this._compare || function compare() 0; },
|
||||
get compare() {
|
||||
return this._compare || function compare() { return 0; };
|
||||
},
|
||||
set compare(val) { this._compare = val; },
|
||||
|
||||
get completions() { return this._completions || []; },
|
||||
@@ -370,10 +409,10 @@ var CompletionContext = Class("CompletionContext", {
|
||||
let res = { highlight: "" };
|
||||
|
||||
function* result(quote) {
|
||||
yield ["context", function p_context() self];
|
||||
yield ["result", quote ? function p_result() quote[0] + util.trapErrors(1, quote, this.text) + quote[2]
|
||||
: function p_result() this.text];
|
||||
yield ["texts", function p_texts() Array.concat(this.text)];
|
||||
yield ["context", function p_context() { return self; }];
|
||||
yield ["result", quote ? function p_result() { return quote[0] + util.trapErrors(1, quote, this.text) + quote[2]; }
|
||||
: function p_result() { return this.text; }];
|
||||
yield ["texts", function p_texts() { return Array.concat(this.text); }];
|
||||
};
|
||||
|
||||
for (let i of iter(this.keys, result(this.quote))) {
|
||||
@@ -383,10 +422,16 @@ var CompletionContext = Class("CompletionContext", {
|
||||
// reference any variables. Don't bother with eval context.
|
||||
v = Function("i", "return i" + v);
|
||||
if (typeof v == "function")
|
||||
res.__defineGetter__(k, function p_gf() Class.replaceProperty(this, k, v.call(this, this.item, self)));
|
||||
res.__defineGetter__(k, function p_gf() {
|
||||
return Class.replaceProperty(this, k, v.call(this, this.item, self));
|
||||
});
|
||||
else
|
||||
res.__defineGetter__(k, function p_gp() Class.replaceProperty(this, k, this.item[v]));
|
||||
res.__defineSetter__(k, function p_s(val) Class.replaceProperty(this, k, val));
|
||||
res.__defineGetter__(k, function p_gp() {
|
||||
return Class.replaceProperty(this, k, this.item[v]);
|
||||
});
|
||||
res.__defineSetter__(k, function p_s(val) {
|
||||
Class.replaceProperty(this, k, val);
|
||||
});
|
||||
}
|
||||
return res;
|
||||
},
|
||||
@@ -511,7 +556,9 @@ var CompletionContext = Class("CompletionContext", {
|
||||
// Item prototypes
|
||||
if (!this._cache.constructed) {
|
||||
let proto = this.itemPrototype;
|
||||
this._cache.constructed = items.map(function m(item) ({ __proto__: proto, item: item }));
|
||||
this._cache.constructed = items.map(function m(item) {
|
||||
return { __proto__: proto, item: item };
|
||||
});
|
||||
}
|
||||
|
||||
// Filters
|
||||
@@ -598,7 +645,9 @@ var CompletionContext = Class("CompletionContext", {
|
||||
|
||||
let quote = this.quote;
|
||||
if (quote)
|
||||
substrings = substrings.map(function m(str) quote[0] + quote[1](str));
|
||||
substrings = substrings.map(function m(str) {
|
||||
return quote[0] + quote[1](str);
|
||||
});
|
||||
return this._substrings = substrings;
|
||||
},
|
||||
|
||||
@@ -658,7 +707,8 @@ var CompletionContext = Class("CompletionContext", {
|
||||
let step = start > end ? -1 : 1;
|
||||
start = Math.max(0, start || 0);
|
||||
end = Math.min(items.length, end ? end : items.length);
|
||||
return iter.map(util.range(start, end, step), function m(i) items[i]);
|
||||
return iter.map(util.range(start, end, step),
|
||||
function m(i) { return items[i]; });
|
||||
},
|
||||
|
||||
getRow: function getRow(idx, doc) {
|
||||
@@ -876,7 +926,8 @@ var CompletionContext = Class("CompletionContext", {
|
||||
*/
|
||||
wait: function wait(timeout, interruptable) {
|
||||
this.allItems;
|
||||
return util.waitFor(function wf() !this.incomplete, this, timeout, interruptable);
|
||||
return util.waitFor(function wf() { return !this.incomplete; },
|
||||
this, timeout, interruptable);
|
||||
}
|
||||
}, {
|
||||
Sort: {
|
||||
@@ -924,7 +975,11 @@ var Completion = Module("completion", {
|
||||
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) ({ item: i })) };
|
||||
return {
|
||||
items: res.map(function m(i) {
|
||||
return { item: i };
|
||||
})
|
||||
};
|
||||
context.contexts["/run"].completions = res;
|
||||
}
|
||||
context.wait(null, true);
|
||||
@@ -933,7 +988,7 @@ var Completion = Module("completion", {
|
||||
|
||||
runCompleter: function runCompleter(name, filter, maxItems) {
|
||||
return apply(this, "_runCompleter", arguments)
|
||||
.items.map(function m(i) i.item);
|
||||
.items.map(function m(i) { return i.item; });
|
||||
},
|
||||
|
||||
listCompleter: function listCompleter(name, filter, maxItems, ...args) {
|
||||
@@ -945,15 +1000,25 @@ var Completion = Module("completion", {
|
||||
|
||||
let contexts = context.activeContexts;
|
||||
if (!contexts.length)
|
||||
contexts = context.contextList.filter(function f(c) c.hasItems).slice(0, 1);
|
||||
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)
|
||||
[template.completionRow(context.title, "CompTitle"),
|
||||
template.map(context.items, function m(item) context.createRow(item), null, 100)])]);
|
||||
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)];
|
||||
})]);
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -972,7 +1037,9 @@ var Completion = Module("completion", {
|
||||
|
||||
context.quote = context.quote || ["", util.identity, ""];
|
||||
let quote = context.quote[1];
|
||||
context.quote[1] = function quote_1(str) quote(str.replace(/!/g, escape));
|
||||
context.quote[1] = function quote_1(str) {
|
||||
return quote(str.replace(/!/g, escape));
|
||||
};
|
||||
}
|
||||
|
||||
if (this.options["urlseparator"])
|
||||
@@ -1029,8 +1096,14 @@ var Completion = Module("completion", {
|
||||
|
||||
let words = context.filter.toLowerCase().split(/\s+/g);
|
||||
context.hasItems = true;
|
||||
context.completions = context.completions.filter(function f({ url, title })
|
||||
words.every(function e(w) (url + " " + title).toLowerCase().indexOf(w) >= 0));
|
||||
context.completions =
|
||||
context.completions
|
||||
.filter(function f({ url, title }) {
|
||||
return words.every(function e(w) {
|
||||
return (url + " " + title)
|
||||
.toLowerCase().indexOf(w) >= 0;
|
||||
})
|
||||
});
|
||||
|
||||
context.format = this.modules.bookmarks.format;
|
||||
context.keys.extra = function k_extra(item) {
|
||||
@@ -1078,9 +1151,13 @@ var Completion = Module("completion", {
|
||||
}
|
||||
|
||||
if (tags)
|
||||
context.filters.push(function filter_(item) tags.
|
||||
every(function e(tag) (item.tags || []).
|
||||
some(function s(t) !compare(tag, t))));
|
||||
context.filters.push(function filter_(item) {
|
||||
return tags.every(function e(tag) {
|
||||
return (item.tags || []).some(function s(t) {
|
||||
return !compare(tag, t);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context.anchored = false;
|
||||
if (!context.title)
|
||||
@@ -1095,13 +1172,18 @@ var Completion = Module("completion", {
|
||||
// accept them if all tokens match either the URL or the title.
|
||||
// Filter out all directly matching strings.
|
||||
let match = context.filters[0];
|
||||
context.filters[0] = function filters_0(item) !match.call(this, item);
|
||||
context.filters[0] = function filters_0(item) {
|
||||
!match.call(this, item);
|
||||
};
|
||||
|
||||
// and all that don't match the tokens.
|
||||
let tokens = context.filter.split(/\s+/);
|
||||
context.filters.push(function filter_(item) tokens.every(
|
||||
function e(tok) contains(item.url, tok) ||
|
||||
contains(item.title, tok)));
|
||||
context.filters.push(function filter_(item) {
|
||||
return tokens.every(function e(tok) {
|
||||
return contains(item.url, tok) ||
|
||||
contains(item.title, tok);
|
||||
});
|
||||
});
|
||||
|
||||
let re = RegExp(tokens.filter(util.identity).map(util.regexp.escape).join("|"), "g");
|
||||
function highlight(item, text, i) {
|
||||
@@ -1139,7 +1221,9 @@ var Completion = Module("completion", {
|
||||
["div", { highlight: "Completions" },
|
||||
template.completionRow(["Context", "Title"], "CompTitle"),
|
||||
template.map(completion.contextList || [],
|
||||
function m(item) template.completionRow(item, "CompItem"))]);
|
||||
function m(item) {
|
||||
return template.completionRow(item, "CompItem");
|
||||
})]);
|
||||
},
|
||||
{
|
||||
argCount: "*",
|
||||
@@ -1169,7 +1253,11 @@ var Completion = Module("completion", {
|
||||
return first == val || second == val;
|
||||
},
|
||||
has: function () {
|
||||
let test = function test(val) this.value.some(function s(value) this.checkHas(value, val), this);
|
||||
let test = function test(val) {
|
||||
return this.value.some(function s(value) {
|
||||
return this.checkHas(value, val)
|
||||
}, this);
|
||||
};
|
||||
return Array.some(arguments, test, this);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -88,7 +88,9 @@ var ConfigBase = Class("ConfigBase", {
|
||||
"resource://dactyl-local/config.json"
|
||||
],
|
||||
|
||||
configs: Class.Memoize(function () this.configFiles.map(url => JSON.parse(File.readURL(url)))),
|
||||
configs: Class.Memoize(function () {
|
||||
return this.configFiles.map(url => JSON.parse(File.readURL(url)));
|
||||
}),
|
||||
|
||||
loadConfig: function loadConfig(documentURL) {
|
||||
|
||||
@@ -211,7 +213,9 @@ var ConfigBase = Class("ConfigBase", {
|
||||
/**
|
||||
* The current dactyl locale.
|
||||
*/
|
||||
locale: Class.Memoize(function () this.bestLocale(this.locales)),
|
||||
locale: Class.Memoize(function () {
|
||||
return this.bestLocale(this.locales);
|
||||
}),
|
||||
|
||||
/**
|
||||
* The current application locale.
|
||||
@@ -237,7 +241,9 @@ var ConfigBase = Class("ConfigBase", {
|
||||
if (f.isDirectory())).array;
|
||||
}
|
||||
|
||||
let exists = function exists(pkg) services["resource:"].hasSubstitution("dactyl-locale-" + pkg);
|
||||
let exists = function exists(pkg) {
|
||||
return services["resource:"].hasSubstitution("dactyl-locale-" + pkg);
|
||||
};
|
||||
|
||||
return Ary.uniq([this.appLocale, this.appLocale.replace(/-.*/, "")]
|
||||
.filter(exists)
|
||||
@@ -415,11 +421,12 @@ var ConfigBase = Class("ConfigBase", {
|
||||
|
||||
get fileExt() { return this.name.slice(0, -6); },
|
||||
|
||||
dtd: Class.Memoize(function ()
|
||||
iter(this.dtdExtra,
|
||||
(["dactyl." + k, v] for ([k, v] of iter(config.dtdDactyl))),
|
||||
(["dactyl." + s, config[s]] for (s of config.dtdStrings)))
|
||||
.toObject()),
|
||||
dtd: Class.Memoize(function () {
|
||||
return iter(this.dtdExtra,
|
||||
(["dactyl." + k, v] for ([k, v] of iter(config.dtdDactyl))),
|
||||
(["dactyl." + s, config[s]] for (s of config.dtdStrings)))
|
||||
.toObject();
|
||||
}),
|
||||
|
||||
dtdDactyl: memoize({
|
||||
get name() { return config.name; },
|
||||
@@ -435,7 +442,9 @@ var ConfigBase = Class("ConfigBase", {
|
||||
"list.mailto": Class.Memoize(() => config.name + "@googlegroups.com"),
|
||||
"list.href": Class.Memoize(() => "http://groups.google.com/group/" + config.name),
|
||||
|
||||
"hg.latest": Class.Memoize(function () this.code + "source/browse/"), // XXX
|
||||
"hg.latest": Class.Memoize(function () {
|
||||
return this.code + "source/browse/"; // XXX
|
||||
}),
|
||||
"irc": "irc://irc.oftc.net/#pentadactyl"
|
||||
}),
|
||||
|
||||
@@ -517,7 +526,10 @@ var ConfigBase = Class("ConfigBase", {
|
||||
return this.browser.mPanelContainer.boxObject.height;
|
||||
},
|
||||
|
||||
tabStrip: Class.Memoize(function () document.getElementById("TabsToolbar") || this.tabbrowser.mTabContainer)
|
||||
tabStrip: Class.Memoize(function () {
|
||||
return document.getElementById("TabsToolbar") ||
|
||||
this.tabbrowser.mTabContainer;
|
||||
})
|
||||
}),
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,9 @@ lazyRequire("overlay", ["overlay"]);
|
||||
lazyRequire("storage", ["File"]);
|
||||
lazyRequire("template", ["template"]);
|
||||
|
||||
var Const = function Const(val) Class.Property({ enumerable: true, value: val });
|
||||
var Const = function Const(val) {
|
||||
return Class.Property({ enumerable: true, value: val });
|
||||
};
|
||||
|
||||
var Group = Class("Group", {
|
||||
init: function init(name, description, filter, persist) {
|
||||
@@ -93,7 +95,9 @@ var Group = Class("Group", {
|
||||
});
|
||||
},
|
||||
|
||||
defaultFilter: Class.Memoize(function () this.compileFilter(["*"]))
|
||||
defaultFilter: Class.Memoize(function () {
|
||||
return this.compileFilter(["*"]);
|
||||
})
|
||||
});
|
||||
|
||||
var Contexts = Module("contexts", {
|
||||
@@ -204,13 +208,15 @@ var Contexts = Module("contexts", {
|
||||
});
|
||||
|
||||
memoize(contexts.hives, name,
|
||||
() => Object.create(Object.create(contexts.hiveProto,
|
||||
{ _hive: { value: name } })));
|
||||
() => Object.create(
|
||||
Object.create(contexts.hiveProto,
|
||||
{ _hive: { value: name } })));
|
||||
|
||||
memoize(contexts.groupsProto, name,
|
||||
function () [group[name]
|
||||
for (group of values(this.groups))
|
||||
if (hasOwnProperty(group, 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]; }
|
||||
@@ -397,11 +403,13 @@ var Contexts = Module("contexts", {
|
||||
return frame;
|
||||
},
|
||||
|
||||
groups: Class.Memoize(function () this.matchingGroups()),
|
||||
groups: Class.Memoize(function () { return this.matchingGroups(); }),
|
||||
|
||||
allGroups: Class.Memoize(function () Object.create(this.groupsProto, {
|
||||
groups: { value: this.initializedGroups() }
|
||||
})),
|
||||
allGroups: Class.Memoize(function () {
|
||||
return Object.create(this.groupsProto, {
|
||||
groups: { value: this.initializedGroups() }
|
||||
});
|
||||
}),
|
||||
|
||||
matchingGroups: function (uri) Object.create(this.groupsProto, {
|
||||
groups: { value: this.activeGroups(uri) }
|
||||
@@ -443,7 +451,9 @@ var Contexts = Module("contexts", {
|
||||
group = this.Group(name, description, filter, persist);
|
||||
this.groupList.unshift(group);
|
||||
this.groupMap[name] = group;
|
||||
this.hiveProto.__defineGetter__(name, function () group[this._hive]);
|
||||
this.hiveProto.__defineGetter__(name, function () {
|
||||
return group[this._hive];
|
||||
});
|
||||
}
|
||||
|
||||
if (replace) {
|
||||
@@ -553,9 +563,11 @@ var Contexts = Module("contexts", {
|
||||
break;
|
||||
|
||||
case "-ex":
|
||||
action = function action() modules.commands
|
||||
.execute(action.macro, makeParams(this, arguments),
|
||||
false, null, action.context);
|
||||
action = function action() {
|
||||
return modules.commands
|
||||
.execute(action.macro, makeParams(this, arguments),
|
||||
false, null, action.context);
|
||||
};
|
||||
action.macro = util.compileMacro(rhs, true);
|
||||
action.context = this.context && update({}, this.context);
|
||||
break;
|
||||
@@ -571,7 +583,9 @@ var Contexts = Module("contexts", {
|
||||
break;
|
||||
}
|
||||
|
||||
action.toString = function toString() (type === default_ ? "" : type + " ") + rhs;
|
||||
action.toString = function toString() {
|
||||
return (type === default_ ? "" : type + " ") + rhs;
|
||||
};
|
||||
args = null;
|
||||
return action;
|
||||
},
|
||||
@@ -608,7 +622,9 @@ var Contexts = Module("contexts", {
|
||||
get persist() { return this.group.persist; },
|
||||
set persist(val) { this.group.persist = val; },
|
||||
|
||||
prefix: Class.Memoize(function () this.name === "builtin" ? "" : this.name + ":"),
|
||||
prefix: Class.Memoize(function () {
|
||||
return this.name === "builtin" ? "" : this.name + ":";
|
||||
}),
|
||||
|
||||
get toStringParams() { return [this.name]; }
|
||||
})
|
||||
|
||||
@@ -150,7 +150,7 @@ var DOM = Class("DOM", {
|
||||
}
|
||||
|
||||
if (DOM.isJSONXML(val))
|
||||
val = (function () this).bind(val);
|
||||
val = (function () { return this; }).bind(val);
|
||||
|
||||
if (callable(val))
|
||||
return this.each(function (elem, i) {
|
||||
@@ -539,8 +539,10 @@ var DOM = Class("DOM", {
|
||||
|
||||
let encodeComponent = encodeURIComponent;
|
||||
if (charset !== "UTF-8")
|
||||
encodeComponent = function encodeComponent(str)
|
||||
escape(converter.ConvertFromUnicode(str) + converter.Finish());
|
||||
encodeComponent = function encodeComponent(str) {
|
||||
return escape(converter.ConvertFromUnicode(str) +
|
||||
converter.Finish());
|
||||
};
|
||||
|
||||
let elems = [];
|
||||
if (field instanceof Ci.nsIDOMHTMLInputElement && field.type == "submit")
|
||||
@@ -1122,12 +1124,22 @@ var DOM = Class("DOM", {
|
||||
return this;
|
||||
},
|
||||
|
||||
code_key: Class.Memoize(function (prop) this.init()[prop]),
|
||||
code_nativeKey: Class.Memoize(function (prop) this.init()[prop]),
|
||||
keyTable: Class.Memoize(function (prop) this.init()[prop]),
|
||||
key_code: Class.Memoize(function (prop) this.init()[prop]),
|
||||
key_key: Class.Memoize(function (prop) this.init()[prop]),
|
||||
pseudoKeys: new RealSet(["count", "leader", "nop", "pass"]),
|
||||
code_key: Class.Memoize(function (prop) {
|
||||
return this.init()[prop];
|
||||
}),
|
||||
code_nativeKey: Class.Memoize(function (prop) {
|
||||
return this.init()[prop];
|
||||
}),
|
||||
keyTable: Class.Memoize(function (prop) {
|
||||
return this.init()[prop];
|
||||
}),
|
||||
key_code: Class.Memoize(function (prop) {
|
||||
return this.init()[prop];
|
||||
}),
|
||||
key_key: Class.Memoize(function (prop) {
|
||||
return this.init()[prop];
|
||||
}),
|
||||
pseudoKeys: new RealSet(["count", "leader", "nop", "pass"]),
|
||||
|
||||
/**
|
||||
* Converts a user-input string of keys into a canonical
|
||||
@@ -1927,8 +1939,10 @@ var DOM = Class("DOM", {
|
||||
dactyl: NS
|
||||
},
|
||||
|
||||
namespaceNames: Class.Memoize(function ()
|
||||
iter(this.namespaces).map(([k, v]) => ([v, k])).toObject())
|
||||
namespaceNames: Class.Memoize(function () {
|
||||
return iter(this.namespaces).map(([k, v]) => ([v, k]))
|
||||
.toObject();
|
||||
})
|
||||
});
|
||||
|
||||
Object.keys(DOM.Event.types).forEach(function (event) {
|
||||
|
||||
@@ -750,7 +750,9 @@ var RangeFind = Class("RangeFind", {
|
||||
this.save();
|
||||
},
|
||||
|
||||
docShell: Class.Memoize(function () util.docShell(this.window)),
|
||||
docShell: Class.Memoize(function () {
|
||||
return util.docShell(this.window);
|
||||
}),
|
||||
|
||||
intersects: function (range) RangeFind.intersects(this.range, range),
|
||||
|
||||
|
||||
@@ -80,14 +80,15 @@ var Help = Module("Help", {
|
||||
init: function init() {
|
||||
this.initialized = false;
|
||||
|
||||
function Loop(fn)
|
||||
function (uri, path) {
|
||||
function Loop(fn) {
|
||||
return function (uri, path) {
|
||||
if (!help.initialized)
|
||||
return RedirectChannel(uri.spec, uri, 2,
|
||||
"Initializing. Please wait...");
|
||||
|
||||
return fn.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
update(services["dactyl:"].providers, {
|
||||
"help": Loop((uri, path) => help.files[path]),
|
||||
|
||||
@@ -17,7 +17,9 @@ var Highlight = Struct("class", "selector", "sites",
|
||||
"value", "extends", "agent",
|
||||
"base", "baseClass", "style");
|
||||
Highlight.liveProperty = function (name, prop) {
|
||||
this.prototype.__defineGetter__(name, function () this.get(name));
|
||||
this.prototype.__defineGetter__(name, function () {
|
||||
return this.get(name);
|
||||
});
|
||||
this.prototype.__defineSetter__(name, function (val) {
|
||||
if (isObject(val) && name !== "style") {
|
||||
if (isArray(val))
|
||||
@@ -45,22 +47,28 @@ Highlight.liveProperty("selector", "css");
|
||||
Highlight.liveProperty("sites");
|
||||
Highlight.liveProperty("style", "css");
|
||||
|
||||
Highlight.defaultValue("baseClass", function () /^(\w*)/.exec(this.class)[0]);
|
||||
Highlight.defaultValue("baseClass", function () {
|
||||
return /^(\w*)/.exec(this.class)[0];
|
||||
});
|
||||
|
||||
Highlight.defaultValue("selector", function () highlight.selector(this.class));
|
||||
Highlight.defaultValue("selector", function () {
|
||||
return highlight.selector(this.class);
|
||||
});
|
||||
|
||||
Highlight.defaultValue("sites", function ()
|
||||
this.base ? this.base.sites
|
||||
: ["resource://dactyl*", "dactyl:*", "file://*"].concat(
|
||||
highlight.styleableChrome));
|
||||
Highlight.defaultValue("sites", function () {
|
||||
return this.base ? this.base.sites
|
||||
: ["resource://dactyl*", "dactyl:*", "file://*"]
|
||||
.concat(highlight.styleableChrome);
|
||||
});
|
||||
|
||||
Highlight.defaultValue("style", function ()
|
||||
styles.system.add("highlight:" + this.class, this.sites, this.css, this.agent, true));
|
||||
Highlight.defaultValue("style", function () {
|
||||
return styles.system.add("highlight:" + this.class, this.sites, this.css, this.agent, true);
|
||||
});
|
||||
|
||||
Highlight.defaultValue("defaultExtends", () => []);
|
||||
Highlight.defaultValue("defaultValue", () => "");
|
||||
Highlight.defaultValue("extends", function () this.defaultExtends);
|
||||
Highlight.defaultValue("value", function () this.defaultValue);
|
||||
Highlight.defaultValue("extends", function () { return this.defaultExtends; });
|
||||
Highlight.defaultValue("value", function () { return this.defaultValue; });
|
||||
|
||||
update(Highlight.prototype, {
|
||||
get base() {
|
||||
|
||||
@@ -837,7 +837,9 @@ unlet s:cpo_save
|
||||
sep = sep || " ";
|
||||
let width = 0;
|
||||
let lines = [];
|
||||
lines.__defineGetter__("last", function () this[this.length - 1]);
|
||||
lines.__defineGetter__("last", function () {
|
||||
return this[this.length - 1];
|
||||
});
|
||||
|
||||
for (let item of values(items.array || items)) {
|
||||
if (item.length > width && (!lines.length || lines.last.length > 1)) {
|
||||
@@ -1056,7 +1058,9 @@ unlet s:cpo_save
|
||||
dir = dir.replace("/+$", "") + "/";
|
||||
completion.file(context, true, dir + context.filter);
|
||||
context.title[0] = dir;
|
||||
context.keys.text = function (f) this.path.substr(dir.length);
|
||||
context.keys.text = function (f) {
|
||||
return this.path.substr(dir.length);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -43,13 +43,17 @@ var JavaScript = Module("javascript", {
|
||||
}
|
||||
}),
|
||||
|
||||
globals: Class.Memoize(function () [
|
||||
[this.modules.userContext, /*L*/"Global Variables"],
|
||||
[this.modules, "modules"],
|
||||
[this.window, "window"]
|
||||
]),
|
||||
globals: Class.Memoize(function () {
|
||||
return [
|
||||
[this.modules.userContext, /*L*/"Global Variables"],
|
||||
[this.modules, "modules"],
|
||||
[this.window, "window"]
|
||||
];
|
||||
}),
|
||||
|
||||
toplevel: Class.Memoize(function () this.modules.jsmodules),
|
||||
toplevel: Class.Memoize(function () {
|
||||
return this.modules.jsmodules;
|
||||
}),
|
||||
|
||||
lazyInit: true,
|
||||
|
||||
@@ -358,7 +362,9 @@ var JavaScript = Module("javascript", {
|
||||
// Constants are unsorted, and appear before other non-null strings.
|
||||
// Other strings are sorted in the default manner.
|
||||
|
||||
let isnan = function isnan(item) item != '' && isNaN(item);
|
||||
let isnan = function isnan(item) {
|
||||
return item != '' && isNaN(item);
|
||||
};
|
||||
let compare = base.compare;
|
||||
|
||||
base.compare = function (a, b) {
|
||||
@@ -617,7 +623,10 @@ var JavaScript = Module("javascript", {
|
||||
return null;
|
||||
},
|
||||
|
||||
magicalNames: Class.Memoize(function () Object.getOwnPropertyNames(Cu.Sandbox(this.window), true).sort()),
|
||||
magicalNames: Class.Memoize(function () {
|
||||
return Object.getOwnPropertyNames(Cu.Sandbox(this.window), true)
|
||||
.sort();
|
||||
}),
|
||||
|
||||
/**
|
||||
* A list of properties of the global object which are not
|
||||
@@ -706,7 +715,7 @@ var JavaScript = Module("javascript", {
|
||||
modes.addMode("REPL", {
|
||||
description: "JavaScript Read Eval Print Loop",
|
||||
bases: [modes.COMMAND_LINE],
|
||||
displayName: Class.Memoize(function () this.name)
|
||||
displayName: Class.Memoize(function () { return this.name; })
|
||||
});
|
||||
},
|
||||
commandline: function initCommandLine(dactyl, modules, window) {
|
||||
|
||||
@@ -195,200 +195,202 @@ var Modules = function Modules(window) {
|
||||
config.loadStyles();
|
||||
|
||||
overlay.overlayWindow(Object.keys(config.overlays),
|
||||
function _overlay(window) ({
|
||||
ready: function onInit(document) {
|
||||
const modules = Modules(window);
|
||||
modules.moduleManager = this;
|
||||
this.modules = modules;
|
||||
this.jsmodules = modules.jsmodules;
|
||||
function _overlay(window) {
|
||||
return {
|
||||
ready: function onInit(document) {
|
||||
const modules = Modules(window);
|
||||
modules.moduleManager = this;
|
||||
this.modules = modules;
|
||||
this.jsmodules = modules.jsmodules;
|
||||
|
||||
window.dactyl = { modules: modules };
|
||||
window.dactyl = { modules: modules };
|
||||
|
||||
defineModule.time("load", null, function _load() {
|
||||
config.modules.global
|
||||
.forEach(function (name) {
|
||||
if (!isArray(name))
|
||||
defineModule.time("load", name, require, null, name, modules.jsmodules);
|
||||
else
|
||||
lazyRequire(name[0], name.slice(1), modules.jsmodules);
|
||||
});
|
||||
defineModule.time("load", null, function _load() {
|
||||
config.modules.global
|
||||
.forEach(function (name) {
|
||||
if (!isArray(name))
|
||||
defineModule.time("load", name, require, null, name, modules.jsmodules);
|
||||
else
|
||||
lazyRequire(name[0], name.slice(1), modules.jsmodules);
|
||||
});
|
||||
|
||||
config.modules.window
|
||||
.forEach(name => { defineModule.time("load", name, modules.load, modules, name); });
|
||||
}, this);
|
||||
},
|
||||
config.modules.window
|
||||
.forEach(name => { defineModule.time("load", name, modules.load, modules, name); });
|
||||
}, this);
|
||||
},
|
||||
|
||||
load: function onLoad(document) {
|
||||
let self = this;
|
||||
load: function onLoad(document) {
|
||||
let self = this;
|
||||
|
||||
var { modules } = this.modules;
|
||||
delete window.dactyl;
|
||||
var { modules } = this.modules;
|
||||
delete window.dactyl;
|
||||
|
||||
this.startTime = Date.now();
|
||||
this.deferredInit = { load: {} };
|
||||
this.seen = new RealSet;
|
||||
this.loaded = new RealSet;
|
||||
modules.loaded = this.loaded;
|
||||
this.startTime = Date.now();
|
||||
this.deferredInit = { load: {} };
|
||||
this.seen = new RealSet;
|
||||
this.loaded = new RealSet;
|
||||
modules.loaded = this.loaded;
|
||||
|
||||
this.modules = modules;
|
||||
this.modules = modules;
|
||||
|
||||
this.scanModules();
|
||||
this.initDependencies("init");
|
||||
this.scanModules();
|
||||
this.initDependencies("init");
|
||||
|
||||
modules.config.scripts.forEach(modules.load);
|
||||
modules.config.scripts.forEach(modules.load);
|
||||
|
||||
this.scanModules();
|
||||
this.scanModules();
|
||||
|
||||
defineModule.modules.forEach(function defModule({ lazyInit, constructor: { className } }) {
|
||||
if (!lazyInit) {
|
||||
Class.replaceProperty(modules, className, modules[className]);
|
||||
this.initDependencies(className);
|
||||
}
|
||||
else
|
||||
modules.__defineGetter__(className, () => {
|
||||
let module = modules.jsmodules[className];
|
||||
Class.replaceProperty(modules, className, module);
|
||||
if (module.reallyInit)
|
||||
module.reallyInit(); // :(
|
||||
|
||||
if (!module.lazyDepends)
|
||||
self.initDependencies(className);
|
||||
return module;
|
||||
});
|
||||
}, this);
|
||||
},
|
||||
|
||||
cleanup: function cleanup(window) {
|
||||
overlay.windows.delete(window);
|
||||
|
||||
JSMLoader.atexit(() => {
|
||||
Cu.nukeSandbox(this.jsmodules);
|
||||
});
|
||||
},
|
||||
|
||||
unload: function unload(window) {
|
||||
for (let mod of this.modules.moduleList.reverse()) {
|
||||
mod.stale = true;
|
||||
|
||||
if ("destroy" in mod)
|
||||
util.trapErrors("destroy", mod);
|
||||
}
|
||||
},
|
||||
|
||||
visible: function visible(window) {
|
||||
// Module.list.forEach(load);
|
||||
this.initDependencies("load");
|
||||
this.modules.times = update({}, defineModule.times);
|
||||
|
||||
defineModule.loadLog.push("Loaded in " + (Date.now() - this.startTime) + "ms");
|
||||
|
||||
overlay.windows.add(window);
|
||||
},
|
||||
|
||||
loadModule: function loadModule(module, prereq, frame) {
|
||||
let { loaded, seen } = this;
|
||||
let { Module, modules } = this.modules;
|
||||
|
||||
if (isString(module)) {
|
||||
if (!Module.constructors.hasOwnProperty(module))
|
||||
modules.load(module);
|
||||
module = Module.constructors[module];
|
||||
}
|
||||
|
||||
try {
|
||||
if (loaded.has(module.className))
|
||||
return;
|
||||
|
||||
if (seen.add(module.className))
|
||||
throw Error("Module dependency loop.");
|
||||
|
||||
for (let dep of module.requires)
|
||||
this.loadModule(Module.constructors[dep], module.className);
|
||||
|
||||
defineModule.loadLog.push(
|
||||
"Load" + (isString(prereq) ? " " + prereq + " dependency: " : ": ")
|
||||
+ module.className);
|
||||
|
||||
if (frame && frame.filename)
|
||||
defineModule.loadLog.push(" from: " + util.fixURI(frame.filename) + ":" + frame.lineNumber);
|
||||
|
||||
let obj = defineModule.time(module.className, "init", module);
|
||||
Class.replaceProperty(modules, module.className, obj);
|
||||
|
||||
loaded.add(module.className);
|
||||
|
||||
if (loaded.has("dactyl") && obj.signals)
|
||||
modules.dactyl.registerObservers(obj);
|
||||
|
||||
if (!module.lazyDepends)
|
||||
this.initDependencies(module.className);
|
||||
}
|
||||
catch (e) {
|
||||
util.dump("Loading " + (module && module.className) + ":");
|
||||
util.reportError(e);
|
||||
}
|
||||
return modules[module.className];
|
||||
},
|
||||
|
||||
deferInit: function deferInit(name, INIT, mod) {
|
||||
let { modules } = this.modules;
|
||||
|
||||
let init = this.deferredInit[name] || {};
|
||||
this.deferredInit[name] = init;
|
||||
|
||||
let className = mod.className || mod.constructor.className;
|
||||
|
||||
if (!hasOwnProperty(init, className)) {
|
||||
init[className] = function callee() {
|
||||
function finish() {
|
||||
this.currentDependency = className;
|
||||
defineModule.time(className, name, INIT[name], mod,
|
||||
modules.dactyl, modules, window);
|
||||
defineModule.modules.forEach(function defModule({ lazyInit, constructor: { className } }) {
|
||||
if (!lazyInit) {
|
||||
Class.replaceProperty(modules, className, modules[className]);
|
||||
this.initDependencies(className);
|
||||
}
|
||||
if (!callee.frobbed) {
|
||||
callee.frobbed = true;
|
||||
if (modules[name] instanceof Class)
|
||||
modules[name].withSavedValues(["currentDependency"], finish);
|
||||
else
|
||||
finish.call({});
|
||||
}
|
||||
};
|
||||
else
|
||||
modules.__defineGetter__(className, () => {
|
||||
let module = modules.jsmodules[className];
|
||||
Class.replaceProperty(modules, className, module);
|
||||
if (module.reallyInit)
|
||||
module.reallyInit(); // :(
|
||||
|
||||
INIT[name].require = name => { init[name](); };
|
||||
}
|
||||
},
|
||||
if (!module.lazyDepends)
|
||||
self.initDependencies(className);
|
||||
return module;
|
||||
});
|
||||
}, this);
|
||||
},
|
||||
|
||||
scanModules: function scanModules() {
|
||||
let { Module, modules } = this.modules;
|
||||
cleanup: function cleanup(window) {
|
||||
overlay.windows.delete(window);
|
||||
|
||||
defineModule.modules.forEach(mod => {
|
||||
let names = new RealSet(Object.keys(mod.INIT));
|
||||
if ("init" in mod.INIT)
|
||||
names.add("init");
|
||||
JSMLoader.atexit(() => {
|
||||
Cu.nukeSandbox(this.jsmodules);
|
||||
});
|
||||
},
|
||||
|
||||
for (let name of names)
|
||||
this.deferInit(name, mod.INIT, mod);
|
||||
});
|
||||
unload: function unload(window) {
|
||||
for (let mod of this.modules.moduleList.reverse()) {
|
||||
mod.stale = true;
|
||||
|
||||
Module.list.forEach(mod => {
|
||||
if (!mod.frobbed) {
|
||||
modules.__defineGetter__(mod.className, () => {
|
||||
delete modules[mod.className];
|
||||
return this.loadModule(mod.className, null, Components.stack.caller);
|
||||
});
|
||||
Object.keys(mod.prototype.INIT)
|
||||
.forEach(name => { this.deferInit(name, mod.prototype.INIT, mod); });
|
||||
if ("destroy" in mod)
|
||||
util.trapErrors("destroy", mod);
|
||||
}
|
||||
mod.frobbed = true;
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
initDependencies: function initDependencies(name, parents) {
|
||||
for (let [k, v] of iter(this.deferredInit[name] || {}))
|
||||
if (!parents || ~parents.indexOf(k))
|
||||
util.trapErrors(v);
|
||||
}
|
||||
}));
|
||||
visible: function visible(window) {
|
||||
// Module.list.forEach(load);
|
||||
this.initDependencies("load");
|
||||
this.modules.times = update({}, defineModule.times);
|
||||
|
||||
defineModule.loadLog.push("Loaded in " + (Date.now() - this.startTime) + "ms");
|
||||
|
||||
overlay.windows.add(window);
|
||||
},
|
||||
|
||||
loadModule: function loadModule(module, prereq, frame) {
|
||||
let { loaded, seen } = this;
|
||||
let { Module, modules } = this.modules;
|
||||
|
||||
if (isString(module)) {
|
||||
if (!Module.constructors.hasOwnProperty(module))
|
||||
modules.load(module);
|
||||
module = Module.constructors[module];
|
||||
}
|
||||
|
||||
try {
|
||||
if (loaded.has(module.className))
|
||||
return;
|
||||
|
||||
if (seen.add(module.className))
|
||||
throw Error("Module dependency loop.");
|
||||
|
||||
for (let dep of module.requires)
|
||||
this.loadModule(Module.constructors[dep], module.className);
|
||||
|
||||
defineModule.loadLog.push(
|
||||
"Load" + (isString(prereq) ? " " + prereq + " dependency: " : ": ")
|
||||
+ module.className);
|
||||
|
||||
if (frame && frame.filename)
|
||||
defineModule.loadLog.push(" from: " + util.fixURI(frame.filename) + ":" + frame.lineNumber);
|
||||
|
||||
let obj = defineModule.time(module.className, "init", module);
|
||||
Class.replaceProperty(modules, module.className, obj);
|
||||
|
||||
loaded.add(module.className);
|
||||
|
||||
if (loaded.has("dactyl") && obj.signals)
|
||||
modules.dactyl.registerObservers(obj);
|
||||
|
||||
if (!module.lazyDepends)
|
||||
this.initDependencies(module.className);
|
||||
}
|
||||
catch (e) {
|
||||
util.dump("Loading " + (module && module.className) + ":");
|
||||
util.reportError(e);
|
||||
}
|
||||
return modules[module.className];
|
||||
},
|
||||
|
||||
deferInit: function deferInit(name, INIT, mod) {
|
||||
let { modules } = this.modules;
|
||||
|
||||
let init = this.deferredInit[name] || {};
|
||||
this.deferredInit[name] = init;
|
||||
|
||||
let className = mod.className || mod.constructor.className;
|
||||
|
||||
if (!hasOwnProperty(init, className)) {
|
||||
init[className] = function callee() {
|
||||
function finish() {
|
||||
this.currentDependency = className;
|
||||
defineModule.time(className, name, INIT[name], mod,
|
||||
modules.dactyl, modules, window);
|
||||
}
|
||||
if (!callee.frobbed) {
|
||||
callee.frobbed = true;
|
||||
if (modules[name] instanceof Class)
|
||||
modules[name].withSavedValues(["currentDependency"], finish);
|
||||
else
|
||||
finish.call({});
|
||||
}
|
||||
};
|
||||
|
||||
INIT[name].require = name => { init[name](); };
|
||||
}
|
||||
},
|
||||
|
||||
scanModules: function scanModules() {
|
||||
let { Module, modules } = this.modules;
|
||||
|
||||
defineModule.modules.forEach(mod => {
|
||||
let names = new RealSet(Object.keys(mod.INIT));
|
||||
if ("init" in mod.INIT)
|
||||
names.add("init");
|
||||
|
||||
for (let name of names)
|
||||
this.deferInit(name, mod.INIT, mod);
|
||||
});
|
||||
|
||||
Module.list.forEach(mod => {
|
||||
if (!mod.frobbed) {
|
||||
modules.__defineGetter__(mod.className, () => {
|
||||
delete modules[mod.className];
|
||||
return this.loadModule(mod.className, null, Components.stack.caller);
|
||||
});
|
||||
Object.keys(mod.prototype.INIT)
|
||||
.forEach(name => { this.deferInit(name, mod.prototype.INIT, mod); });
|
||||
}
|
||||
mod.frobbed = true;
|
||||
});
|
||||
},
|
||||
|
||||
initDependencies: function initDependencies(name, parents) {
|
||||
for (let [k, v] of iter(this.deferredInit[name] || {}))
|
||||
if (!parents || ~parents.indexOf(k))
|
||||
util.trapErrors(v);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
endModule();
|
||||
|
||||
|
||||
@@ -39,22 +39,26 @@ var Messages = Module("messages", {
|
||||
services.stringBundle.flushBundles();
|
||||
},
|
||||
|
||||
bundles: Class.Memoize(function ()
|
||||
Ary.uniq([JSMLoader.getTarget("dactyl://locale/" + this.name + ".properties"),
|
||||
JSMLoader.getTarget("dactyl://locale-local/" + this.name + ".properties"),
|
||||
"resource://dactyl-locale/en-US/" + this.name + ".properties",
|
||||
"resource://dactyl-locale-local/en-US/" + this.name + ".properties"],
|
||||
true)
|
||||
.map(services.stringBundle.createBundle)
|
||||
.filter(function (bundle) {
|
||||
try {
|
||||
bundle.getSimpleEnumeration();
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
})),
|
||||
bundles: Class.Memoize(function () {
|
||||
let urls = [
|
||||
JSMLoader.getTarget("dactyl://locale/"),
|
||||
JSMLoader.getTarget("dactyl://locale-local/"),
|
||||
"resource://dactyl-locale/en-US/",
|
||||
"resource://dactyl-locale-local/en-US/"
|
||||
].map(url => url + this.name + ".properties");
|
||||
|
||||
return Ary.uniq(urls, true)
|
||||
.map(services.stringBundle.createBundle)
|
||||
.filter(bundle => {
|
||||
try {
|
||||
bundle.getSimpleEnumeration();
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}),
|
||||
|
||||
iterate: function* () {
|
||||
let seen = new RealSet;
|
||||
@@ -166,7 +170,10 @@ var Messages = Module("messages", {
|
||||
let value = this[_prop];
|
||||
|
||||
function getter(key, default_) {
|
||||
return function getter() messages.get([name, key].join("."), default_);
|
||||
return function getter() {
|
||||
return messages.get([name, key].join("."),
|
||||
default_);
|
||||
};
|
||||
}
|
||||
|
||||
if (value != null) {
|
||||
|
||||
@@ -272,7 +272,7 @@ var Option = Class("Option", {
|
||||
name: null,
|
||||
|
||||
/** @property {[string]} All names by which this option is identified. */
|
||||
names: Class.Memoize(function () this.realNames),
|
||||
names: Class.Memoize(function () { return this.realNames; }),
|
||||
|
||||
/**
|
||||
* @property {string} The option's data type. One of:
|
||||
@@ -461,7 +461,9 @@ var Option = Class("Option", {
|
||||
re.bang = bang;
|
||||
re.result = result !== undefined ? result : !bang;
|
||||
re.key = re.bang + Option.quote(util.regexp.getSource(re), /^!|:/);
|
||||
re.toString = function () Option.unparseRegexp(this, keepQuotes);
|
||||
re.toString = function () {
|
||||
return Option.unparseRegexp(this, keepQuotes);
|
||||
};
|
||||
return re;
|
||||
},
|
||||
|
||||
@@ -705,15 +707,21 @@ var Option = Class("Option", {
|
||||
// NOTE: Vim doesn't prepend if there's a match in the current value
|
||||
return uniq(Array.concat(values, this.value), true);
|
||||
case "-":
|
||||
return this.value.filter(function (item) !this.has(item), new RealSet(values));
|
||||
return this.value.filter(function (item) {
|
||||
return !this.has(item), new RealSet(values);
|
||||
});
|
||||
case "=":
|
||||
if (invert) {
|
||||
let old = this.value.map(String);
|
||||
let new_ = values.map(String);
|
||||
let map = Ary(this.value).concat(values).map(val => [String(val), val]).toObject();
|
||||
|
||||
let keepValues = old.filter(function (item) !this.has(item), new RealSet(new_));
|
||||
let addValues = new_.filter(function (item) !this.has(item), new RealSet(old));
|
||||
let keepValues = old.filter(function (item) {
|
||||
return !this.has(item);
|
||||
}, new RealSet(new_));
|
||||
let addValues = new_.filter(function (item) {
|
||||
return !this.has(item);
|
||||
}, new RealSet(old));
|
||||
return addValues.concat(keepValues).map(s => map[s]);
|
||||
}
|
||||
return values;
|
||||
@@ -816,8 +824,9 @@ var Option = Class("Option", {
|
||||
}, this);
|
||||
|
||||
update(BooleanOption.prototype, {
|
||||
names: Class.Memoize(function ()
|
||||
Ary.flatten([[name, "no" + name] for (name of this.realNames)]))
|
||||
names: Class.Memoize(function () {
|
||||
return Ary.flatten([[name, "no" + name] for (name of this.realNames)]);
|
||||
})
|
||||
});
|
||||
|
||||
var OptionHive = Class("OptionHive", Contexts.Hive, {
|
||||
@@ -982,8 +991,12 @@ var Options = Module("options", {
|
||||
memoize(this._options, this._options.length, closure);
|
||||
|
||||
// quickly access options with options["wildmode"]:
|
||||
this.__defineGetter__(name, function () this._optionMap[name].value);
|
||||
this.__defineSetter__(name, function (value) { this._optionMap[name].value = value; });
|
||||
this.__defineGetter__(name, function () {
|
||||
return this._optionMap[name].value;
|
||||
});
|
||||
this.__defineSetter__(name, function (value) {
|
||||
this._optionMap[name].value = value;
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
@@ -211,23 +211,28 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
|
||||
filter = filter.trim();
|
||||
|
||||
if (filter === "*")
|
||||
var test = function test(uri) true;
|
||||
var test = function test(uri) { return true; };
|
||||
else if (!/^(?:[a-z-]+:|[a-z-.]+$)/.test(filter)) {
|
||||
let re = util.regexp(filter);
|
||||
test = function test(uri) re.test(uri.spec);
|
||||
test = function test(uri) { return re.test(uri.spec); };
|
||||
}
|
||||
else if (/[*]$/.test(filter)) {
|
||||
let re = RegExp("^" + util.regexp.escape(filter.substr(0, filter.length - 1)));
|
||||
test = function test(uri) re.test(uri.spec);
|
||||
test = function test(uri) { return re.test(uri.spec); };
|
||||
test.re = re;
|
||||
}
|
||||
else if (/[\/:]/.test(filter)) {
|
||||
test = function test(uri) uri.spec === filter;
|
||||
test = function test(uri) { return uri.spec === filter; };
|
||||
test.exact = true;
|
||||
}
|
||||
else
|
||||
test = function test(uri) { try { return util.isSubdomain(uri.host, filter); } catch (e) { return false; } };
|
||||
test.toString = function toString() filter;
|
||||
test = function test(uri) {
|
||||
try {
|
||||
return util.isSubdomain(uri.host, filter);
|
||||
}
|
||||
catch (e) { return false; }
|
||||
};
|
||||
test.toString = function toString() { return filter; };
|
||||
test.key = filter;
|
||||
}
|
||||
if (arguments.length < 2)
|
||||
@@ -417,7 +422,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
|
||||
|
||||
delete desc.value;
|
||||
delete desc.writable;
|
||||
desc.get = function get() value;
|
||||
desc.get = function get() { return value; }
|
||||
desc.set = function set(val) {
|
||||
if (!callable(val) || !Function.prototype.toString(val).contains(sentinel))
|
||||
Class.replaceProperty(this, k, val);
|
||||
@@ -434,8 +439,14 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
|
||||
|
||||
if (callable(value)) {
|
||||
var sentinel = "(function DactylOverlay() {}())";
|
||||
value.toString = function toString() toString.toString.call(this).replace(/\}?$/, sentinel + "; $&");
|
||||
value.toSource = function toSource() toSource.toSource.call(this).replace(/\}?$/, sentinel + "; $&");
|
||||
value.toString = function toString() {
|
||||
return toString.toString.call(this)
|
||||
.replace(/\}?$/, sentinel + "; $&");
|
||||
};
|
||||
value.toSource = function toSource() {
|
||||
return toSource.toSource.call(this)
|
||||
.replace(/\}?$/, sentinel + "; $&");
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
@@ -219,11 +219,12 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
if (this._prefContexts.length)
|
||||
this._prefContexts[this._prefContexts.length - 1][name] = this.get(name, null);
|
||||
|
||||
function assertType(needType)
|
||||
util.assert(type === Ci.nsIPrefBranch.PREF_INVALID || type === needType,
|
||||
function assertType(needType) {
|
||||
return util.assert(type === Ci.nsIPrefBranch.PREF_INVALID || type === needType,
|
||||
type === Ci.nsIPrefBranch.PREF_INT
|
||||
? /*L*/"E521: Number required after =: " + name + "=" + value
|
||||
: /*L*/"E474: Invalid argument: " + name + "=" + value);
|
||||
}
|
||||
|
||||
let type = this.branch.getPrefType(name);
|
||||
try {
|
||||
@@ -434,8 +435,14 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
};
|
||||
},
|
||||
javascript: function init_javascript(dactyl, modules) {
|
||||
modules.JavaScript.setCompleter([this.get, this.safeSet, this.set, this.reset, this.toggle],
|
||||
[function (context) (context.anchored=false, this.getNames().map(pref => [pref, ""]))]);
|
||||
const { setCompleter } = modules.JavaScript;
|
||||
|
||||
setCompleter([this.get, this.safeSet, this.set,
|
||||
this.reset, this.toggle],
|
||||
[function (context) {
|
||||
context.anchored=false;
|
||||
return this.getNames().map(pref => [pref, ""]);
|
||||
}]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -233,33 +233,35 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
||||
let branch = Item.PREFIX + Item.BRANCH;
|
||||
|
||||
overlay.overlayWindow("chrome://browser/content/sanitize.xul",
|
||||
function (win) prefOverlay(branch, false, {
|
||||
append: {
|
||||
itemList: [
|
||||
["listitem", { xmlns: "xul", label: /*L*/"See :help privacy for the following:",
|
||||
disabled: "true", style: "font-style: italic; font-weight: bold;" }],
|
||||
template.map(ourItems(), ([item, desc]) =>
|
||||
["listitem", { xmlns: "xul", preference: branch + item,
|
||||
type: "checkbox", label: config.appName + ", " + desc,
|
||||
onsyncfrompreference: "return gSanitizePromptDialog.onReadGeneric();" }])
|
||||
]
|
||||
},
|
||||
ready: function ready(win) {
|
||||
let elem = win.document.getElementById("itemList");
|
||||
elem.setAttribute("rows", elem.itemCount);
|
||||
win.Sanitizer = Class("Sanitizer", win.Sanitizer, {
|
||||
sanitize: function sanitize() {
|
||||
self.withSavedValues(["sanitizing"], function () {
|
||||
self.sanitizing = true;
|
||||
sanitize.superapply(this, arguments);
|
||||
sanitizer.sanitizeItems([item.name for (item of values(self.itemMap))
|
||||
if (item.shouldSanitize(false))],
|
||||
Range.fromArray(this.range || []));
|
||||
}, this);
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
function (win) {
|
||||
return prefOverlay(branch, false, {
|
||||
append: {
|
||||
itemList: [
|
||||
["listitem", { xmlns: "xul", label: /*L*/"See :help privacy for the following:",
|
||||
disabled: "true", style: "font-style: italic; font-weight: bold;" }],
|
||||
template.map(ourItems(), ([item, desc]) =>
|
||||
["listitem", { xmlns: "xul", preference: branch + item,
|
||||
type: "checkbox", label: config.appName + ", " + desc,
|
||||
onsyncfrompreference: "return gSanitizePromptDialog.onReadGeneric();" }])
|
||||
]
|
||||
},
|
||||
ready: function ready(win) {
|
||||
let elem = win.document.getElementById("itemList");
|
||||
elem.setAttribute("rows", elem.itemCount);
|
||||
win.Sanitizer = Class("Sanitizer", win.Sanitizer, {
|
||||
sanitize: function sanitize() {
|
||||
self.withSavedValues(["sanitizing"], function () {
|
||||
self.sanitizing = true;
|
||||
sanitize.superapply(this, arguments);
|
||||
sanitizer.sanitizeItems([item.name for (item of values(self.itemMap))
|
||||
if (item.shouldSanitize(false))],
|
||||
Range.fromArray(this.range || []));
|
||||
}, this);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -394,7 +396,9 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
||||
session: 8
|
||||
},
|
||||
|
||||
UNPERMS: Class.Memoize(function () iter(this.PERMS).map(Array.reverse).toObject()),
|
||||
UNPERMS: Class.Memoize(function () {
|
||||
return iter(this.PERMS).map(Array.reverse).toObject();
|
||||
}),
|
||||
|
||||
COMMANDS: {
|
||||
"unset": /*L*/"Unset",
|
||||
|
||||
@@ -178,10 +178,13 @@ var Services = Module("Services", {
|
||||
addClass: function addClass(name, class_, ifaces, init, quiet) {
|
||||
this.services[name] = { class: class_, interfaces: Array.concat(ifaces || []), method: "createInstance", init: init, quiet: quiet };
|
||||
if (init)
|
||||
memoize(this.services[name], "callable",
|
||||
function () callable(XPCOMShim(this.interfaces)[this.init]));
|
||||
memoize(this.services[name], "callable", function () {
|
||||
return callable(XPCOMShim(this.interfaces)[this.init]);
|
||||
});
|
||||
|
||||
this[name] = (function Create() this._create(name, arguments)).bind(this);
|
||||
this[name] = (function Create() {
|
||||
return this._create(name, arguments);
|
||||
}).bind(this);
|
||||
update.apply(null, [this[name]].concat([Ci[i] for (i of Array.concat(ifaces))]));
|
||||
return this[name];
|
||||
},
|
||||
|
||||
@@ -289,7 +289,9 @@ var Storage = Module("Storage", {
|
||||
|
||||
this.keys[key] = new constructor(key, params.store, load, params);
|
||||
this.keys[key].timer = new Timer(1000, 10000, () => this.save(key));
|
||||
this.__defineGetter__(key, function () this.keys[key]);
|
||||
this.__defineGetter__(key, function () {
|
||||
return this.keys[key];
|
||||
});
|
||||
}
|
||||
return this.keys[key];
|
||||
},
|
||||
@@ -698,13 +700,18 @@ var File = Class("File", {
|
||||
*/
|
||||
PATH_SEP: Class.Memoize(() => /foo(.)bar/.exec(OS.Path.join("foo", "bar"))[1]),
|
||||
|
||||
pathSplit: Class.Memoize(function () util.regexp("[/" + util.regexp.escape(this.PATH_SEP) + "]", "g")),
|
||||
pathSplit: Class.Memoize(function () {
|
||||
return util.regexp("[/" + util.regexp.escape(this.PATH_SEP) + "]",
|
||||
"g");
|
||||
}),
|
||||
|
||||
DoesNotExist: function DoesNotExist(path, error) ({
|
||||
__proto__: DoesNotExist.prototype,
|
||||
path: path,
|
||||
exists: function () false,
|
||||
__noSuchMethod__: function () { throw error || Error("Does not exist"); }
|
||||
__noSuchMethod__: function () {
|
||||
throw error || Error("Does not exist");
|
||||
}
|
||||
}),
|
||||
|
||||
defaultEncoding: "UTF-8",
|
||||
@@ -827,7 +834,9 @@ var File = Class("File", {
|
||||
catch (e) {}
|
||||
|
||||
if (isFunction)
|
||||
File.prototype[prop] = util.wrapCallback(function wrapper() apply(this.file, prop, arguments));
|
||||
File.prototype[prop] = util.wrapCallback(function wrapper() {
|
||||
return apply(this.file, prop, arguments);
|
||||
});
|
||||
else
|
||||
Object.defineProperty(File.prototype, prop, {
|
||||
configurable: true,
|
||||
|
||||
@@ -19,7 +19,7 @@ var namespace = "@namespace html " + JSON.stringify(XHTML) + ";\n" +
|
||||
var Sheet = Struct("name", "id", "sites", "css", "hive", "agent");
|
||||
Sheet.liveProperty = function (name) {
|
||||
let i = this.prototype.members[name];
|
||||
this.prototype.__defineGetter__(name, function () this[i]);
|
||||
this.prototype.__defineGetter__(name, function () { return this[i]; });
|
||||
this.prototype.__defineSetter__(name, function (val) {
|
||||
if (isArray(val))
|
||||
val = Array.slice(val);
|
||||
@@ -322,12 +322,13 @@ var Styles = Module("Styles", {
|
||||
|
||||
hives = hives || styles.hives.filter(h => (h.modifiable && h.sheets.length));
|
||||
|
||||
function sheets(group)
|
||||
group.sheets.slice()
|
||||
.filter(sheet => ((!name || sheet.name === name) &&
|
||||
(!sites || sites.every(s => sheet.sites.indexOf(s) >= 0))))
|
||||
.sort((a, b) => (a.name && b.name ? String.localeCompare(a.name, b.name)
|
||||
: !!b.name - !!a.name || a.id - b.id));
|
||||
function sheets(group) {
|
||||
return group.sheets.slice()
|
||||
.filter(sheet => ((!name || sheet.name === name) &&
|
||||
(!sites || sites.every(s => sheet.sites.indexOf(s) >= 0))))
|
||||
.sort((a, b) => (a.name && b.name ? String.localeCompare(a.name, b.name)
|
||||
: !!b.name - !!a.name || a.id - b.id));
|
||||
}
|
||||
|
||||
let uris = util.visibleURIs(content);
|
||||
|
||||
@@ -414,8 +415,11 @@ var Styles = Module("Styles", {
|
||||
context.generate = () => values(group.sites);
|
||||
|
||||
context.keys.text = util.identity;
|
||||
context.keys.description = function (site) this.sheets.length + /*L*/" sheet" + (this.sheets.length == 1 ? "" : "s") + ": " +
|
||||
Ary.compact(this.sheets.map(s => s.name)).join(", ");
|
||||
context.keys.description = function (site) {
|
||||
return this.sheets.length + /*L*/" sheet" +
|
||||
(this.sheets.length == 1 ? "" : "s") + ": " +
|
||||
Ary.compact(this.sheets.map(s => s.name)).join(", ");
|
||||
};
|
||||
context.keys.sheets = site => group.sheets.filter(s => s.sites.indexOf(site) >= 0);
|
||||
context.keys.active = site => uris.some(Styles.matchFilter(site));
|
||||
|
||||
@@ -438,20 +442,25 @@ var Styles = Module("Styles", {
|
||||
filter = filter.trim();
|
||||
|
||||
if (filter === "*")
|
||||
var test = function test(uri) true;
|
||||
var test = function test(uri) { return true; };
|
||||
else if (!/^(?:[a-z-]+:|[a-z-.]+$)/.test(filter)) {
|
||||
let re = util.regexp(filter);
|
||||
test = function test(uri) re.test(uri.spec);
|
||||
test = function test(uri) { return re.test(uri.spec); };
|
||||
}
|
||||
else if (/[*]$/.test(filter)) {
|
||||
let re = RegExp("^" + util.regexp.escape(filter.substr(0, filter.length - 1)));
|
||||
test = function test(uri) re.test(uri.spec);
|
||||
test = function test(uri) { return re.test(uri.spec); };
|
||||
}
|
||||
else if (/[\/:]/.test(filter))
|
||||
test = function test(uri) uri.spec === filter;
|
||||
test = function test(uri) { return uri.spec === filter; };
|
||||
else
|
||||
test = function test(uri) { try { return util.isSubdomain(uri.host, filter); } catch (e) { return false; } };
|
||||
test.toString = function toString() filter;
|
||||
test = function test(uri) {
|
||||
try {
|
||||
return util.isSubdomain(uri.host, filter);
|
||||
}
|
||||
catch (e) { return false; }
|
||||
};
|
||||
test.toString = function toString() { return filter; }
|
||||
test.key = filter;
|
||||
if (arguments.length < 2)
|
||||
return test;
|
||||
|
||||
@@ -448,7 +448,7 @@ var Template = Module("Template", {
|
||||
// TODO: This might be mind-bogglingly slow. We'll see.
|
||||
return ["table", {},
|
||||
["tr", { highlight: "Title", align: "left" },
|
||||
this.map(headings, function (h)
|
||||
this.map(headings, h =>
|
||||
["th", {}, h])],
|
||||
this.map(iter, row =>
|
||||
["tr", {},
|
||||
|
||||
@@ -257,20 +257,21 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
|
||||
compileFormat: function compileFormat(format) {
|
||||
let stack = [frame()];
|
||||
stack.__defineGetter__("top", function () this[this.length - 1]);
|
||||
stack.__defineGetter__("top", function () {
|
||||
return this[this.length - 1];
|
||||
});
|
||||
|
||||
function frame() {
|
||||
return update(
|
||||
function _frame(obj)
|
||||
_frame === stack.top || _frame.valid(obj)
|
||||
? _frame.elements.map(e => callable(e) ? e(obj) : e)
|
||||
.join("")
|
||||
: "",
|
||||
{
|
||||
elements: [],
|
||||
seen: {},
|
||||
valid: function valid(obj) this.elements.every(e => !e.test || e.test(obj))
|
||||
});
|
||||
return update(function _frame(obj) {
|
||||
return _frame === stack.top || _frame.valid(obj)
|
||||
? _frame.elements.map(e => callable(e) ? e(obj) : e)
|
||||
.join("")
|
||||
: "";
|
||||
}, {
|
||||
elements: [],
|
||||
seen: new RealSet,
|
||||
valid: function valid(obj) this.elements.every(e => !e.test || e.test(obj))
|
||||
});
|
||||
}
|
||||
|
||||
let end = 0;
|
||||
@@ -341,24 +342,26 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
*/
|
||||
compileMacro: function compileMacro(macro, keepUnknown) {
|
||||
let stack = [frame()];
|
||||
stack.__defineGetter__("top", function () this[this.length - 1]);
|
||||
stack.__defineGetter__("top", function () {
|
||||
return this[this.length - 1];
|
||||
});
|
||||
|
||||
let unknown = util.identity;
|
||||
if (!keepUnknown)
|
||||
unknown = () => "";
|
||||
|
||||
// FIXME: duplicated in compileFormat
|
||||
function frame() {
|
||||
return update(
|
||||
function _frame(obj)
|
||||
_frame === stack.top || _frame.valid(obj)
|
||||
? _frame.elements.map(e => callable(e) ? e(obj) : e)
|
||||
.join("")
|
||||
: "",
|
||||
{
|
||||
elements: [],
|
||||
seen: new RealSet,
|
||||
valid: function valid(obj) this.elements.every(e => (!e.test || e.test(obj)))
|
||||
});
|
||||
return update(function _frame(obj) {
|
||||
return _frame === stack.top || _frame.valid(obj)
|
||||
? _frame.elements.map(e => callable(e) ? e(obj) : e)
|
||||
.join("")
|
||||
: "";
|
||||
}, {
|
||||
elements: [],
|
||||
seen: new RealSet,
|
||||
valid: function valid(obj) this.elements.every(e => !e.test || e.test(obj))
|
||||
});
|
||||
}
|
||||
|
||||
let defaults = { lt: "<", gt: ">" };
|
||||
@@ -394,9 +397,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
|
||||
let quote = util.identity;
|
||||
if (flags.has("q"))
|
||||
quote = function quote(obj) typeof obj === "number" ? obj : JSON.stringify(obj);
|
||||
quote = function quote(obj) {
|
||||
return typeof obj === "number" ? obj : JSON.stringify(obj);
|
||||
};
|
||||
if (flags.has("e"))
|
||||
quote = function quote(obj) "";
|
||||
quote = function quote(obj) { return ""; };
|
||||
|
||||
if (hasOwnProperty(defaults, name))
|
||||
stack.top.elements.push(quote(defaults[name]));
|
||||
@@ -879,7 +884,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
isDactyl: Class.Memoize(function () {
|
||||
let base = util.regexp.escape(Components.stack.filename.replace(/[^\/]+$/, ""));
|
||||
let re = RegExp("^(?:.* -> )?(?:resource://dactyl(?!-content/eval.js)|" + base + ")\\S+$");
|
||||
return function isDactyl(frame) re.test(frame.filename);
|
||||
return function isDactyl(frame) { return re.test(frame.filename); };
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -1407,7 +1412,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
|
||||
this.errors.push([new Date, obj + "\n" + obj.stack]);
|
||||
this.errors = this.errors.slice(-this.maxErrors);
|
||||
this.errors.toString = function () [k + "\n" + v for ([k, v] of this)].join("\n\n");
|
||||
this.errors.toString = function () {
|
||||
return [k + "\n" + v for ([k, v] of this)].join("\n\n");
|
||||
};
|
||||
|
||||
this.dump(String(error));
|
||||
this.dump(obj);
|
||||
@@ -1634,7 +1641,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
}
|
||||
catch (e if e instanceof StopIteration) {};
|
||||
})();
|
||||
}),
|
||||
}),
|
||||
|
||||
/**
|
||||
* Wraps a callback function such that its errors are not lost. This
|
||||
|
||||
Reference in New Issue
Block a user