Przeglądaj źródła

[python] fix Reflect.isFunction(f) is f is anon object
fixes #8593

Aleksandr Kuzmenko 6 lat temu
rodzic
commit
d90776c698
2 zmienionych plików z 16 dodań i 1 usunięć
  1. 7 1
      std/python/_std/Reflect.hx
  2. 9 0
      tests/unit/src/unit/TestJson.hx

+ 7 - 1
std/python/_std/Reflect.hx

@@ -81,7 +81,13 @@ class Reflect {
 	}
 	}
 
 
 	public static function isFunction(f:Dynamic):Bool {
 	public static function isFunction(f:Dynamic):Bool {
-		return Inspect.isfunction(f) || Inspect.ismethod(f) || UBuiltins.hasattr(f, "func_code");
+		if (Inspect.isfunction(f) || Inspect.ismethod(f)) {
+			return true;
+		}
+		if (Boot.isAnonObject(f)) {
+			return Syntax.code("{0}._hx_hasattr({1})", f, "func_code");
+		}
+		return UBuiltins.hasattr(f, "func_code");
 	}
 	}
 
 
 	public static function compare<T>(a:T, b:T):Int {
 	public static function compare<T>(a:T, b:T):Int {

+ 9 - 0
tests/unit/src/unit/TestJson.hx

@@ -100,6 +100,15 @@ class TestJson extends Test {
 		eq( parsed.y, 1.456 );
 		eq( parsed.y, 1.456 );
 	}
 	}
 
 
+	function test8593_stringifyNestedObjects() {
+		var src = {
+			one: {
+				two: "three"
+			}
+		};
+		eq('{"one":{"two":"three"}}', haxe.Json.stringify(src));
+	}
+
 	#if (!neko && (cpp && !cppia && !hxcpp_smart_strings))
 	#if (!neko && (cpp && !cppia && !hxcpp_smart_strings))
 	function test8228() {
 	function test8228() {
 		var strJson = haxe.Json.stringify("👽");
 		var strJson = haxe.Json.stringify("👽");