浏览代码

generated __string check that toString() return an object.

Nicolas Cannasse 19 年之前
父节点
当前提交
99ec0583db
共有 1 个文件被更改,包括 3 次插入1 次删除
  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 ->