Don't change global prototype: local utils.indexOf

Auditors: eater
This commit is contained in:
Ben Alpert 2014-01-14 19:52:08 -08:00
parent ee58c126fb
commit 99e7710020
2 changed files with 18 additions and 32 deletions

View File

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

View File

@ -1,37 +1,22 @@
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf var nativeIndexOf = Array.prototype.indexOf;
if (!Array.prototype.indexOf) { var indexOf = function(list, elem) {
Array.prototype.indexOf = function (searchElement, fromIndex) { if (list == null) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
}
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; return -1;
}; }
} if (nativeIndexOf && list.indexOf === nativeIndexOf) {
return list.indexOf(elem);
}
var i = 0, l = list.length;
for (; i < l; i++) {
if (list[i] === elem) {
return i;
}
}
return -1;
};
var contains = function(list, elem) { var contains = function(list, elem) {
return list.indexOf(elem) !== -1; return indexOf(list, elem) !== -1;
}; };
var setTextContent; var setTextContent;
@ -53,6 +38,7 @@ function clearNode(node) {
module.exports = { module.exports = {
contains: contains, contains: contains,
indexOf: indexOf,
setTextContent: setTextContent, setTextContent: setTextContent,
clearNode: clearNode clearNode: clearNode
}; };