1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-14 20:35:47 +01:00

Hello strange new syntax. Can we be friends?

This commit is contained in:
Kris Maglione
2013-08-21 22:55:55 -07:00
parent e5864bfd23
commit c89f3e0df5
21 changed files with 106 additions and 134 deletions

View File

@@ -211,9 +211,8 @@ var Addon = Class("Addon", {
},
update: function callee() {
let self = this;
function update(key, xml) {
let node = self.nodes[key];
let update = (key, xml) => {
let node = this.nodes[key];
while (node.firstChild)
node.removeChild(node.firstChild);

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2009-2012 Kris Maglione <maglione.k@gmail.com>
// Copyright (c) 2009-2013 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -953,14 +953,13 @@ Class.prototype = {
* @returns {nsITimer} The timer which backs this timeout.
*/
timeout: function timeout(callback, timeout) {
const self = this;
function timeout_notify(timer) {
if (self.stale ||
let timeout_notify = (timer) => {
if (this.stale ||
util.rehashing && !isinstance(Cu.getGlobalForObject(callback), ["BackstagePass"]))
return;
self.timeouts.splice(self.timeouts.indexOf(timer), 1);
util.trapErrors(callback, self);
}
this.timeouts.splice(this.timeouts.indexOf(timer), 1);
util.trapErrors(callback, this);
};
let timer = services.Timer(timeout_notify, timeout || 0, services.Timer.TYPE_ONE_SHOT);
this.timeouts.push(timer);
return timer;
@@ -973,12 +972,11 @@ Class.prototype = {
* localized properties.
*/
update: function update() {
let self = this;
// XXX: Duplication.
for (let i = 0; i < arguments.length; i++) {
let src = arguments[i];
Object.getOwnPropertyNames(src || {}).forEach(function (k) {
Object.getOwnPropertyNames(src || {}).forEach((k) => {
let desc = Object.getOwnPropertyDescriptor(src, k);
if (desc.value instanceof Class.Property)
desc = desc.value.init(k, this) || desc.value;
@@ -986,12 +984,16 @@ Class.prototype = {
if (typeof desc.value === "function") {
let func = desc.value.wrapped || desc.value;
if (!func.superapply) {
func.__defineGetter__("super", function () Object.getPrototypeOf(self)[k]);
func.superapply = function superapply(self, args)
let (meth = Object.getPrototypeOf(self)[k])
meth && meth.apply(self, args);
func.supercall = function supercall(self)
func.superapply(self, Array.slice(arguments, 1));
func.__defineGetter__("super", () => Object.getPrototypeOf(this)[k]);
func.superapply = function superapply(self, args) {
let meth = Object.getPrototypeOf(self)[k];
return meth && meth.apply(self, args);
};
func.supercall = function supercall(self) {
return func.superapply(self, Array.slice(arguments, 1));
}
}
}

View File

@@ -995,8 +995,6 @@ var Buffer = Module("Buffer", {
showPageInfo: function showPageInfo(verbose, sections) {
let { commandline, dactyl, options } = this.modules;
let self = this;
// Ctrl-g single line output
if (!verbose) {
let file = this.win.location.pathname.split("/").pop() || _("buffer.noName");
@@ -1004,7 +1002,7 @@ var Buffer = Module("Buffer", {
let info = template.map(
(sections || options["pageinfo"])
.map(function (opt) Buffer.pageInfo[opt].action.call(self)),
.map((opt) => Buffer.pageInfo[opt].action.call(this)),
function (res) res && iter(res).join(", ") || undefined,
", ").join("");
@@ -1016,9 +1014,9 @@ var Buffer = Module("Buffer", {
return;
}
let list = template.map(sections || options["pageinfo"], function (option) {
let list = template.map(sections || options["pageinfo"], (option) => {
let { action, title } = Buffer.pageInfo[option];
return template.table(title, action.call(self, true));
return template.table(title, action.call(this, true));
}, ["br"]);
commandline.commandOutput(list);
@@ -1254,14 +1252,13 @@ var Buffer = Module("Buffer", {
* Updates the zoom level of this buffer from a content preference.
*/
updateZoom: util.wrapCallback(function updateZoom() {
let self = this;
let uri = this.uri;
if (prefs.get("browser.zoom.siteSpecific")) {
this.getPref("dactyl.content.full-zoom", function (val) {
if (val != null && uri.equals(self.uri) && val != prefs.get("browser.zoom.full"))
[self.contentViewer.textZoom, self.contentViewer.fullZoom] =
[self.contentViewer.fullZoom, self.contentViewer.textZoom];
this.getPref("dactyl.content.full-zoom", (val) => {
if (val != null && uri.equals(this.uri) && val != prefs.get("browser.zoom.full"))
[this.contentViewer.textZoom, this.contentViewer.fullZoom] =
[this.contentViewer.fullZoom, this.contentViewer.textZoom];
});
}
}),

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2012 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -583,8 +583,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
this.remove(name);
}
let self = this;
let closure = function () self._map[name];
let closure = () => this._map[name];
memoize(this._map, name, function () commands.Command(specs, description, action, extra));
if (!extra.hidden)

View File

@@ -135,10 +135,10 @@ var CompletionContext = Class("CompletionContext", {
* {@link #filters} array.
*/
this.filterFunc = function filterFunc(items) {
let self = this;
return this.filters.
reduce(function r(res, filter) res.filter(function f(item) filter.call(self, item)),
items);
return this.filters
.reduce((res, filter)
=> res.filter((item) => filter.call(this, item)),
items);
};
/**
* @property {Array} An array of predicates on which to filter the
@@ -674,7 +674,6 @@ var CompletionContext = Class("CompletionContext", {
},
getRows: function getRows(start, end, doc) {
let self = this;
let items = this.items;
let cache = this.cache.rows;
let step = start > end ? -1 : 1;
@@ -733,12 +732,10 @@ var CompletionContext = Class("CompletionContext", {
},
split: function split(name, obj, fn) {
const self = this;
let context = this.fork(name);
function alias(prop) {
context.__defineGetter__(prop, function get_() self[prop]);
context.__defineSetter__(prop, function set_(val) self[prop] = val);
let alias = (prop) => {
context.__defineGetter__(prop, () => this[prop]);
context.__defineSetter__(prop, (val) => this[prop] = val);
}
alias("_cache");
alias("_completions");
@@ -821,7 +818,6 @@ var CompletionContext = Class("CompletionContext", {
* context.
*/
reset: function reset() {
let self = this;
if (this.parent)
throw Error();
@@ -842,7 +838,7 @@ var CompletionContext = Class("CompletionContext", {
this.value = this._value;
this._caret = this.value.length;
}
//for (let key in (k for ([k, v] in Iterator(self.contexts)) if (v.offset > this.caret)))
//for (let key in (k for ([k, v] in Iterator(this.contexts)) if (v.offset > this.caret)))
// delete this.contexts[key];
for each (let context in this.contexts) {
context.hasItems = false;

View File

@@ -19,8 +19,6 @@ var Const = function Const(val) Class.Property({ enumerable: true, value: val })
var Group = Class("Group", {
init: function init(name, description, filter, persist) {
const self = this;
this.name = name;
this.description = description;
this.filter = filter || this.constructor.defaultFilter;
@@ -171,13 +169,12 @@ var Contexts = Module("contexts", {
Hives: Class("Hives", Class.Property, {
init: function init(name, constructor) {
const { contexts } = modules;
const self = this;
if (this.Hive)
return {
enumerable: true,
get: function () array(contexts.groups[self.name])
get: () => array(contexts.groups[this.name])
};
this.Hive = constructor;

View File

@@ -23,21 +23,20 @@ var states = iter([v, k.slice(prefix.length).toLowerCase()]
var Download = Class("Download", {
init: function init(id, list) {
let self = this;
this.download = services.downloadManager.getDownload(id);
this.list = list;
this.nodes = {
commandTarget: self
commandTarget: this
};
DOM.fromJSON(
["tr", { highlight: "Download", key: "row" },
["td", { highlight: "DownloadTitle" },
["span", { highlight: "Link" },
["a", { key: "launch", href: self.target.spec, path: self.targetFile.path },
self.displayName],
["a", { key: "launch", href: this.target.spec, path: this.targetFile.path },
this.displayName],
["span", { highlight: "LinkInfo" },
self.targetFile.path]]],
this.targetFile.path]]],
["td", { highlight: "DownloadState", key: "state" }],
["td", { highlight: "DownloadButtons Buttons" },
["a", { highlight: "Button", href: "javascript:0", key: "pause" }, _("download.action.Pause")],
@@ -54,19 +53,19 @@ var Download = Class("Download", {
["td", { highlight: "DownloadSpeed", key: "speed" }],
["td", { highlight: "DownloadTime", key: "time" }],
["td", {},
["a", { highlight: "DownloadSource", key: "source", href: self.source.spec },
self.source.spec]]],
["a", { highlight: "DownloadSource", key: "source", href: this.source.spec },
this.source.spec]]],
this.list.document, this.nodes);
this.nodes.launch.addEventListener("click", function (event) {
this.nodes.launch.addEventListener("click", (event) => {
if (event.button == 0) {
event.preventDefault();
self.command("launch");
this.command("launch");
}
}, false);
self.updateStatus();
return self;
this.updateStatus();
return this;
},
get status() states[this.state],
@@ -102,7 +101,6 @@ var Download = Class("Download", {
this.updateStatus();
},
launch: function launch() {
let self = this;
// Behavior mimics that of the builtin Download Manager.
function action() {
try {
@@ -119,13 +117,13 @@ var Download = Class("Download", {
let file = io.File(this.targetFile);
if (file.isExecutable() && prefs.get("browser.download.manager.alertOnEXEOpen", true))
this.list.modules.commandline.input(_("download.prompt.launchExecutable") + " ",
function (resp) {
(resp) => {
if (/^a(lways)$/i.test(resp)) {
prefs.set("browser.download.manager.alertOnEXEOpen", false);
resp = "yes";
}
if (/^y(es)?$/i.test(resp))
action.call(self);
action.call(this);
});
else
action.call(this);

View File

@@ -218,11 +218,12 @@ var Highlights = Module("Highlight", {
* @param {string} class
*/
selector: function selector(class_)
let (self = this)
class_.replace(/(^|[>\s])([A-Z][\w-]+)\b/g,
function (m, n1, hl) n1 +
(self.highlight[hl] && self.highlight[hl].class != class_
? self.highlight[hl].selector : "[dactyl|highlight~=" + hl + "]")),
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(/*
^

View File

@@ -765,13 +765,12 @@ var JavaScript = Module("javascript", {
init: function init(context) {
init.supercall(this);
let self = this;
let sandbox = true || isinstance(context, ["Sandbox"]);
this.context = modules.newContext(context, !sandbox, "Dactyl REPL Context");
this.js = modules.JavaScript();
this.js.replContext = this.context;
this.js.newContext = function newContext() modules.newContext(self.context, !sandbox, "Dactyl REPL Temp Context");
this.js.newContext = () => modules.newContext(this.context, !sandbox, "Dactyl REPL Temp Context");
this.js.globals = [
[this.context, /*L*/"REPL Variables"],

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2009-2012 Kris Maglione <maglione.k@gmail.com>
// Copyright (c) 2009-2013 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -321,25 +321,24 @@ overlay.overlayWindow(Object.keys(config.overlays), function _overlay(window) ({
},
scanModules: function scanModules() {
let self = this;
let { Module, modules } = this.modules;
defineModule.modules.forEach(function defModule(mod) {
defineModule.modules.forEach((mod) => {
let names = Set(Object.keys(mod.INIT));
if ("init" in mod.INIT)
Set.add(names, "init");
keys(names).forEach(function (name) { self.deferInit(name, mod.INIT, mod); });
keys(names).forEach((name) => { this.deferInit(name, mod.INIT, mod); });
});
Module.list.forEach(function frobModule(mod) {
Module.list.forEach((mod) => {
if (!mod.frobbed) {
modules.__defineGetter__(mod.className, function () {
modules.__defineGetter__(mod.className, () => {
delete modules[mod.className];
return self.loadModule(mod.className, null, Components.stack.caller);
return this.loadModule(mod.className, null, Components.stack.caller);
});
Object.keys(mod.prototype.INIT)
.forEach(function (name) { self.deferInit(name, mod.prototype.INIT, mod); });
.forEach((name) => { this.deferInit(name, mod.prototype.INIT, mod); });
}
mod.frobbed = true;
});

View File

@@ -147,7 +147,6 @@ var Messages = Module("messages", {
obj[_prop] = this.default;
return {
get: function get() {
let self = this;
let value = this[_prop];
function getter(key, default_) function getter() messages.get([name, key].join("."), default_);

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2011 by Kris Maglione <maglione.k@gmail.com>
// Copyright (c) 2008-2013 by Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -908,8 +908,6 @@ var Options = Module("options", {
* @optional
*/
add: function add(names, description, type, defaultValue, extraInfo) {
const self = this;
if (!util.isDactyl(Components.stack.caller))
deprecated.warn(add, "options.add", "group.options.add");
@@ -927,7 +925,7 @@ var Options = Module("options", {
this.remove(name);
}
let closure = function () self._optionMap[name];
let closure = () => this._optionMap[name];
memoize(this._optionMap, name, function () Option.types[type](modules, names, description, defaultValue, extraInfo));
for (let alias in values(names.slice(1)))

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2008-2012 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -139,7 +139,7 @@ var Services = Module("Services", {
if (service.quiet === false)
throw e.stack ? e : Error(e);
if (typeof util !== "undefined")
if (typeof util !== "undefined" && util != null)
util.reportError(e);
else
dump("dactyl: Service creation failed for '" + service.class + "': " + e + "\n" + (e.stack || Error(e).stack));
@@ -176,13 +176,12 @@ var Services = Module("Services", {
* class.
*/
addClass: function addClass(name, class_, ifaces, init, quiet) {
const self = this;
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]));
this[name] = function Create() self._create(name, arguments);
this[name] = (function Create() this._create(name, arguments)).bind(this);
update.apply(null, [this[name]].concat([Ci[i] for each (i in Array.concat(ifaces))]));
return this[name];
},

View File

@@ -241,7 +241,6 @@ var Storage = Module("Storage", {
},
newObject: function newObject(key, constructor, params) {
let self = this;
if (params == null || !isObject(params))
throw Error("Invalid argument type");
@@ -261,10 +260,10 @@ var Storage = Module("Storage", {
if (key in this && !reload)
throw Error("Cannot add storage key with that name.");
let load = function () self._loadData(key, params.store, params.type || myObject);
let load = () => this._loadData(key, params.store, params.type || myObject);
this.keys[key] = new constructor(key, params.store, load, params);
this.keys[key].timer = new Timer(1000, 10000, function () self.save(key));
this.keys[key].timer = new Timer(1000, 10000, () => this.save(key));
this.__defineGetter__(key, function () this.keys[key]);
}
return this.keys[key];

View File

@@ -203,7 +203,6 @@ var Hive = Class("Hive", {
* @param {number} index
*/
remove: function remove(name, filter, css, index) {
let self = this;
if (arguments.length == 1) {
var matches = [name];
name = null;
@@ -211,7 +210,7 @@ var Hive = Class("Hive", {
if (filter && filter.indexOf(",") > -1)
return filter.split(",").reduce(
function (n, f) n + self.removeSheet(name, f, index), 0);
(n, f) => n + this.removeSheet(name, f, index), 0);
if (filter == undefined)
filter = "";

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2008-2012 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -456,26 +456,24 @@ var Template = Module("Template", {
},
tabular: function tabular(headings, style, iter) {
let self = this;
// TODO: This might be mind-bogglingly slow. We'll see.
return ["table", {},
["tr", { highlight: "Title", align: "left" },
this.map(headings, function (h)
["th", {}, h])],
this.map(iter, function (row)
this.map(iter, (row) =>
["tr", {},
self.map(Iterator(row), function ([i, d])
this.map(Iterator(row), function ([i, d])
["td", { style: style[i] || "" }, d])])];
},
usage: function usage(iter, format) {
let self = this;
format = format || {};
let desc = format.description || function (item) self.linkifyHelp(item.description);
let help = format.help || function (item) item.name;
function sourceLink(frame) {
let source = self.sourceLink(frame);
let desc = format.description || (item => this.linkifyHelp(item.description));
let help = format.help || (item => item.name);
let sourceLink = (frame) => {
let source = this.sourceLink(frame);
source[1]["dactyl:hint"] = source[2];
return source;
}
@@ -483,25 +481,25 @@ var Template = Module("Template", {
format.headings ?
["thead", { highlight: "UsageHead" },
["tr", { highlight: "Title", align: "left" },
this.map(format.headings, function (h) ["th", {}, h])]] :
this.map(format.headings, (h) => ["th", {}, h])]] :
[],
format.columns ?
["colgroup", {},
this.map(format.columns, function (c) ["col", { style: c }])] :
this.map(format.columns, (c) => ["col", { style: c }])] :
[],
["tbody", { highlight: "UsageBody" },
this.map(iter, function (item)
this.map(iter, (item) =>
// Urgh.
let (name = item.name || item.names[0], frame = item.definedAt)
["tr", { highlight: "UsageItem" },
["td", { style: "padding-right: 2em;" },
["span", { highlight: "Usage Link" },
!frame ? name :
[self.helpLink(help(item), name, "Title"),
[this.helpLink(help(item), name, "Title"),
["span", { highlight: "LinkInfo" },
_("io.definedAt"), " ",
sourceLink(frame)]]]],
item.columns ? self.map(item.columns, function (c) ["td", {}, c]) : [],
item.columns ? this.map(item.columns, (c) => ["td", {}, c]) : [],
["td", {}, desc(item)]])]];
}
});