Add an Array.indexOf polyfill and don't depend on underscore.js

Auditors: alpert
This commit is contained in:
Ben Eater
2014-01-14 17:37:16 -08:00
parent c45685e4ea
commit ee58c126fb
2 changed files with 33 additions and 12 deletions

View File

@@ -363,7 +363,7 @@ Parser.prototype.parseNucleus = function(pos) {
if (group) {
return new ParseResult(
new ParseNode("sizing", {
size: "size" + (_.indexOf(sizeFuncs, nucleus.type) + 1),
size: "size" + (sizeFuncs.indexOf(nucleus.type) + 1),
value: group.result
}),
group.position);

View File

@@ -1,17 +1,38 @@
function fastContains(list, elem) {
return list.indexOf(elem) !== -1;
}
function slowContains(list, elem) {
for (var i = 0; i < list.length; i++) {
if (list[i] === elem) {
return true;
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
}
}
return false;
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
fromIndex = +fromIndex || 0;
if (Math.abs(fromIndex) === Infinity) {
fromIndex = 0;
}
if (fromIndex < 0) {
fromIndex += length;
if (fromIndex < 0) {
fromIndex = 0;
}
}
for (;fromIndex < length; fromIndex++) {
if (this[fromIndex] === searchElement) {
return fromIndex;
}
}
return -1;
};
}
var contains = Array.prototype.indexOf ? fastContains : slowContains;
var contains = function(list, elem) {
return list.indexOf(elem) !== -1;
};
var setTextContent;