Permalink
Browse files

Add a shim for Array.prototype.indexOf

Apparently, whatever JavaScript engine WSH uses, it doesn't support
Array.prototype.indexOf method so I had to add a shim for it. I took
the original version from MDN and modified it to pass our lint tests.

Closes GH-617.
  • Loading branch information...
1 parent 892cfdd commit c047ea1b01097fcc220fcd1a55c41f67ae2e6e81 @valueof valueof committed Aug 20, 2012
Showing with 40 additions and 2 deletions.
  1. +40 −2 jshint.js
View
@@ -189,7 +189,7 @@
Timer, Tips, Type, TypeError, Toggle, Try, "use strict", unescape, URI, URIError, URL,
VBArray, WSH, WScript, XDomainRequest, Web, Window, XMLDOM, XMLHttpRequest, XMLSerializer,
XPathEvaluator, XPathException, XPathExpression, XPathNamespace, XPathNSResolver, XPathResult,
- "\\", a, addEventListener, address, alert, apply, applicationCache, arguments, arity,
+ "\\", a, abs, addEventListener, address, alert, apply, applicationCache, arguments, arity,
asi, atob, b, basic, basicToken, bitwise, blacklist, block, blur, boolOptions, boss,
browser, btoa, c, call, callee, caller, camelcase, cases, charAt, charCodeAt, character,
clearInterval, clearTimeout, close, closed, closure, comment, condition, confirm, console,
@@ -205,7 +205,7 @@
isDigit, isFinite, isNaN, iterator, java, join, jshint,
JSHINT, json, jquery, jQuery, keys, label, labelled, last, lastcharacter, lastsemic, laxbreak,
laxcomma, latedef, lbp, led, left, length, line, load, loadClass, localStorage, location,
- log, loopfunc, m, match, maxerr, maxlen, member,message, meta, module, moveBy,
+ log, loopfunc, m, match, max, maxerr, maxlen, member,message, meta, module, moveBy,
moveTo, mootools, multistr, name, navigator, new, newcap, noarg, node, noempty, nomen,
nonew, nonstandard, nud, onbeforeunload, onblur, onerror, onevar, onecase, onfocus,
onload, onresize, onunload, open, openDatabase, openURL, opener, opera, options, outer, param,
@@ -836,6 +836,44 @@ var JSHINT = (function () {
};
}
+ if (!Array.prototype.indexOf) {
+ Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
+ if (this === null || this === undefined) {
+ throw new TypeError();
+ }
+
+ var t = new Object(this);
+ var len = t.length >>> 0;
+
+ if (len === 0) {
+ return -1;
+ }
+
+ var n = 0;
+ if (arguments.length > 0) {
+ n = Number(arguments[1]);
+ if (n != n) { // shortcut for verifying if it's NaN
+ n = 0;
+ } else if (n !== 0 && n != Infinity && n != -Infinity) {
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
+ }
+ }
+
+ if (n >= len) {
+ return -1;
+ }
+
+ var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
+ for (; k < len; k++) {
+ if (k in t && t[k] === searchElement) {
+ return k;
+ }
+ }
+
+ return -1;
+ };
+ }
+
if (typeof Object.create !== "function") {
Object.create = function (o) {
F.prototype = o;

0 comments on commit c047ea1

Please sign in to comment.