1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-30 19:52:25 +01:00

Cleanup crufty apply code.

This commit is contained in:
Kris Maglione
2015-02-21 22:43:41 -08:00
parent 7ee579200f
commit 1ee5668cac
26 changed files with 65 additions and 69 deletions

View File

@@ -957,7 +957,7 @@ var CommandLine = Module("commandline", {
}
this.savingOutput = true;
dactyl.trapErrors.apply(dactyl, [fn, self].concat(args));
apply(dactyl, "trapErrors", [fn, self].concat(args));
this.savingOutput = false;
return output.map(elem => elem instanceof Node ? DOM.stringify(elem) : elem)
.join("\n");
@@ -1755,7 +1755,7 @@ var CommandLine = Module("commandline", {
return Events.PASS;
});
let bind = function bind(...args) mappings.add.apply(mappings, [[modes.COMMAND_LINE]].concat(args));
let bind = function bind(...args) apply(mappings, "add", [[modes.COMMAND_LINE]].concat(args));
bind(["<Esc>", "<C-[>"], "Stop waiting for completions or exit Command Line mode",
function ({ self }) {

View File

@@ -1334,7 +1334,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
},
{ count: true });
bind = function bind(...args) mappings.add.apply(mappings, [[modes.AUTOCOMPLETE]].concat(args));
bind = function bind(...args) apply(mappings, "add", [[modes.AUTOCOMPLETE]].concat(args));
bind(["<Esc>"], "Return to Insert mode",
() => Events.PASS_THROUGH);

View File

@@ -57,7 +57,7 @@ var EventHive = Class("EventHive", Contexts.Hive, {
capture,
allowUntrusted];
target.addEventListener.apply(target, args.slice(2));
apply(target, "addEventListener", args.slice(2));
this.sessionListeners.push(args);
}
},
@@ -83,7 +83,7 @@ var EventHive = Class("EventHive", Contexts.Hive, {
&& args[3].wrapped == events[args[2]]
&& args[4] == capture) {
elem.removeEventListener.apply(elem, args.slice(2));
apply(elem, "removeEventListener", args.slice(2));
return false;
}
return elem;
@@ -426,7 +426,7 @@ var Events = Module("events", {
canonicalKeys: deprecated("DOM.Event.canonicalKeys", { get: function canonicalKeys() DOM.Event.bound.canonicalKeys }),
create: deprecated("DOM.Event", function create() DOM.Event.apply(null, arguments)),
dispatch: deprecated("DOM.Event.dispatch", function dispatch() DOM.Event.dispatch.apply(DOM.Event, arguments)),
dispatch: deprecated("DOM.Event.dispatch", function dispatch() apply(DOM.Event, "dispatch", arguments)),
fromString: deprecated("DOM.Event.parse", { get: function fromString() DOM.Event.bound.parse }),
iterKeys: deprecated("DOM.Event.iterKeys", { get: function iterKeys() DOM.Event.bound.iterKeys }),
@@ -435,7 +435,7 @@ var Events = Module("events", {
return toString.supercall(this);
deprecated.warn(toString, "toString", "DOM.Event.stringify");
return DOM.Event.stringify.apply(DOM.Event, arguments);
return apply(DOM.Event, "stringify", arguments);
},
get defaultTarget() dactyl.focusedElement || content.document.body || document.documentElement,

View File

@@ -354,7 +354,7 @@ var History = Module("history", {
completion.addUrlCompleter("history", "History", completion.history);
},
mappings: function initMappings() {
function bind(...args) mappings.add.apply(mappings, [config.browserModes].concat(args));
function bind(...args) apply(mappings, "add", [config.browserModes].concat(args));
bind(["<C-o>"], "Go to an older position in the jump list",
function ({ count }) { history.stepTo(-Math.max(count, 1), true); },

View File

@@ -252,13 +252,13 @@ var KeyProcessor = Class("KeyProcessor", {
execute: function execute(map, args)
() => {
if (this.preExecute)
this.preExecute.apply(this, args);
apply(this, "preExecute", args);
args.self = this.main.params.mappingSelf || this.main.mappingSelf || map;
let res = map.execute.call(map, args);
if (this.postExecute)
this.postExecute.apply(this, args);
apply(this, "postExecute", args);
return res;
},

View File

@@ -414,7 +414,7 @@ var Mappings = Module("mappings", {
group = this.user;
}
let map = group.add.apply(group, arguments);
let map = apply(group, "add", arguments);
map.definedAt = contexts.getCaller(Components.stack.caller);
return map;
},
@@ -431,7 +431,7 @@ var Mappings = Module("mappings", {
* @optional
*/
addUserMap: deprecated("group.mappings.add", function addUserMap() {
let map = this.user.add.apply(this.user, arguments);
let map = apply(this.user, "add", arguments);
map.definedAt = contexts.getCaller(Components.stack.caller);
return map;
}),

View File

@@ -450,7 +450,7 @@ var Modes = Module("modes", {
for (let mode of array.iterValues(queue))
if (!seen.add(mode)) {
res.push(mode);
queue.push.apply(queue, mode.bases);
apply(queue, "push", mode.bases);
}
return res;
}),
@@ -649,7 +649,7 @@ var Modes = Module("modes", {
},
prefs: function initPrefs() {
prefs.watch("accessibility.browsewithcaret",
function () { modes.onCaretChange.apply(modes, arguments); });
function () { apply(modes, "onCaretChange", arguments); });
}
});

View File

@@ -66,7 +66,7 @@ var MOW = Module("mow", {
});
},
__noSuchMethod__: function (meth, args) Buffer[meth].apply(Buffer, [this.body].concat(args)),
__noSuchMethod__: function (meth, args) apply(Buffer, meth, [this.body].concat(args)),
get widget() this.widgets.multilineOutput,

View File

@@ -237,7 +237,7 @@ var StatusLine = Module("statusline", {
},
unsafeURI: deprecated("util.unsafeURI", { get: function unsafeURI() util.unsafeURI }),
losslessDecodeURI: deprecated("util.losslessDecodeURI", function losslessDecodeURI() util.losslessDecodeURI.apply(util, arguments)),
losslessDecodeURI: deprecated("util.losslessDecodeURI", function losslessDecodeURI() apply(util, "losslessDecodeURI", arguments)),
/**
* Update the URL displayed in the status line. Also displays status

View File

@@ -238,7 +238,7 @@ var Addon = Class("Addon", {
["cancelUninstall", "findUpdates", "getResourceURI", "hasResource", "isCompatibleWith",
"uninstall"].forEach(function (prop) {
Addon.prototype[prop] = function proxy() this.addon[prop].apply(this.addon, arguments);
Addon.prototype[prop] = function proxy() apply(this.addon, prop, arguments);
});
["aboutURL", "appDisabled", "applyBackgroundUpdates", "blocklistState", "contributors", "creator",

View File

@@ -270,7 +270,7 @@ function literal(comment) {
function apply(obj, meth, args) {
// The function's own apply method breaks in strange ways
// when using CPOWs.
Function.prototype.apply.call(obj[meth], obj, args);
return Function.prototype.apply.call(obj[meth], obj, args);
}
/**
@@ -354,7 +354,7 @@ function deprecated(alternative, fn) {
let name,
func = callable(fn) ? fn
: function () this[fn].apply(this, arguments);
: function () apply(this, fn, arguments);
function deprecatedMethod() {
let obj = !this ? "" :
@@ -561,7 +561,7 @@ function set() {
Object.keys(Set).forEach(function (meth) {
set[meth] = function proxy() {
deprecated.warn(proxy, "set." + meth, "Set." + meth);
return Set[meth].apply(Set, arguments);
return apply(Set, meth, arguments);
};
});
@@ -617,7 +617,7 @@ function curry(fn, length, self, acc) {
var bind = function bind(meth, self, ...args) {
let func = callable(meth) ? meth : self[meth];
return func.bind.apply(func, [self].concat(args));
return apply(func, "bind", [self].concat(args));
}
/**
@@ -1728,12 +1728,12 @@ const Iter = Class("Iter", {
this.iter = iter.__iterator__();
if (this.iter.finalize)
this.finalize = function finalize() this.iter.finalize.apply(this.iter, arguments);
this.finalize = function finalize() apply(this.iter, "finalize", arguments);
},
next: function next() this.iter.next(),
send: function send() this.iter.send.apply(this.iter, arguments),
send: function send() apply(this.iter, "send", arguments),
"@@iterator": function () this.iter,
});
@@ -1915,7 +1915,7 @@ var array = Class("array", Array, {
let iterProto = Iter.prototype;
Object.keys(iter).forEach(function (k) {
iterProto[k] = function (...args) {
let res = iter[k].apply(iter, [this].concat(args));
let res = apply(iter, k, [this].concat(args));
if (isinstance(res, ["Iterator", "Generator"]))
return Iter(res);
return res;
@@ -1925,7 +1925,7 @@ Object.keys(iter).forEach(function (k) {
Object.keys(array).forEach(function (k) {
if (!(k in iterProto))
iterProto[k] = function (...args) {
let res = array[k].apply(array, [this.toArray()].concat(args));
let res = apply(array, k, [this.toArray()].concat(args));
if (isinstance(res, ["Iterator", "Generator"]))
return Iter(res);
if (isArray(res))
@@ -1938,7 +1938,7 @@ Object.getOwnPropertyNames(Array.prototype).forEach(function (k) {
if (!(k in iterProto) && callable(Array.prototype[k]))
iterProto[k] = function () {
let ary = iter(this).toArray();
let res = ary[k].apply(ary, arguments);
let res = apply(ary, k, arguments);
if (isArray(res))
return array(res);
return res;

View File

@@ -204,7 +204,7 @@ var Buffer = Module("Buffer", {
/**
* @property {number} True when the buffer is fully loaded.
*/
get loaded() Math.min.apply(null,
get loaded() apply(Math, "min",
this.allFrames()
.map(frame => ["loading", "interactive", "complete"]
.indexOf(frame.document.readyState))),

View File

@@ -596,7 +596,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
_add: function _add(names, description, action, extra={}, replace=false) {
const { contexts } = this.modules;
extra.definedAt = contexts.getCaller(Components.stack.caller.caller);
return this.add.apply(this, arguments);
return apply(this, "add", arguments);
},
/**
@@ -837,7 +837,7 @@ var Commands = Module("commands", {
group = this.user;
}
return group._add.apply(group, arguments);
return apply(group, "_add", arguments);
},
addUserCommand: deprecated("group.commands.add", { get: function addUserCommand() this.user.bound._add }),
getUserCommands: deprecated("iter(group.commands)", function getUserCommands() iter(this.user).toArray()),

View File

@@ -241,7 +241,7 @@ var CompletionContext = Class("CompletionContext", {
return this.cache.allItemsResult;
this.cache.allItems = allItems;
let minStart = Math.min.apply(Math, this.activeContexts.map(function m(c) c.offset));
let minStart = apply(Math, "min", this.activeContexts.map(function m(c) c.offset));
if (minStart == Infinity)
minStart = 0;
@@ -271,7 +271,7 @@ var CompletionContext = Class("CompletionContext", {
// Temporary
get allSubstrings() {
let contexts = this.activeContexts;
let minStart = Math.min.apply(Math, contexts.map(function m(c) c.offset));
let minStart = apply(Math, "min", contexts.map(function m(c) 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);
@@ -906,7 +906,7 @@ var Completion = Module("completion", {
_runCompleter: function _runCompleter(name, filter, maxItems, ...args) {
let context = modules.CompletionContext(filter);
context.maxItems = maxItems;
let res = context.fork.apply(context, ["run", 0, this, name].concat(args));
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 })) };
@@ -917,14 +917,14 @@ var Completion = Module("completion", {
},
runCompleter: function runCompleter(name, filter, maxItems) {
return this._runCompleter.apply(this, arguments)
return apply(this, "_runCompleter", arguments)
.items.map(function m(i) i.item);
},
listCompleter: function listCompleter(name, filter, maxItems, ...args) {
let context = modules.CompletionContext(filter || "");
context.maxItems = maxItems;
context.fork.apply(context, ["list", 0, this, name].concat(args));
apply(context, "fork", ["list", 0, this, name].concat(args));
context = context.contexts["/list"];
context.wait(null, true);

View File

@@ -553,7 +553,7 @@ var Contexts = Module("contexts", {
if (callable(params))
action = dactyl.userEval("(function action() { with (action.makeParams(this, arguments)) {" + args.literalArg + "} })");
else
action = dactyl.userFunc.apply(dactyl, params.concat(args.literalArg));
action = apply(dactyl, "userFunc", params.concat(args.literalArg));
process = param => isObject(param) && param.valueOf ? param.valueOf() : param;
action.params = params;
action.makeParams = makeParams;

View File

@@ -1002,12 +1002,7 @@ var DOM = Class("DOM", {
for (k in opts)
if (k in params)));
// Because security boundaries :/
let ary = new doc.defaultView.Array;
for (let arg of args)
ary.push(params[arg]);
evt["init" + t + "Event"].apply(evt, ary);
apply(evt, "init" + t + "Event", args.map(arg => params[arg]));
return evt;
}
}, {

View File

@@ -306,7 +306,7 @@ var IO = Module("io", {
*/
sourcing: null,
expandPath: deprecated("File.expandPath", function expandPath() File.expandPath.apply(File, arguments)),
expandPath: deprecated("File.expandPath", function expandPath() apply(File, "expandPath", arguments)),
/**
* Returns the first user RC file found in *dir*.
@@ -523,7 +523,7 @@ var IO = Module("io", {
stdin.write(input);
function result(status, output) ({
__noSuchMethod__: function (meth, args) this.output[meth].apply(this.output, args),
__noSuchMethod__: function (meth, args) apply(this.output, meth, args),
valueOf: function () this.output,
output: output.replace(/^(.*)\n$/, "$1"),
returnValue: status,

View File

@@ -760,7 +760,7 @@ var JavaScript = Module("javascript", {
return this.rootNode;
}),
__noSuchMethod__: function (meth, args) Buffer[meth].apply(Buffer, [this.rootNode].concat(args))
__noSuchMethod__: function (meth, args) apply(Buffer, meth, [this.rootNode].concat(args))
});
modules.CommandREPLMode = Class("CommandREPLMode", modules.CommandMode, {
@@ -859,7 +859,7 @@ var JavaScript = Module("javascript", {
mappings: function initMappings(dactyl, modules, window) {
const { mappings, modes } = modules;
function bind(...args) mappings.add.apply(mappings, [[modes.REPL]].concat(args))
function bind(...args) apply(mappings, "add", [[modes.REPL]].concat(args))
bind(["<Return>"], "Accept the current input",
function ({ self }) { self.accept(); });

View File

@@ -985,18 +985,18 @@ var Options = Module("options", {
"@@iterator": function __iterator__()
values(this._options.sort((a, b) => String.localeCompare(a.name, b.name))),
allPrefs: deprecated("prefs.getNames", function allPrefs() prefs.getNames.apply(prefs, arguments)),
getPref: deprecated("prefs.get", function getPref() prefs.get.apply(prefs, arguments)),
invertPref: deprecated("prefs.invert", function invertPref() prefs.invert.apply(prefs, arguments)),
listPrefs: deprecated("prefs.list", function listPrefs() { this.modules.commandline.commandOutput(prefs.list.apply(prefs, arguments)); }),
observePref: deprecated("prefs.observe", function observePref() prefs.observe.apply(prefs, arguments)),
popContext: deprecated("prefs.popContext", function popContext() prefs.popContext.apply(prefs, arguments)),
pushContext: deprecated("prefs.pushContext", function pushContext() prefs.pushContext.apply(prefs, arguments)),
resetPref: deprecated("prefs.reset", function resetPref() prefs.reset.apply(prefs, arguments)),
safeResetPref: deprecated("prefs.safeReset", function safeResetPref() prefs.safeReset.apply(prefs, arguments)),
safeSetPref: deprecated("prefs.safeSet", function safeSetPref() prefs.safeSet.apply(prefs, arguments)),
setPref: deprecated("prefs.set", function setPref() prefs.set.apply(prefs, arguments)),
withContext: deprecated("prefs.withContext", function withContext() prefs.withContext.apply(prefs, arguments)),
allPrefs: deprecated("prefs.getNames", function allPrefs() apply(prefs, "getNames", arguments)),
getPref: deprecated("prefs.get", function getPref() apply(prefs, "get", arguments)),
invertPref: deprecated("prefs.invert", function invertPref() apply(prefs, "invert", arguments)),
listPrefs: deprecated("prefs.list", function listPrefs() { this.modules.commandline.commandOutput(apply(prefs, "list", arguments)); }),
observePref: deprecated("prefs.observe", function observePref() apply(prefs, "observe", arguments)),
popContext: deprecated("prefs.popContext", function popContext() apply(prefs, "popContext", arguments)),
pushContext: deprecated("prefs.pushContext", function pushContext() apply(prefs, "pushContext", arguments)),
resetPref: deprecated("prefs.reset", function resetPref() apply(prefs, "reset", arguments)),
safeResetPref: deprecated("prefs.safeReset", function safeResetPref() apply(prefs, "safeReset", arguments)),
safeSetPref: deprecated("prefs.safeSet", function safeSetPref() apply(prefs, "safeSet", arguments)),
setPref: deprecated("prefs.set", function setPref() apply(prefs, "set", arguments)),
withContext: deprecated("prefs.withContext", function withContext() apply(prefs, "withContext", arguments)),
cleanupPrefs: Class.Memoize(() => config.prefs.Branch("cleanup.option.")),

View File

@@ -82,7 +82,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
capture,
allowUntrusted];
target.addEventListener.apply(target, args.slice(1));
apply(target, "addEventListener", args.slice(1));
listeners.push(args);
}
},
@@ -105,7 +105,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
this.setData(doc, "listeners", listeners.filter(function (args) {
let elem = args[0].get();
if (target == null || elem == target && args[1] == event && args[2].wrapped == callback && args[3] == capture) {
elem.removeEventListener.apply(elem, args.slice(1));
apply(elem, "removeEventListener", args.slice(1));
return false;
}
return elem;

View File

@@ -265,7 +265,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
storage.addObserver("sanitizer",
function (key, event, arg) {
if (names.has(event))
params.action.apply(params, arg);
apply(params, "action", arg);
},
getWindow(params.action));

View File

@@ -130,7 +130,7 @@ var Services = Module("Services", {
if (service.init && args.length) {
if (service.callable)
res[service.init].apply(res, args);
apply(res, service.init, args);
else
res[service.init] = args[0];
}

View File

@@ -134,7 +134,7 @@ var ArrayStore = Class("ArrayStore", StoreBase, {
mutate: function mutate(funcName) {
var _funcName = funcName;
arguments[0] = this._object;
this._object = Array[_funcName].apply(Array, arguments)
this._object = apply(Array, _funcName, arguments)
.map(this.makeOwn.bind(this));
this.fireEvent("change", null);
},
@@ -271,7 +271,7 @@ var Storage = Module("Storage", {
throw Error("Invalid argument type");
if (this.isLocalModule) {
this.globalInstance.newObject.apply(this.globalInstance, arguments);
apply(this.globalInstance, "newObject", arguments);
if (!(key in this.keys) && this.privateMode && key in this.globalInstance.keys) {
let obj = this.globalInstance.keys[key];
@@ -799,7 +799,7 @@ var File = Class("File", {
catch (e) {}
if (isFunction)
File.prototype[prop] = util.wrapCallback(function wrapper() this.file[prop].apply(this.file, arguments));
File.prototype[prop] = util.wrapCallback(function wrapper() apply(this.file, prop, arguments));
else
Object.defineProperty(File.prototype, prop, {
configurable: true,

View File

@@ -299,7 +299,7 @@ var Styles = Module("Styles", {
_proxy: function (name, args) {
let obj = this[args[0] ? "system" : "user"];
return obj[name].apply(obj, Array.slice(args, 1));
return apply(obj, name, Array.slice(args, 1));
},
addSheet: deprecated("Styles#{user,system}.add", function addSheet() this._proxy("add", arguments)),
@@ -720,7 +720,7 @@ var Styles = Module("Styles", {
get sites() this.hive.sites,
__noSuchMethod__: function __noSuchMethod__(meth, args) {
return this.hive[meth].apply(this.hive, args);
return apply(this.hive, meth, args);
},
destroy: function () {

View File

@@ -36,7 +36,7 @@ var Binding = Class("Binding", {
configurable: true,
writeable: true,
value: function __noSuchMethod__(meth, args) {
return this.node[meth].apply(this.node, args);
return apply(this.node, meth, args);
}
})
}, {
@@ -88,7 +88,7 @@ var Binding = Class("Binding", {
Object.defineProperty(Binding.prototype, key, {
configurable: true,
enumerable: false,
value: function () this.node[key].apply(this.node, arguments),
value: function () apply(this.node, key, arguments),
writable: true
});
});

View File

@@ -799,7 +799,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
args.push(params.user);
if (params.pass != null)
args.push(prams.pass);
xmlhttp.open.apply(xmlhttp, args);
apply(xmlhttp, "open", args);
for (let [header, val] of iter(params.headers || {}))
xmlhttp.setRequestHeader(header, val);