Преглед изворни кода

[As3] clarified Reflect.field/setField limitation (fixed issue #1848)

Simon Krajewski пре 12 година
родитељ
комит
79286b5381
2 измењених фајлова са 11 додато и 1 уклоњено
  1. 6 0
      std/Reflect.hx
  2. 5 1
      tests/unit/unitstd/Reflect.unit.hx

+ 6 - 0
std/Reflect.hx

@@ -45,6 +45,9 @@ extern class Reflect {
 		to [Reflect.getProperty] for a function supporting property accessors.
 		
 		If [field] is null, the result is unspecified.
+		
+		(As3) If used on a property field, the getter will be invoked. It is
+		not possible to obtain the value directly.
 	**/
 	public static function field( o : Dynamic, field : String ) : Dynamic;
 
@@ -55,6 +58,9 @@ extern class Reflect {
 		work for anonymous structures.
 		
 		If [o] or [field] are null, the result is unspecified.
+		
+		(As3) If used on a property field, the setter will be invoked. It is
+		not possible to set the value directly.		
 	**/
 	public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void;
 

+ 5 - 1
tests/unit/unitstd/Reflect.unit.hx

@@ -13,7 +13,8 @@ var c = new C2();
 Reflect.field(c, "v") == "var";
 Reflect.field(c, "prop") == "prop";
 Reflect.field(c, "func")() == "foo";
-Reflect.field(c, "propAcc") == "0";
+// As3 invokes the getter
+Reflect.field(c, "propAcc") == #if as3 "1" #else "0" #end;
 Reflect.field(null, null) == null;
 Reflect.field(1, "foo") == null;
 
@@ -52,7 +53,10 @@ c.v == "bar";
 //Reflect.setProperty(c, "func2", function() return "x");
 //Reflect.field(c, "func2")() == "x";
 Reflect.setProperty(c, "propAcc", "abc");
+#if !as3
+// not supported on AS3
 Reflect.field(c, "propAcc") == "ABC";
+#end
 
 // fields
 var names = ["a", "b", "c"];