|
@@ -139,6 +139,27 @@ let rec add_final_return e =
|
|
|
{ e with eexpr = TFunction f }
|
|
|
| _ -> e
|
|
|
|
|
|
+let rec wrap_js_exceptions com e =
|
|
|
+ let terr = List.find (fun mt -> match mt with TClassDecl {cl_path = ["js";"_Boot"],"HaxeError"} -> true | _ -> false) com.types in
|
|
|
+ let cerr = match terr with TClassDecl c -> c | _ -> assert false in
|
|
|
+
|
|
|
+ let rec is_error = function
|
|
|
+ | TInst ({cl_path = (["js"],"Error")},_) -> true
|
|
|
+ | TInst ({cl_super = Some (csup,tl)}, _) -> is_error (TInst (csup,tl))
|
|
|
+ | _ -> false
|
|
|
+ in
|
|
|
+
|
|
|
+ let rec loop e =
|
|
|
+ match e.eexpr with
|
|
|
+ | TThrow eerr when not (is_error eerr.etype) ->
|
|
|
+ let ewrap = { eerr with eexpr = TNew (cerr,[],[eerr]) } in
|
|
|
+ { e with eexpr = TThrow ewrap }
|
|
|
+ | _ ->
|
|
|
+ Type.map_expr loop e
|
|
|
+ in
|
|
|
+
|
|
|
+ loop e
|
|
|
+
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
(* CHECK LOCAL VARS INIT *)
|
|
|
|
|
@@ -1088,6 +1109,7 @@ let run com tctx main =
|
|
|
let filters = [
|
|
|
Optimizer.sanitize com;
|
|
|
if com.config.pf_add_final_return then add_final_return else (fun e -> e);
|
|
|
+ if com.platform = Js then wrap_js_exceptions com else (fun e -> e);
|
|
|
rename_local_vars tctx;
|
|
|
] in
|
|
|
List.iter (run_expression_filters tctx filters) new_types;
|
|
@@ -1113,6 +1135,7 @@ let run com tctx main =
|
|
|
captured_vars com;
|
|
|
promote_complex_rhs com;
|
|
|
if com.config.pf_add_final_return then add_final_return else (fun e -> e);
|
|
|
+ if com.platform = Js then wrap_js_exceptions com else (fun e -> e);
|
|
|
rename_local_vars tctx;
|
|
|
] in
|
|
|
List.iter (run_expression_filters tctx filters) new_types;
|