Skip to content

Commit 7ed1189

Browse files
committed
add stacktrace
1 parent 6d5e2d0 commit 7ed1189

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

jscomp/core/js_dump.ml

+12-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ type cxt = Ext_pp_scope.t
136136
let semi f = P.string f L.semi
137137
let comma f = P.string f L.comma
138138

139-
let exn_block_as_obj (el : J.expression list) (ext : J.tag_info) : J.expression_desc =
139+
let exn_block_as_obj ~stack (el : J.expression list) (ext : J.tag_info) : J.expression_desc =
140140
let field_name =
141141
match ext with
142142
| Blk_extension -> (fun i ->
@@ -152,9 +152,13 @@ let exn_block_as_obj (el : J.expression list) (ext : J.tag_info) : J.expression_
152152
| i -> ss.(i-1))
153153
| _ -> assert false in
154154
Object (
155-
Ext_list.mapi el (fun i e -> field_name i, e)
155+
if stack then
156+
Ext_list.mapi_append el (fun i e -> field_name i, e)
157+
["Error",
158+
E.new_ (E.js_global "Error") []
159+
]
160+
else Ext_list.mapi el (fun i e -> field_name i, e)
156161
)
157-
(* @ ["Error", {expression_desc = New ({expression_desc = Var (Id (Ext_ident .(create_js "Error")));comment = None},None); comment = None}] *)
158162

159163
let rec iter_lst cxt (f : P.t) ls element inter =
160164
match ls with
@@ -839,7 +843,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
839843
(* name convention of Record is slight different from modules
840844
*)
841845
| Caml_block(el,_, _, (Blk_extension | Blk_record_ext _ as ext )) ->
842-
expression_desc cxt ~level f (exn_block_as_obj el ext)
846+
expression_desc cxt ~level f (exn_block_as_obj ~stack:false el ext)
843847
| Caml_block( el, mutable_flag, tag, tag_info)
844848
->
845849
(* Note that, if we ignore more than tag [0] we loose some information
@@ -1292,6 +1296,10 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
12921296
P.newline f;
12931297
statement_list false cxt f def ))
12941298
| Throw e ->
1299+
let e = match e.expression_desc with
1300+
| Caml_block (el,_,_,(Blk_extension | Blk_record_ext _ as ext)) ->
1301+
{e with expression_desc = exn_block_as_obj ~stack:true el ext}
1302+
| _ -> e in
12951303
P.string f L.throw;
12961304
P.space f ;
12971305
P.group f throw_indent (fun _ ->

0 commit comments

Comments
 (0)