summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDoug Kearns <dougkearns@gmail.com>2009-09-15 13:13:07 +1000
committerDoug Kearns <dougkearns@gmail.com>2009-09-15 13:20:06 +1000
commitdbc99ad9566d15b18bc0c397c3b431901b41b85d (patch)
tree96539e77f84989f36caa56dc92cb3e468c336939 /common
parent66f86d2da43c63f3f570c16ce7e7fe7d724728e2 (diff)
downloadpentadactyl-dbc99ad9566d15b18bc0c397c3b431901b41b85d.tar.gz
Revert "Move util.Array to modules.Array_."
This reverts commit d6cdda48a18c9fa05365b50046470fec9935fd3c. Array_ method chaining needs fixing.
Diffstat (limited to 'common')
-rw-r--r--common/content/bookmarks.js6
-rw-r--r--common/content/buffer.js10
-rw-r--r--common/content/commands.js6
-rw-r--r--common/content/completion.js4
-rw-r--r--common/content/events.js2
-rw-r--r--common/content/hints.js2
-rw-r--r--common/content/io.js6
-rw-r--r--common/content/liberator.js4
-rw-r--r--common/content/mappings.js2
-rw-r--r--common/content/modes.js2
-rw-r--r--common/content/options.js4
-rw-r--r--common/content/style.js2
-rw-r--r--common/content/template.js2
-rw-r--r--common/content/ui.js12
-rw-r--r--common/content/util.js67
15 files changed, 66 insertions, 65 deletions
diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js
index 1bd0e22a..e546033c 100644
--- a/common/content/bookmarks.js
+++ b/common/content/bookmarks.js
@@ -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);
}
},
diff --git a/common/content/buffer.js b/common/content/buffer.js
index 5492c439..cc7f0b94 100644
--- a/common/content/buffer.js
+++ b/common/content/buffer.js
@@ -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
{
diff --git a/common/content/commands.js b/common/content/commands.js
index 9b523583..d7fcaa10 100644
--- a/common/content/commands.js
+++ b/common/content/commands.js
@@ -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" }))
diff --git a/common/content/completion.js b/common/content/completion.js
index f2276dcb..30740f2b 100644
--- a/common/content/completion.js
+++ b/common/content/completion.js
@@ -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()
diff --git a/common/content/events.js b/common/content/events.js
index 343f6038..5d76c2dd 100644
--- a/common/content/events.js
+++ b/common/content/events.js
@@ -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
diff --git a/common/content/hints.js b/common/content/hints.js
index cba49632..9646d3f8 100644
--- a/common/content/hints.js
+++ b/common/content/hints.js
@@ -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(" | ");
diff --git a/common/content/io.js b/common/content/io.js
index d666ca0e..724d0f7b 100644
--- a/common/content/io.js
+++ b/common/content/io.js
@@ -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);
};
};
diff --git a/common/content/liberator.js b/common/content/liberator.js
index c4d00496..f2058ae2 100644
--- a/common/content/liberator.js
+++ b/common/content/liberator.js
@@ -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);
};
};
diff --git a/common/content/mappings.js b/common/content/mappings.js
index d0cc32fd..32bf284d 100644
--- a/common/content/mappings.js
+++ b/common/content/mappings.js
@@ -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])))
diff --git a/common/content/modes.js b/common/content/modes.js
index c130c23a..f578084a 100644
--- a/common/content/modes.js
+++ b/common/content/modes.js
@@ -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(),
diff --git a/common/content/options.js b/common/content/options.js
index f310c3a8..8d3f4c19 100644
--- a/common/content/options.js
+++ b/common/content/options.js
@@ -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);
diff --git a/common/content/style.js b/common/content/style.js
index 3b9b0f27..b9ec5b88 100644
--- a/common/content/style.js
+++ b/common/content/style.js
@@ -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__,
diff --git a/common/content/template.js b/common/content/template.js
index 4dab16da..ae0ff09d 100644
--- a/common/content/template.js
+++ b/common/content/template.js
@@ -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))
diff --git a/common/content/ui.js b/common/content/ui.js
index 575e94b1..be9927c4 100644
--- a/common/content/ui.js
+++ b/common/content/ui.js
@@ -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);
}
diff --git a/common/content/util.js b/common/content/util.js
index 365ba401..a8e410bc 100644
--- a/common/content/util.js
+++ b/common/content/util.js
@@ -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)
{
@@ -406,6 +407,23 @@ const util = { //{{{
},
/**
+ * 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.
*
* @param {string} uri
@@ -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();