|
@@ -492,12 +492,7 @@ let catch_native ctx catches t p =
|
|
|
in
|
|
|
transform [] None catches
|
|
|
|
|
|
-(**
|
|
|
- Transform `throw` and `try..catch` expressions.
|
|
|
- `rename_locals` is required to deal with the names of temp vars.
|
|
|
-*)
|
|
|
-let filter tctx =
|
|
|
- let stub e = e in
|
|
|
+let create_exception_context tctx =
|
|
|
match tctx.com.platform with (* TODO: implement for all targets *)
|
|
|
| Php | Js | Jvm | Python | Lua | Eval | Neko | Flash | Hl | Cpp ->
|
|
|
let config = tctx.com.config.pf_exceptions in
|
|
@@ -549,6 +544,18 @@ let filter tctx =
|
|
|
value_exception_type = value_exception_type;
|
|
|
value_exception_class = value_exception_class;
|
|
|
} in
|
|
|
+ Some ctx
|
|
|
+ | Cross | CustomTarget _ ->
|
|
|
+ None
|
|
|
+
|
|
|
+(**
|
|
|
+ Transform `throw` and `try..catch` expressions.
|
|
|
+ `rename_locals` is required to deal with the names of temp vars.
|
|
|
+*)
|
|
|
+let filter ectx =
|
|
|
+ let stub e = e in
|
|
|
+ match ectx with
|
|
|
+ | Some ctx ->
|
|
|
let rec run e =
|
|
|
match e.eexpr with
|
|
|
| TThrow e1 ->
|
|
@@ -566,22 +573,18 @@ let filter tctx =
|
|
|
if contains_throw_or_try e then run e
|
|
|
else stub e
|
|
|
)
|
|
|
- | Cross | CustomTarget _ -> stub
|
|
|
+ | None ->
|
|
|
+ stub
|
|
|
|
|
|
(**
|
|
|
Inserts `haxe.NativeStackTrace.saveStack(e)` in non-haxe.Exception catches.
|
|
|
*)
|
|
|
-let insert_save_stacks tctx =
|
|
|
+let insert_save_stacks ectx =
|
|
|
+ let tctx = ectx.typer in
|
|
|
if not (has_feature tctx.com "haxe.NativeStackTrace.exceptionStack") then
|
|
|
(fun e -> e)
|
|
|
else
|
|
|
- let native_stack_trace_cls =
|
|
|
- let tp = mk_type_path (["haxe"],"NativeStackTrace") in
|
|
|
- match Typeload.load_type_def tctx null_pos tp with
|
|
|
- | TClassDecl cls -> cls
|
|
|
- | TAbstractDecl { a_impl = Some cls } -> cls
|
|
|
- | _ -> raise_typing_error "haxe.NativeStackTrace is expected to be a class or an abstract" null_pos
|
|
|
- in
|
|
|
+ let native_stack_trace_cls = ectx.haxe_native_stack_trace in
|
|
|
let rec contains_insertion_points e =
|
|
|
match e.eexpr with
|
|
|
| TTry (e, catches) ->
|
|
@@ -639,12 +642,19 @@ let insert_save_stacks tctx =
|
|
|
else e
|
|
|
)
|
|
|
|
|
|
+let insert_save_stacks tctx ectx =
|
|
|
+ match ectx with
|
|
|
+ | Some ctx ->
|
|
|
+ insert_save_stacks {ctx with typer = tctx}
|
|
|
+ | None ->
|
|
|
+ (fun e -> e)
|
|
|
+
|
|
|
(**
|
|
|
Adds `this.__shiftStack()` calls to constructors of classes which extend `haxe.Exception`
|
|
|
*)
|
|
|
-let patch_constructors tctx =
|
|
|
- let tp = make_ptp (mk_type_path haxe_exception_type_path) null_pos in
|
|
|
- match Typeload.load_instance tctx tp ParamSpawnMonos LoadNormal with
|
|
|
+let patch_constructors ectx =
|
|
|
+ let tctx = ectx.typer in
|
|
|
+ match ectx.haxe_exception_type with
|
|
|
(* Add only if `__shiftStack` method exists *)
|
|
|
| TInst(cls,_) when PMap.mem "__shiftStack" cls.cl_fields ->
|
|
|
(fun mt ->
|
|
@@ -694,3 +704,10 @@ let patch_constructors tctx =
|
|
|
| _ -> ()
|
|
|
)
|
|
|
| _ -> (fun _ -> ())
|
|
|
+
|
|
|
+let patch_constructors tctx ectx =
|
|
|
+ match ectx with
|
|
|
+ | Some ctx ->
|
|
|
+ patch_constructors {ctx with typer = tctx}
|
|
|
+ | None ->
|
|
|
+ (fun _ -> ())
|