Skip to content

Commit c36dc5f

Browse files
committed
Compiler: experiemental improved backtrace
1 parent 85b1ef4 commit c36dc5f

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

compiler/generate.ml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ module Share = struct
167167
["caml_trampoline";
168168
"caml_trampoline_return";
169169
"caml_wrap_exception";
170-
"caml_list_of_js_array"] in
170+
"caml_list_of_js_array";
171+
"caml_exn_with_js_backtrace"] in
171172
{count; vars = empty_aux; alias_strings; alias_prims; alias_apply}
172173

173174
let get_string gen s t =
@@ -931,6 +932,18 @@ let _ =
931932
(fun cx _ -> J.EUn(J.Typeof, cx))
932933

933934
(****)
935+
(* when raising ocaml exception and [improved_stacktrace] is enabled,
936+
tag the ocaml exception with a Javascript error (that contain js stacktrace).
937+
{[ throw e ]}
938+
becomes
939+
{[ throw (caml_exn_with_js_backtrace(e,false)) ]}
940+
*)
941+
let throw_statement cx loc =
942+
if not (Option.Optim.improved_stacktrace ())
943+
then
944+
[J.Throw_statement cx,loc]
945+
else
946+
[J.Throw_statement (J.ECall (s_var "caml_exn_with_js_backtrace",[cx;bool (J.ENum 0.)],loc)),loc]
934947

935948
let rec translate_expr ctx queue loc _x e level : _ * J.statement_list =
936949
match e with
@@ -1589,7 +1602,7 @@ and compile_conditional st queue pc last handler backs frontier interm succs =
15891602
flush_all queue [J.Return_statement (Some cx), loc]
15901603
| Raise x ->
15911604
let ((_px, cx), queue) = access_queue queue x in
1592-
flush_all queue [J.Throw_statement cx, loc]
1605+
flush_all queue (throw_statement cx loc)
15931606
| Stop ->
15941607
flush_all queue [J.Return_statement None, loc]
15951608
| Branch cont ->

compiler/option.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ module Optim = struct
9898
let debugger = o ~name:"debugger" ~default:true
9999
let genprim = o ~name:"genprim" ~default:true
100100
let excwrap = o ~name:"excwrap" ~default:true
101+
let improved_stacktrace = o ~name:"with-js-error" ~default:false
101102
let include_cmis = o ~name:"withcmi" ~default: true
102103
let warn_unused = o ~name:"warn-unused" ~default: false
103104

compiler/option.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module Optim : sig
4242
val debuginfo : unit -> bool
4343
val excwrap : unit -> bool
4444
val include_cmis: unit -> bool
45+
val improved_stacktrace : unit -> bool
4546

4647
val warn_unused : unit -> bool
4748
val inline_callgen : unit -> bool

0 commit comments

Comments
 (0)