Browse Source

[js] fix Std.string with objects that have non-function toString field (closes #3480)

Dan Korostelev 11 years ago
parent
commit
34849d14e9
2 changed files with 13 additions and 4 deletions
  1. 4 4
      std/js/Boot.hx
  2. 9 0
      tests/unit/src/unit/issues/Issue3480.hx

+ 4 - 4
std/js/Boot.hx

@@ -123,7 +123,7 @@ class Boot {
 					// strange error on IE
 					return "???";
 				}
-				if( tostr != null && tostr != __js__("Object.toString") ) {
+				if( tostr != null && tostr != __js__("Object.toString") && __typeof__(tostr) == "function" ) {
 					var s2 = o.toString();
 					if( s2 != "[object Object]")
 						return s2;
@@ -212,7 +212,7 @@ class Boot {
 		if (__instanceof(o, t)) return o;
 		else throw "Cannot cast " +Std.string(o) + " to " +Std.string(t);
 	}
-	
+
 	static var __toStr = untyped __js__("{}.toString");
 	// get native JS [[Class]]
 	static function __nativeClassName(o:Dynamic):String {
@@ -223,12 +223,12 @@ class Boot {
 			return null;
 		return name;
 	}
-	
+
 	// check for usable native JS object
 	static function __isNativeObj(o:Dynamic):Bool {
 		return __nativeClassName(o) != null;
 	}
-	
+
 	// resolve native JS class (with window or global):
 	static function __resolveNativeClass(name:String) untyped {
 		if (__js__("typeof window") != "undefined")

+ 9 - 0
tests/unit/src/unit/issues/Issue3480.hx

@@ -0,0 +1,9 @@
+package unit.issues;
+
+class Issue3480 extends Test {
+    function test() {
+        #if js
+        eq("{\n\ttoString : 1\n}", Std.string({toString: 1}));
+        #end
+    }
+}