1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 11:18:00 +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

@@ -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();