2
0
Эх сурвалжийг харах

fixed JS "catch" generation.

Nicolas Cannasse 19 жил өмнө
parent
commit
e7ce85d69c
1 өөрчлөгдсөн 14 нэмэгдсэн , 8 устгасан
  1. 14 8
      genjs.ml

+ 14 - 8
genjs.ml

@@ -285,25 +285,31 @@ and gen_expr ctx e =
 			match t with
 			| None -> 
 				last := true; 
+				spr ctx "{";
+				let bend = open_block ctx in
+				newline ctx;
 				print ctx "var %s = $e" v;
 				newline ctx;
 				gen_expr ctx e;
 				bend();
 				newline ctx;
+				spr ctx "}"
 			| Some t ->
-				print ctx "var %s = $e" v;
-				newline ctx;
 				spr ctx "if( js.Boot.__instanceof($e,";
 				gen_value ctx (mk (TType t) (mk_mono()) e.epos);
-				spr ctx ") ) ";
+				spr ctx ") ) {";
+				let bend = open_block ctx in
+				newline ctx;
+				print ctx "var %s = $e" v;
+				newline ctx;
 				gen_expr ctx e;
+				bend();
 				newline ctx;
+				spr ctx "} else "
 		) catchs;
-		if not !last then begin
-			spr ctx "throw($e)";
-			bend();
-			newline ctx;
-		end;		
+		if not !last then spr ctx "throw($e)";		
+		bend();
+		newline ctx;
 		spr ctx "}";
 	| TMatch (e,_,cases,def) ->
 		spr ctx "var $e = ";