Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10 from shivak/master

Fix indexOf()-related bug for IE
  • Loading branch information...
commit ce19ed52bdf8a14cffe1003330aadd6a700bef8f 2 parents 792f3fc + f5e31c4
@joshbuddy authored
Showing with 37 additions and 6 deletions.
  1. +37 −6 lib/sherpa.js
View
43 lib/sherpa.js
@@ -1,10 +1,41 @@
-if (!Array.prototype.indexOf) {
- Array.prototype.indexOf = function(obj, start) {
- for (var i = (start || 0), j = this.length; i < j; i++) {
- if (this[i] == obj) { return i; }
+if (!Array.prototype.indexOf)
+{
+ Array.prototype.indexOf = function(searchElement /*, fromIndex */)
+ {
+ "use strict";
+
+ if (this === void 0 || this === null)
+ throw new TypeError();
+
+ var t = 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 !== (1 / 0) && n !== -(1 / 0))
+ 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;
- }
+ };
}
RegExp.escape = function(text) {
@@ -64,7 +95,7 @@ Sherpa = {
var startIndex = 0;
var endIndex = 1;
- for (var charIndex in chars) {
+ for (var charIndex = 0; charIndex < chars.length; charIndex++) {
var c = chars[charIndex];
if (c == '(') {
// over current working set, double paths
Please sign in to comment.
Something went wrong with that request. Please try again.