@@ -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
935948let 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 ->
0 commit comments