Browse Source

fixed Array.map/filter for as3

Nicolas Cannasse 12 years ago
parent
commit
2e0bba6468
2 changed files with 34 additions and 7 deletions
  1. 4 0
      genas3.ml
  2. 30 7
      std/flash/Boot.hx

+ 4 - 0
genas3.ml

@@ -511,6 +511,10 @@ and gen_field_access ctx t s =
 			print ctx "[\"%s\"]" s
 		| [], "String", "charCodeAt" ->
 			spr ctx "[\"charCodeAtHX\"]"
+		| [], "Array", "map" ->
+			spr ctx "[\"mapHX\"]"
+		| [], "Array", "filter" ->
+			spr ctx "[\"filterHX\"]"
 		| [], "Date", "toString" ->
 			print ctx "[\"toStringHX\"]"
 		| [], "String", "cca" ->

+ 30 - 7
std/flash/Boot.hx

@@ -231,6 +231,36 @@ class Boot extends flash.display.MovieClip {
 				}
 			}
 		};
+		aproto.setPropertyIsEnumerable("copy", false);
+		aproto.setPropertyIsEnumerable("insert", false);
+		aproto.setPropertyIsEnumerable("remove", false);
+		aproto.setPropertyIsEnumerable("iterator", false);
+		#if as3
+		aproto.filterHX = function(f) {
+			var ret = [];
+			var i = 0;
+			var l = __this__.length;
+			while ( i < l ) {
+				if (f(__this__[i]))
+					ret.push(__this__[i]);
+				i++;
+			}
+			return ret;
+		};
+		aproto.mapHX = function(f) {
+			var ret = [];
+			var i = 0;
+			var l = __this__.length;
+			while( i < l ) {
+				ret.push(f(__this__[i]));
+				i++;
+			}
+			return ret;
+		};
+		aproto.setPropertyIsEnumerable("mapHX", false);
+		aproto.setPropertyIsEnumerable("filterHX", false);
+		String.prototype.charCodeAtHX = function(i) : Null<Int> {
+		#else
 		aproto.filter = function(f) {
 			var ret = [];
 			var i = 0;
@@ -252,15 +282,8 @@ class Boot extends flash.display.MovieClip {
 			}
 			return ret;
 		};
-		aproto.setPropertyIsEnumerable("copy", false);
-		aproto.setPropertyIsEnumerable("insert", false);
-		aproto.setPropertyIsEnumerable("remove", false);
-		aproto.setPropertyIsEnumerable("iterator", false);
 		aproto.setPropertyIsEnumerable("map", false);
 		aproto.setPropertyIsEnumerable("filter", false);
-		#if as3
-		String.prototype.charCodeAtHX = function(i) : Null<Int> {
-		#else
 		String.prototype.charCodeAt = function(i) : Null<Int> {
 		#end
 			var s : String = __this__;