1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 01:47:58 +01:00

Revert "Move util.Array to modules.Array_."

This reverts commit d6cdda48a18c9fa05365b50046470fec9935fd3c.

Array_ method chaining needs fixing.
This commit is contained in:
Doug Kearns
2009-09-15 13:13:07 +10:00
parent 66f86d2da4
commit dbc99ad956
17 changed files with 69 additions and 68 deletions

View File

@@ -328,7 +328,7 @@ function Bookmarks() //{{{
args.completeFilter = have.pop();
let prefix = filter.substr(0, filter.length - args.completeFilter.length);
let tags = Array_([b.tags for ([k, b] in Iterator(cache.bookmarks))]).flatten().uniq();
let tags = util.Array.uniq(util.Array.flatten([b.tags for ([k, b] in Iterator(cache.bookmarks))]));
return [[prefix + tag, tag] for ([i, tag] in Iterator(tags)) if (have.indexOf(tag) < 0)];
}
@@ -1023,7 +1023,7 @@ function History() //{{{
let sh = window.getWebNavigation().sessionHistory;
let obj = [];
obj.index = sh.index;
obj.__iterator__ = function () Array_.iteritems(this);
obj.__iterator__ = function () util.Array.iteritems(this);
for (let i in util.range(0, sh.count))
{
obj[i] = { index: i, __proto__: sh.getEntryAtIndex(i, false) };
@@ -1044,7 +1044,7 @@ function History() //{{{
liberator.beep();
else
{
let index = Math_.constrain(current + steps, start, end);
let index = util.Math.constrain(current + steps, start, end);
window.getWebNavigation().gotoIndex(index);
}
},

View File

@@ -71,7 +71,7 @@ function Buffer() //{{{
{
let values = ZoomManager.zoomValues;
let cur = values.indexOf(ZoomManager.snap(ZoomManager.zoom));
let i = Math_.constrain(cur + steps, 0, values.length - 1);
let i = util.Math.constrain(cur + steps, 0, values.length - 1);
if (i == cur && fullZoom == ZoomManager.useFullZoom)
liberator.beep();
@@ -96,7 +96,7 @@ function Buffer() //{{{
if (win.scrollMaxX > 0 || win.scrollMaxY > 0)
return win;
for (let frame in Array_.itervalues(win.frames))
for (let frame in util.Array.itervalues(win.frames))
if (frame.scrollMaxX > 0 || frame.scrollMaxY > 0)
return frame;
@@ -359,7 +359,7 @@ function Buffer() //{{{
if (elements.length > 0)
{
count = Math_.constrain(count, 1, elements.length);
count = util.Math.constrain(count, 1, elements.length);
buffer.focusElement(elements[count - 1]);
}
else
@@ -648,7 +648,7 @@ function Buffer() //{{{
level = buffer.textZoom + parseInt(arg, 10);
// relative args shouldn't take us out of range
level = Math_.constrain(level, ZOOM_MIN, ZOOM_MAX);
level = util.Math.constrain(level, ZOOM_MIN, ZOOM_MAX);
}
else
return void liberator.echoerr("E488: Trailing characters");
@@ -805,7 +805,7 @@ function Buffer() //{{{
const ACCESS_READ = Ci.nsICache.ACCESS_READ;
let cacheKey = doc.location.toString().replace(/#.*$/, "");
for (let proto in Array_.itervalues(["HTTP", "FTP"]))
for (let proto in util.Array.itervalues(["HTTP", "FTP"]))
{
try
{

View File

@@ -460,7 +460,7 @@ function Commands() //{{{
__iterator__: function ()
{
let sorted = exCommands.sort(function (a, b) a.name > b.name);
return Array_.itervalues(sorted);
return util.Array.itervalues(sorted);
},
/** @property {string} The last executed Ex command line. */
@@ -652,7 +652,7 @@ function Commands() //{{{
argCount = "*";
var args = []; // parsed options
args.__iterator__ = function () Array_.iteritems(this);
args.__iterator__ = function () util.Array.iteritems(this);
args.string = str; // for access to the unparsed string
args.literalArg = "";
@@ -1150,7 +1150,7 @@ function Commands() //{{{
{
command: this.name,
bang: true,
options: Array_.toObject(
options: util.Array.toObject(
[[v, typeof cmd[k] == "boolean" ? null : cmd[k]]
// FIXME: this map is expressed multiple times
for ([k, v] in Iterator({ argCount: "-nargs", bang: "-bang", count: "-count", description: "-description" }))

View File

@@ -256,7 +256,7 @@ CompletionContext.prototype = {
let prefix = self.value.substring(minStart, context.offset);
return context.items.map(function makeItem(item) ({ text: prefix + item.text, item: item.item }));
});
return { start: minStart, items: Array_.flatten(items), longestSubstring: this.longestAllSubstring };
return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring };
}
catch (e)
{
@@ -279,7 +279,7 @@ CompletionContext.prototype = {
lists.pop());
if (!substrings) // FIXME: How is this undefined?
return [];
return Array_.uniq(substrings);
return util.Array.uniq(substrings);
},
// Temporary
get longestAllSubstring()

View File

@@ -198,7 +198,7 @@ function AutoCommands() //{{{
return {
__iterator__: function () Array_.itervalues(store),
__iterator__: function () util.Array.itervalues(store),
/**
* Adds a new autocommand. <b>cmd</b> will be executed when one of the

View File

@@ -786,7 +786,7 @@ function Hints() //{{{
/////////////////////////////////////////////////////////////////////////////{{{
const DEFAULT_HINTTAGS =
Array_(["input[not(@type='hidden')]", "a", "area", "iframe", "textarea", "button", "select"])
util.Array(["input[not(@type='hidden')]", "a", "area", "iframe", "textarea", "button", "select"])
.map(function (spec) [spec, "xhtml:" + spec]).flatten()
.concat("*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @role='link']")
.map(function (node) "//" + node).join(" | ");

View File

@@ -283,7 +283,7 @@ function IO() //{{{
// TODO: Use a set/specifiable list here:
let lines = [cmd.serial().map(commands.commandToString) for (cmd in commands) if (cmd.serial)];
lines = Array_.flatten(lines);
lines = util.Array.flatten(lines);
// source a user .vimperatorrc file
lines.unshift('"' + liberator.version + "\n");
@@ -399,7 +399,7 @@ function IO() //{{{
completion.charset = function (context) {
context.anchored = false;
context.generate = function () {
let names = Array_(
let names = util.Array(
"more1 more2 more3 more4 more5 unicode".split(" ").map(function (key)
options.getPref("intl.charsetmenu.browser." + key).split(', '))
).flatten().uniq();
@@ -477,7 +477,7 @@ function IO() //{{{
}
}
return Array_.flatten(commands);
return util.Array.flatten(commands);
};
};

View File

@@ -228,7 +228,7 @@ const liberator = (function () //{{{
{
let opts = [v.opts for ([k, v] in Iterator(groups))];
opts = opts.map(function (opt) [[k, v[0]] for ([k, v] in Iterator(opt))]);
return Array_.flatten(opts);
return util.Array.flatten(opts);
},
validator: function (val) Option.validateCompleter.call(this, val) &&
[v for ([k, v] in Iterator(groups))].every(function (g) !g.validator || g.validator(val))
@@ -880,7 +880,7 @@ const liberator = (function () //{{{
return Array.map(doc.getElementsByClassName("tag"),
function (elem) [elem.textContent, file]);
});
return Array_.flatten(res);
return util.Array.flatten(res);
};
};

View File

@@ -337,7 +337,7 @@ function Mappings() //{{{
function (context, obj, args)
{
let mode = args[0];
return Array_.flatten(
return util.Array.flatten(
[
[[name, map.description] for ([i, name] in Iterator(map.names))]
for ([i, map] in Iterator(user[mode].concat(main[mode])))

View File

@@ -129,7 +129,7 @@ const modes = (function () //{{{
NONE: 0,
__iterator__: function () Array_.itervalues(this.all),
__iterator__: function () util.Array.itervalues(this.all),
get all() mainModes.slice(),

View File

@@ -378,11 +378,11 @@ Option.prototype = {
switch (operator)
{
case "+":
newValue = Array_(this.values).concat(values).uniq(true);
newValue = util.Array.uniq(Array.concat(this.values, values), true);
break;
case "^":
// NOTE: Vim doesn't prepend if there's a match in the current value
newValue = Array_(values).concat(this.values).uniq(true);
newValue = util.Array.uniq(Array.concat(values, this.values), true);
break;
case "-":
newValue = this.values.filter(function (item) values.indexOf(item) == -1);

View File

@@ -470,7 +470,7 @@ function Styles(name, store)
sss.unregisterSheet(uri, agent ? sss.AGENT_SHEET : sss.USER_SHEET);
};
}
let (array = Array_)
let (array = util.Array)
{
util.extend(Styles.prototype, {
get sites() array([v.sites for ([k, v] in this.userSheets)]).flatten().uniq().__proto__,

View File

@@ -15,7 +15,7 @@ const template = { //{{{
map: function map(iter, func, sep, interruptable)
{
if (iter.length) // FIXME: Kludge?
iter = Array_.itervalues(iter);
iter = util.Array.itervalues(iter);
let ret = <></>;
let n = 0;
for each (let i in Iterator(iter))

View File

@@ -216,7 +216,7 @@ function CommandLine() //{{{
this.index += diff;
if (this.index < 0 || this.index > this.store.length)
{
this.index = Math_.constrain(this.index, 0, this.store.length);
this.index = util.Math.constrain(this.index, 0, this.store.length);
liberator.beep();
// I don't know why this kludge is needed. It
// prevents the caret from moving to the end of
@@ -436,7 +436,7 @@ function CommandLine() //{{{
idx = null;
break;
default:
idx = Math_.constrain(idx, 0, this.items.length - 1);
idx = util.Math.constrain(idx, 0, this.items.length - 1);
break;
}
@@ -525,7 +525,7 @@ function CommandLine() //{{{
if (this.type.list)
completionList.show();
this.wildIndex = Math_.constrain(this.wildIndex + 1, 0, this.wildtypes.length - 1);
this.wildIndex = util.Math.constrain(this.wildIndex + 1, 0, this.wildtypes.length - 1);
this.preview();
statusTimer.tell();
@@ -1895,7 +1895,7 @@ function ItemList(id) //{{{
let end = startIndex + options["maxitems"];
function getRows(context)
{
function fix(n) Math_.constrain(n, 0, len);
function fix(n) util.Math.constrain(n, 0, len);
let len = context.items.length;
let start = off;
end -= !!context.message + context.incomplete;
@@ -1924,7 +1924,7 @@ function ItemList(id) //{{{
for (let [i, row] in Iterator(context.getRows(start, end, doc)))
nodes[i] = row;
for (let [i, row] in Array_.iteritems(nodes))
for (let [i, row] in util.Array.iteritems(nodes))
{
if (!row)
continue;
@@ -2285,7 +2285,7 @@ function StatusLine() //{{{
// tab numbers set
if (options.get("guioptions").has("n", "N"))
{
for (let [i, tab] in Array_.iteritems(getBrowser().mTabs))
for (let [i, tab] in util.Array.iteritems(getBrowser().mTabs))
tab.setAttribute("ordinal", i + 1);
}

View File

@@ -183,9 +183,10 @@ const util = { //{{{
*
* @param {object} obj The object to alter.
* @param {string} key The name of the property to memoize.
* @param {function} getter A function of zero to two arguments which will
* return the property's value. <b>obj</b> is passed as the first
* argument, <b>key</b> as the second.
* @param {function} getter A function of zero to two arguments which
* will return the property's value. <b>obj</b> is
* passed as the first argument, <b>key</b> as the
* second.
*/
memoize: function memoize(obj, key, getter)
{
@@ -405,6 +406,23 @@ const util = { //{{{
return ary;
},
/**
* Math utility methods.
* @singleton
*/
Math: {
/**
* Returns the specified <b>value</b> constrained to the range <b>min</b> -
* <b>max</b>.
*
* @param {number} value The value to constrain.
* @param {number} min The minimum constraint.
* @param {number} max The maximum constraint.
* @returns {number}
*/
constrain: function constrain(value, min, max) Math.min(Math.max(min, value), max)
},
/**
* Converts a URI string into a URI object.
*
@@ -440,7 +458,7 @@ const util = { //{{{
if (typeof object != "object")
return false;
const NAMESPACES = Array_.toObject([
const NAMESPACES = util.Array.toObject([
[NS, 'liberator'],
[XHTML, 'html'],
[XUL, 'xul']
@@ -459,7 +477,7 @@ const util = { //{{{
}
let tag = "<" + [namespaced(elem)].concat(
[namespaced(a) + "=" + template.highlight(a.value, true)
for ([i, a] in Array_.iteritems(elem.attributes))]).join(" ");
for ([i, a] in util.Array.iteritems(elem.attributes))]).join(" ");
if (!elem.firstChild || /^\s*$/.test(elem.firstChild) && !elem.firstChild.nextSibling)
tag += '/>';
@@ -709,18 +727,19 @@ const util = { //{{{
}
}; //}}}
// TODO: Why don't we just push all util.BuiltinType up into modules? --djk
/**
* Array utility methods.
*/
var Array_ = function Array_(ary) {
util.Array = function Array_(ary) {
var obj = {
__proto__: ary,
__iterator__: function () this.iteritems(),
__noSuchMethod__: function (meth, args)
{
let res = (Array_[meth] || Array[meth]).apply(null, [this.__proto__].concat(args));
if (Array_.isinstance(res))
return Array_(res);
let res = (util.Array[meth] || Array[meth]).apply(null, [this.__proto__].concat(args));
if (util.Array.isinstance(res))
return util.Array(res);
return res;
},
concat: function () [].concat.apply(this.__proto__, arguments),
@@ -728,7 +747,7 @@ var Array_ = function Array_(ary) {
};
return obj;
}
Array_.isinstance = function isinstance(obj) {
util.Array.isinstance = function isinstance(obj) {
return Object.prototype.toString.call(obj) == "[object Array]";
};
/**
@@ -741,7 +760,7 @@ Array_.isinstance = function isinstance(obj) {
* @... {string} 0 - Key
* @... 1 - Value
*/
Array_.toObject = function toObject(assoc)
util.Array.toObject = function toObject(assoc)
{
let obj = {};
assoc.forEach(function ([k, v]) { obj[k] = v; });
@@ -756,7 +775,7 @@ Array_.toObject = function toObject(assoc)
* @param {Array} ary
* @returns {Array}
*/
Array_.flatten = function flatten(ary) Array.concat.apply([], ary),
util.Array.flatten = function flatten(ary) Array.concat.apply([], ary),
/**
* Returns an Iterator for an array's values.
@@ -764,7 +783,7 @@ Array_.flatten = function flatten(ary) Array.concat.apply([], ary),
* @param {Array} ary
* @returns {Iterator(Object)}
*/
Array_.itervalues = function itervalues(ary)
util.Array.itervalues = function itervalues(ary)
{
let length = ary.length;
for (let i = 0; i < length; i++)
@@ -777,7 +796,7 @@ Array_.itervalues = function itervalues(ary)
* @param {Array} ary
* @returns {Iterator([{number}, {Object}])}
*/
Array_.iteritems = function iteritems(ary)
util.Array.iteritems = function iteritems(ary)
{
let length = ary.length;
for (let i = 0; i < length; i++)
@@ -793,7 +812,7 @@ Array_.iteritems = function iteritems(ary)
* @param {boolean} unsorted
* @returns {Array}
*/
Array_.uniq = function uniq(ary, unsorted)
util.Array.uniq = function uniq(ary, unsorted)
{
let ret = [];
if (unsorted)
@@ -814,24 +833,6 @@ Array_.uniq = function uniq(ary, unsorted)
return ret;
};
/**
* Math utility methods.
* @singleton
*/
var Math_ = {
__proto__ : Math,
/**
* Returns the specified <b>value</b> constrained to the range <b>min</b> -
* <b>max</b>.
*
* @param {number} value The value to constrain.
* @param {number} min The minimum constraint.
* @param {number} max The maximum constraint.
* @returns {number}
*/
constrain: function constrain(value, min, max) Math.min(Math.max(min, value), max)
};
function Struct()
{
let self = this instanceof Struct ? this : new Struct();

View File

@@ -42,7 +42,7 @@ function Library() // {{{
{
let albums = toJSArray(MAIN_LIBRARY.getItemsByProperty(SBProperties.artistName, artist))
.map(function (track) track.getProperty(SBProperties.albumName));
return Array_.uniq(albums);
return util.Array.uniq(albums);
},
/**

View File

@@ -402,7 +402,7 @@ function Player() // {{{
if (/^[+-]/.test(arg))
level = player.volume + level;
player.volume = Math_.constrain(level, 0, 1);
player.volume = util.Math.constrain(level, 0, 1);
},
{ argCount: "1" });
@@ -567,7 +567,7 @@ function Player() // {{{
let min = 0;
let max = gMM.playbackControl.duration - 5000; // TODO: 5s buffer like cmus desirable?
gMM.playbackControl.position = Math_.constrain(position, min, max);
gMM.playbackControl.position = util.Math.constrain(position, min, max);
},
// FIXME: 10% ?