Browse Source

generated __string check that toString() return an object.

Nicolas Cannasse 19 năm trước cách đây
mục cha
commit
99ec0583db
1 tập tin đã thay đổi với 3 bổ sung1 xóa
  1. 3 1
      genneko.ml

+ 3 - 1
genneko.ml

@@ -287,7 +287,9 @@ let gen_class c =
 		match follow f.cf_type with
 		| TFun ([],_) ->
 			["__string",(EFunction ([],(EBlock [
-				EReturn (Some (field p (call p (field p (this p) "toString") []) "__s")),p
+				EVars ["@s",Some (call p (field p (this p) "toString") [])] ,p;
+				EIf ((EBinop ("!=",call p (builtin p "typeof") [ident p "@s"],builtin p "tobject"),p),(EReturn (Some (null p)),p),None),p;
+				EReturn (Some (field p (ident p "@s") "__s")),p;
 			],p)),p)]
 		| _ -> []
 	with Not_found ->