@@ -23,6 +23,7 @@ open Type
23
23
open Typecore
24
24
open Error
25
25
open Globals
26
+ open FiltersCommon
26
27
27
28
(* * retrieve string from @:native metadata or raise Not_found *)
28
29
let get_native_name meta =
@@ -81,33 +82,6 @@ let rec add_final_return e =
81
82
{ e with eexpr = TFunction f }
82
83
| _ -> e
83
84
84
- let rec wrap_js_exceptions com e =
85
- let rec is_error t =
86
- match follow t with
87
- | TInst ({cl_path = (["js" ],"Error" )} ,_ ) -> true
88
- | TInst ({cl_super = Some (csup ,tl )} , _ ) -> is_error (TInst (csup,tl))
89
- | _ -> false
90
- in
91
- let rec loop e =
92
- match e.eexpr with
93
- | TThrow eerr when not (is_error eerr.etype) ->
94
- let terr = List. find (fun mt -> match mt with TClassDecl {cl_path = [" js" ;" _Boot" ],"HaxeError" } -> true | _ -> false ) com.types in
95
- let cerr = match terr with TClassDecl c -> c | _ -> assert false in
96
- (match eerr.etype with
97
- | TDynamic _ ->
98
- let eterr = Texpr.Builder. make_static_this cerr e.epos in
99
- let ewrap = Texpr.Builder. fcall eterr " wrap" [eerr] t_dynamic e.epos in
100
- { e with eexpr = TThrow ewrap }
101
- | _ ->
102
- let ewrap = { eerr with eexpr = TNew (cerr,[] ,[eerr]); etype = TInst (cerr,[] ) } in
103
- { e with eexpr = TThrow ewrap }
104
- )
105
- | _ ->
106
- Type. map_expr loop e
107
- in
108
-
109
- loop e
110
-
111
85
(* -------------------------------------------------------------------------- *)
112
86
(* CHECK LOCAL VARS INIT *)
113
87
@@ -441,25 +415,6 @@ let save_class_state ctx t = match t with
441
415
442
416
(* PASS 2 begin *)
443
417
444
- let rec is_removable_class c =
445
- match c.cl_kind with
446
- | KGeneric ->
447
- (Meta. has Meta. Remove c.cl_meta ||
448
- (match c.cl_super with
449
- | Some (c ,_ ) -> is_removable_class c
450
- | _ -> false ) ||
451
- List. exists (fun (_ ,t ) -> match follow t with
452
- | TInst (c ,_ ) ->
453
- has_ctor_constraint c || Meta. has Meta. Const c.cl_meta
454
- | _ ->
455
- false
456
- ) c.cl_params)
457
- | KTypeParameter _ ->
458
- (* this shouldn't happen, have to investigate (see #4092) *)
459
- true
460
- | _ ->
461
- false
462
-
463
418
let remove_generic_base ctx t = match t with
464
419
| TClassDecl c when is_removable_class c ->
465
420
c.cl_extern < - true
@@ -776,37 +731,6 @@ let check_reserved_type_paths ctx t =
776
731
777
732
(* PASS 3 end *)
778
733
779
- let run_expression_filters ctx filters t =
780
- let run e =
781
- List. fold_left (fun e f -> f e) e filters
782
- in
783
- match t with
784
- | TClassDecl c when is_removable_class c -> ()
785
- | TClassDecl c ->
786
- ctx.curclass < - c;
787
- let rec process_field f =
788
- ctx.curfield < - f;
789
- (match f.cf_expr with
790
- | Some e when not (is_removable_field ctx f) ->
791
- AbstractCast. cast_stack := f :: ! AbstractCast. cast_stack;
792
- f.cf_expr < - Some (run e);
793
- AbstractCast. cast_stack := List. tl ! AbstractCast. cast_stack;
794
- | _ -> () );
795
- List. iter process_field f.cf_overloads
796
- in
797
- List. iter process_field c.cl_ordered_fields;
798
- List. iter process_field c.cl_ordered_statics;
799
- (match c.cl_constructor with
800
- | None -> ()
801
- | Some f -> process_field f);
802
- (match c.cl_init with
803
- | None -> ()
804
- | Some e ->
805
- c.cl_init < - Some (run e));
806
- | TEnumDecl _ -> ()
807
- | TTypeDecl _ -> ()
808
- | TAbstractDecl _ -> ()
809
-
810
734
let pp_counter = ref 1
811
735
812
736
let is_cached t =
@@ -869,6 +793,8 @@ let run com tctx main =
869
793
filters @ [
870
794
TryCatchWrapper. configure_java com
871
795
]
796
+ | Js ->
797
+ filters @ [JsExceptions. init tctx];
872
798
| _ -> filters
873
799
in
874
800
let t = filter_timer detail_times [" expr 1" ] in
@@ -897,7 +823,6 @@ let run com tctx main =
897
823
let filters = [
898
824
Optimizer. sanitize com;
899
825
if com.config.pf_add_final_return then add_final_return else (fun e -> e);
900
- if com.platform = Js then wrap_js_exceptions com else (fun e -> e);
901
826
rename_local_vars tctx reserved;
902
827
mark_switch_break_loops;
903
828
] in
@@ -949,6 +874,7 @@ let run com tctx main =
949
874
] in
950
875
let type_filters = match com.platform with
951
876
| Cs -> type_filters @ [ fun _ t -> InterfaceProps. run t ]
877
+ | Js -> JsExceptions. inject_callstack com type_filters
952
878
| _ -> type_filters
953
879
in
954
880
let t = filter_timer detail_times [" type 3" ] in
0 commit comments