Browse Source

[js] do not try to be too clever about enum printing

We just keep `__string_rec` as soon as we keep the enum because at that point it doesn't really matter anymore anyway. There are too many problems where enums might be printed hidden behind Dynamic or something else otherwise.
Simon Krajewski 10 years ago
parent
commit
15e8bb321d
4 changed files with 5 additions and 10 deletions
  1. 1 0
      extra/CHANGES.txt
  2. 0 6
      filters.ml
  3. 3 3
      genjs.ml
  4. 1 1
      std/js/Boot.hx

+ 1 - 0
extra/CHANGES.txt

@@ -3,6 +3,7 @@
 	Bugfixes:
 
 	js : added variable number of arguments support in js.html.* classes
+	js : fixed DCE issue related to printing enums
 
 	General improvements and optimizations:
 

+ 0 - 6
filters.ml

@@ -705,12 +705,6 @@ let rename_local_vars ctx e =
 	e
 
 let check_unification ctx e t =
-	begin match follow e.etype,follow t with
-		| TEnum _,TDynamic _ ->
-			Hashtbl.replace ctx.curclass.cl_module.m_extra.m_features "may_print_enum" true;
-		| _ ->
-			()
-	end;
 	begin match e.eexpr,t with
 		| TLocal v,TType({t_path = ["cs"],("Ref" | "Out")},_) ->
 			(* TODO: this smells of hack, but we have to deal with it somehow *)

+ 3 - 3
genjs.ml

@@ -1099,14 +1099,14 @@ let generate_enum ctx e =
 		| TFun (args,_) ->
 			let sargs = String.concat "," (List.map (fun (n,_,_) -> ident n) args) in
 			print ctx "function(%s) { var $x = [\"%s\",%d,%s]; $x.__enum__ = %s;" sargs f.ef_name f.ef_index sargs p;
-			if has_feature ctx "may_print_enum" then
+			if has_feature ctx "has_enum" then
 				spr ctx " $x.toString = $estr;";
 			spr ctx " return $x; }";
 			ctx.separator <- true;
 		| _ ->
 			print ctx "[\"%s\",%d]" f.ef_name f.ef_index;
 			newline ctx;
-			if has_feature ctx "may_print_enum" then begin
+			if has_feature ctx "has_enum" then begin
 				print ctx "%s%s.toString = $estr" p (field f.ef_name);
 				newline ctx;
 			end;
@@ -1329,7 +1329,7 @@ let generate com =
 	(* TODO: fix $estr *)
 	let vars = [] in
 	let vars = (if has_feature ctx "Type.resolveClass" || has_feature ctx "Type.resolveEnum" then ("$hxClasses = " ^ (if ctx.js_modern then "{}" else "$hxClasses || {}")) :: vars else vars) in
-	let vars = if has_feature ctx "may_print_enum"
+	let vars = if has_feature ctx "has_enum"
 		then ("$estr = function() { return " ^ (ctx.type_accessor (TClassDecl { null_class with cl_path = ["js"],"Boot" })) ^ ".__string_rec(this,''); }") :: vars
 		else vars in
 	(match List.rev vars with

+ 1 - 1
std/js/Boot.hx

@@ -93,7 +93,7 @@ class Boot {
 		}
 	}
 
-	@:ifFeature("may_print_enum")
+	@:ifFeature("has_enum")
 	private static function __string_rec(o,s:String) {
 		untyped {
 			if( o == null )