Browse Source

Fix array iterators (array length change during iteration)

Pascal Peridont 19 years ago
parent
commit
78dbf545f5
3 changed files with 13 additions and 19 deletions
  1. 4 5
      std/flash/Boot.hx
  2. 3 4
      std/js/Boot.hx
  3. 6 10
      std/neko/NekoArray__.hx

+ 4 - 5
std/flash/Boot.hx

@@ -216,10 +216,9 @@ class Boot {
 			Array.prototype.iterator = function() {
 				return {
 					cur : 0,
-					max : this.length,
 					arr : this,
 					hasNext : function() {
-						return this.cur < this.max;
+						return this.cur < this.arr.length;
 					},
 					next : function() {
 						return this.arr[this.cur++];
@@ -229,9 +228,9 @@ class Boot {
 			Array.prototype.indexes = function() {
 				return {
 					cur : 0,
-					max : this.length,
+					arr : this,
 					hasNext : function() {
-						return this.cur < this.max;
+						return this.cur < this.arr.length;
 					},
 					next : function() {
 						return this.cur++;
@@ -280,4 +279,4 @@ class Boot {
 		}
 	}
 
-}
+}

+ 3 - 4
std/js/Boot.hx

@@ -190,10 +190,9 @@ class Boot {
 			Array.prototype.iterator = function() {
 				return {
 					cur : 0,
-					max : this.length,
 					arr : this,
 					hasNext : function() {
-						return this.cur < this.max;
+						return this.cur < this.arr.length;
 					},
 					next : function() {
 						return this.arr[this.cur++];
@@ -203,9 +202,9 @@ class Boot {
 			Array.prototype.indexes = function() {
 				return {
 					cur : 0,
-					max : this.length,
+					arr : this,
 					hasNext : function() {
-						return this.cur < this.max;
+						return this.cur < this.arr.length;
 					},
 					next : function() {
 						return this.cur++;

+ 6 - 10
std/neko/NekoArray__.hx

@@ -65,30 +65,26 @@ class NekoArray__<T> implements Array<T> {
 
 	public function indexes() {
 		return untyped {
-			a : this.__a,
+			a : this,
 			p : 0,
-			l : this.length,
 			hasNext : function() {
-				return this.p < this.l;
+				return this.p < this.a.length;
 			},
 			next : function() {
-				var i = this.p;
-				this.p += 1;
-				return i;
+				return this.p++;
 			}
 		};
 	}
 
 	public function iterator() {
 		return untyped {
-			a : this.__a,
+			a : this,
 			p : 0,
-			l : this.length,
 			hasNext : function() {
-				return this.p < this.l;
+				return this.p < this.a.length;
 			},
 			next : function() {
-				var i = this.a[this.p];
+				var i = this.a.__a[this.p];
 				this.p += 1;
 				return i;
 			}