2
0
Эх сурвалжийг харах

[java/cs] unit tests-related fixes

Caue Waneck 12 жил өмнө
parent
commit
2a16e41cfb

+ 18 - 8
gencommon.ml

@@ -6823,14 +6823,17 @@ struct
                 mk_this_call_raw fn (TFun(["value",false,cf.cf_type], cf.cf_type)) [ value_local ];
                 mk_return value_local
               ] in
-              {
-                eexpr = TIf(
-                  handle_prop_local,
-                  { eexpr = TBlock bl; etype = value_local.etype; epos = pos },
-                  Some ret);
-                etype = value_local.etype;
-                epos = pos;
-              }
+              if Type.is_extern_field cf then
+                { eexpr = TBlock bl; etype = value_local.etype; epos = pos }
+              else
+                {
+                  eexpr = TIf(
+                    handle_prop_local,
+                    { eexpr = TBlock bl; etype = value_local.etype; epos = pos },
+                    Some ret);
+                  etype = value_local.etype;
+                  epos = pos;
+                }
             | _ ->
               ret
         in
@@ -6868,6 +6871,8 @@ struct
 
          let get_field cf cf_type ethis cl name =
           match cf.cf_kind with
+            | Var { v_read = AccCall fn } when Type.is_extern_field cf ->
+              mk_return (mk_this_call_raw fn (TFun(["value",false,cf.cf_type], cf.cf_type)) [  ])
             | Var { v_read = AccCall fn } ->
               {
                 eexpr = TIf(
@@ -6918,6 +6923,11 @@ struct
 
       let mk_switch static =
         let fields = get_fields static in
+        let fields = List.filter (fun (_, cf) -> match is_set, cf.cf_kind with
+          | true, Var { v_write = AccCall _ } -> true
+          | false, Var { v_read = AccCall _ } -> true
+          | _ -> not (Type.is_extern_field cf)) fields
+        in
         (if fields <> [] then has_fields := true);
         let cases = List.map (fun (names, cf) ->
           (if names = [] then assert false);

+ 6 - 1
gencs.ml

@@ -1275,7 +1275,7 @@ let configure gen =
 
     (match cf.cf_kind with
       | Var _
-      | Method (MethDynamic) ->
+      | Method (MethDynamic) when not (Type.is_extern_field cf) ->
         (if is_overload || List.exists (fun cf -> cf.cf_expr <> None) cf.cf_overloads then
           gen.gcon.error "Only normal (non-dynamic) methods can be overloaded" cf.cf_pos);
         if not is_interface then begin
@@ -1290,6 +1290,11 @@ let configure gen =
               print w "%s %s%s %s %s;" access (if is_static then "static " else "") (String.concat " " modifiers) (t_s (run_follow gen cf.cf_type)) (change_field name)
           )
         end (* TODO see how (get,set) variable handle when they are interfaces *)
+      | Method _ when Type.is_extern_field cf ->
+        List.iter (fun cf -> if cl.cl_interface || cf.cf_expr <> None then
+          gen_class_field w ~is_overload:true is_static cl (Meta.has Meta.Final cf.cf_meta) cf
+        ) cf.cf_overloads
+      | Var _ | Method MethDynamic -> ()
       | Method mkind ->
         List.iter (fun cf ->
           if cl.cl_interface || cf.cf_expr <> None then

+ 7 - 6
genjava.ml

@@ -164,11 +164,7 @@ struct
         | TCall( { eexpr = TField( _, FStatic({ cl_path = (["java";"lang"], "Math") }, { cf_name = "ceil" }) ) }, _) ->
           mk_cast basic.tint (Type.map_expr run e)
         | TCall( ( { eexpr = TField( _, FStatic({ cl_path = (["java";"lang"], "Math") }, { cf_name = "isFinite" }) ) } as efield ), [v]) ->
-          { e with eexpr =
-            TUnop(Ast.Not, Ast.Prefix, {
-              e with eexpr = TCall( mk_static_field_access_infer float_cl "_isInfinite" efield.epos [], [run v] )
-            })
-          }
+          { e with eexpr = TCall( mk_static_field_access_infer runtime_cl "isFinite" efield.epos [], [run v] ) }
         (* end of math changes *)
 
         (* Std.is() *)
@@ -1382,7 +1378,7 @@ let configure gen =
     in
     (match cf.cf_kind with
       | Var _
-      | Method (MethDynamic) ->
+      | Method (MethDynamic) when not (Type.is_extern_field cf) ->
         (if is_overload || List.exists (fun cf -> cf.cf_expr <> None) cf.cf_overloads then
           gen.gcon.error "Only normal (non-dynamic) methods can be overloaded" cf.cf_pos);
         if not is_interface then begin
@@ -1396,6 +1392,11 @@ let configure gen =
             | None -> write w ";"
           )
         end (* TODO see how (get,set) variable handle when they are interfaces *)
+      | Method _ when Type.is_extern_field cf ->
+        List.iter (fun cf -> if cl.cl_interface || cf.cf_expr <> None then
+          gen_class_field w ~is_overload:true is_static cl (Meta.has Meta.Final cf.cf_meta) cf
+        ) cf.cf_overloads
+      | Var _ | Method MethDynamic -> ()
       | Method mkind ->
         List.iter (fun cf ->
           if cl.cl_interface || cf.cf_expr <> None then

+ 5 - 0
std/cs/_std/Reflect.hx

@@ -101,6 +101,9 @@ import cs.internal.Function;
 		if (o is haxe.lang.IHxObject)
 			return ((haxe.lang.IHxObject) o).__hx_getField(field, haxe.lang.FieldLookup.hash(field), false, false, true);
 
+		if (haxe.lang.Runtime.hasField(o, "get_" + field))
+			return haxe.lang.Runtime.slowCallField(o, "get_" + field, null);
+
 		return haxe.lang.Runtime.slowGetField(o, field, false);
 	')
 	public static function getProperty( o : Dynamic, field : String ) : Dynamic
@@ -114,6 +117,8 @@ import cs.internal.Function;
 	@:functionCode('
 		if (o is haxe.lang.IHxObject)
 			((haxe.lang.IHxObject) o).__hx_setField(field, haxe.lang.FieldLookup.hash(field), value, true);
+		else if (haxe.lang.Runtime.hasField(o, "set_" + field))
+			haxe.lang.Runtime.slowCallField(o, "set_" + field, new Array<object>(new object[]{value}));
 		else
 			haxe.lang.Runtime.slowSetField(o, field, value);
 	')

+ 2 - 2
std/cs/_std/Type.hx

@@ -181,9 +181,9 @@ import cs.internal.Runtime;
 	}
 
 	@:functionCode('
-		if (@params == null)
+		if (@params == null || @params.length == 0)
 		{
-			object ret = haxe.lang.Runtime.slowGetField(e, constr, false);
+			object ret = haxe.lang.Runtime.slowGetField(e, constr, true);
 			if (ret is haxe.lang.Function)
 				throw haxe.lang.HaxeException.wrap("Constructor " + constr + " needs parameters");
 			return (T) ret;

+ 1 - 1
std/cs/_std/Xml.hx

@@ -293,7 +293,7 @@ private enum RealXmlType {
 
 	public function toString() : String {
 		if( nodeType == Xml.PCData )
-			return _nodeValue;
+			return StringTools.htmlEscape(_nodeValue);
 		if( nodeType == Xml.CData )
 			return "<![CDATA["+_nodeValue+"]]>";
 		if( nodeType == Xml.Comment )

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
std/cs/internal/HxObject.hx


+ 1 - 0
std/cs/internal/Runtime.hx

@@ -665,6 +665,7 @@ import cs.system.Type;
 		return null;
 	}
 
+
 	//TODO: change from genericCast to getConverter, so we don't need to handle extra boxing associated with it
 	/*@:functionCode('
 		if (typeof(To).TypeHandle == typeof(double).TypeHandle)

+ 5 - 0
std/java/_std/Reflect.hx

@@ -102,6 +102,9 @@ import java.Boot;
 		if (o instanceof haxe.lang.IHxObject)
 			return ((haxe.lang.IHxObject) o).__hx_getField(field, false, false, true);
 
+		if (haxe.lang.Runtime.slowHasField(o, "get_" + field))
+			return haxe.lang.Runtime.slowCallField(o, "get_" + field, null);
+
 		return haxe.lang.Runtime.slowGetField(o, field, false);
 	')
 	public static function getProperty( o : Dynamic, field : String ) : Dynamic
@@ -115,6 +118,8 @@ import java.Boot;
 	@:functionCode('
 		if (o instanceof haxe.lang.IHxObject)
 			((haxe.lang.IHxObject) o).__hx_setField(field, value, true);
+		else if (haxe.lang.Runtime.slowHasField(o, "set_" + field))
+			haxe.lang.Runtime.slowCallField(o, "set_" + field, new Array( new java.lang.Object[]{value} ));
 		else
 			haxe.lang.Runtime.slowSetField(o, field, value);
 	')

+ 1 - 1
std/java/_std/Std.hx

@@ -52,7 +52,7 @@ import java.internal.Exceptions;
 		return untyped clt.isAssignableFrom(clv);
 	}
 
-	public static inline function string( s : Dynamic ) : String {
+	public static function string( s : Dynamic ) : String {
 		return cast s;
 	}
 

+ 1 - 1
std/java/_std/Type.hx

@@ -249,7 +249,7 @@
 	@:functionCode('
 		if (params == null || params.length == 0)
 		{
-			java.lang.Object ret = haxe.lang.Runtime.slowGetField(e, constr, false);
+			java.lang.Object ret = haxe.lang.Runtime.slowGetField(e, constr, true);
 			if (ret instanceof haxe.lang.Function)
 				throw haxe.lang.HaxeException.wrap("Constructor " + constr + " needs parameters");
 			return (T) ret;

+ 1 - 1
std/java/_std/Xml.hx

@@ -293,7 +293,7 @@ private enum RealXmlType {
 
 	public function toString() : String {
 		if( nodeType == Xml.PCData )
-			return _nodeValue;
+			return StringTools.htmlEscape(_nodeValue);
 		if( nodeType == Xml.CData )
 			return "<![CDATA["+_nodeValue+"]]>";
 		if( nodeType == Xml.Comment )

+ 1 - 1
std/java/_std/haxe/Int64.hx

@@ -37,7 +37,7 @@ private typedef NativeInt64 = Int;
 
 	public static inline function getLow( x : Int64 ) : Int
 	{
-		return cast (x.asNative() & 0xFFFFFFFF.mkNative());
+		return cast (x.asNative() & untyped __java__("0xFFFFFFFFL"));
 	}
 
 	public static inline function getHigh( x : Int64 ) : Int

+ 1 - 1
std/java/internal/HxObject.hx

@@ -85,7 +85,7 @@ private class Enum
 	}
 	public function toString():String
 	{
-		if (params == null) return getTag();
+		if (params == null || params.length == 0) return getTag();
 		var ret = new StringBuf();
 		ret.add(getTag()); ret.add("(");
 		var first = true;

+ 6 - 1
std/java/internal/Runtime.hx

@@ -239,7 +239,7 @@ package java.internal;
 
 	@:functionCode('
 			if (v1 instanceof java.lang.String || v2 instanceof java.lang.String)
-				return (v1 + "") + (v2 + "");
+				return toString(v1) + toString(v2);
 
 			if (v1 instanceof java.lang.Number || v2 instanceof java.lang.Number)
 			{
@@ -560,6 +560,11 @@ package java.internal;
 			return (cast(obj, Int)) + "";
 		return untyped obj.toString();
 	}
+
+	public static function isFinite(v:Float):Bool
+	{
+		return (v == v) && !java.lang.Double._isInfinite(v);
+	}
 }
 
 @:keep @:native("haxe.lang.EmptyObject") private enum EmptyObject

+ 2 - 0
tests/unit/Test.hx

@@ -149,10 +149,12 @@ class Test #if swf_mark implements mt.Protect #end {
 		}
 		haxe.Log.trace(msg,pos);
 		reportCount++;
+#if !(java || cs)
 		if( reportCount == 50 ) {
 			trace("Too many errors");
 			report = function(msg,?pos) {};
 		}
+#end
 	}
 
 	static function checkDone() {

+ 6 - 6
tests/unit/TestSpecification.hx

@@ -10,11 +10,11 @@ typedef T = {
 	public function func() { }
 	public var v:String;
 	public var prop(default, null):String;
-	
+
 	static function staticFunc() { }
 	static public var staticVar:String;
 	static var staticProp(default, null):String;
-	
+
 	public function new() {
 		v = "var";
 		prop = "prop";
@@ -37,7 +37,7 @@ private class ClassWithToString {
 }
 
 private class ClassWithToStringChild extends ClassWithToString {
-	
+
 }
 
 private class ClassWithToStringChild2 extends ClassWithToString {
@@ -54,7 +54,7 @@ private class ClassWithToStringChild2 extends ClassWithToString {
 }
 
 private class ClassWithCtorDefaultValuesChild extends ClassWithCtorDefaultValues {
-	
+
 }
 
 private enum SomeEnum<T> {
@@ -64,11 +64,11 @@ private enum SomeEnum<T> {
 
 private class IntWrap {
 	public var i(default, null):Int;
-	
+
 	public function new(i:Int) {
 		this.i = i;
 	}
-	
+
 	static public function compare(a:IntWrap, b:IntWrap) {
 		return if (a.i == b.i) 0;
 			else if (a.i > b.i) 1;

+ 16 - 16
tests/unit/TestXML.hx

@@ -14,14 +14,14 @@ class TestXML extends Test {
 		var x = Xml.parse('<a href="hello">World<b/></a>');
 
 		t( x.firstChild() == x.firstChild() );
-		
+
 		eq( x.nodeType, Xml.Document );
 		checkExc(x);
 
 		x = x.firstChild();
 		eq( x.nodeType, Xml.Element );
 
-		
+
 		// nodeName
 		eq( x.nodeName, "a" );
 		x.nodeName = "b";
@@ -124,7 +124,7 @@ class TestXML extends Test {
 
 		eq( Xml.createCData("<x>").toString(), "<![CDATA[<x>]]>" );
 		eq( Xml.createComment("Hello").toString(), "<!--Hello-->" );
-		
+
 		#if flash9
 		eq( Xml.createProcessingInstruction("XHTML").toString(), "<?XHTML ?>");
 		// doctype is parsed but not printed
@@ -133,7 +133,7 @@ class TestXML extends Test {
 		eq( Xml.createProcessingInstruction("XHTML").toString(), "<?XHTML?>");
 		eq( Xml.createDocType("XHTML").toString(), "<!DOCTYPE XHTML>" );
 		#end
-				
+
 		eq( Xml.parse("<!--Hello-->").firstChild().nodeValue, "Hello" );
 		var c = Xml.createComment("Hello");
 		eq( c.nodeValue, "Hello" );
@@ -190,20 +190,20 @@ class TestXML extends Test {
 			exc(function() for (x in xml) null);
 		}
 	}
-	
+
 	function testEntities() {
 		var entities = ["&lt;", "&gt;", "&quot;", "&amp;", "&apos;", "&nbsp;", "&euro;", "&#64;", "&#244;", "&#x3F;", "&#xFF;"];
 		var values = entities.copy();
-		#if (flash || js)
+		#if (flash || js || cs || java)
 		// flash parser does support XML + some HTML entities (nbsp only ?) + character codes entities
 		values = ['<', '>', '"', '&', "'", String.fromCharCode(160), '&euro;', '@', 'ô', '?', 'ÿ'];
 		#end
-		
+
 		#if flash9
 		// for a very strange reason, flash9 uses a non standard charcode for non breaking space
 		values[5] = String.fromCharCode(65440);
 		#end
-		
+
 		#if php
 		// &nbsp; and &euro; creates an invalid entity error (first time I see PHP being strict !)
 		entities[5] = "x";
@@ -211,33 +211,33 @@ class TestXML extends Test {
 		// character codes entities are supported
 		values = ["&lt;", "&gt;", "&quot;", "&amp;", "&apos;", "x", "x", '@', 'ô', '?', 'ÿ'];
 		#end
-		
+
 		for( i in 0...entities.length ) {
 			infos(entities[i]);
 			eq( Xml.parse(entities[i]).firstChild().nodeValue, values[i] );
 		}
 	}
-	
+
 	function testCustomXmlParser() {
 		var entities = ["&lt;", "&gt;", "&quot;", "&amp;", "&apos;", "&euro;", "&#64;", "&#244;", "&#x3F;", "&#xFF;"];
 		var values = ['<', '>', '"', '&', "'", '&euro;', '@', String.fromCharCode(244), String.fromCharCode(0x3F), String.fromCharCode(0xFF)];
-		
-		for( i in 0...entities.length ) {
+
+		for( i in 0...entities.length) {
 			infos(entities[i]);
 			eq( haxe.xml.Parser.parse(entities[i]).firstChild().nodeValue, values[i] );
 		}
-		
+
 		var s = "<a>&gt;<b>&lt;</b>&lt;&gt;<b>&gt;&lt;</b>\"</a>";
 		var xml = haxe.xml.Parser.parse(s);
 		eq(s, xml.toString());
 	}
-	
+
 	function testMore() {
 		var doc = Xml.parse("<a>A</a><i>I</i>");
 		var aElement = doc.elementsNamed('a').next();
 		var iElement = doc.elementsNamed('i').next();
 		iElement.addChild(aElement);
-		
+
 		eq(doc.toString(), "<i>I<a>A</a></i>");
 	}
-}
+}

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно