@@ -97,10 +97,7 @@ type cxt = Ext_pp_scope.t
97
97
let semi f = P. string f L. semi
98
98
let comma f = P. string f L. comma
99
99
100
- let new_error name cause =
101
- E. new_ (E. js_global Js_dump_lit. error) [ name; cause ]
102
-
103
- let exn_block_as_obj ~(stack : bool ) (el : J.expression list ) (ext : J.tag_info )
100
+ let exn_block_as_obj ~(is_exception : bool ) (el : J.expression list ) (ext : J.tag_info )
104
101
: J.expression =
105
102
let field_name =
106
103
match ext with
@@ -111,29 +108,18 @@ let exn_block_as_obj ~(stack : bool) (el : J.expression list) (ext : J.tag_info)
111
108
fun i -> match i with 0 -> Literals. exception_id | i -> ss.(i - 1 ))
112
109
| _ -> assert false
113
110
in
114
- let cause =
111
+ let extension =
115
112
{
116
113
J. expression_desc =
117
114
Object (List. mapi (fun i e -> (Js_op. Lit (field_name i), e)) el);
118
115
comment = None ;
119
116
}
120
117
in
121
- if stack then
122
- new_error (List. hd el)
123
- {
124
- J. expression_desc = Object [ (Lit Js_dump_lit. cause, cause) ];
125
- comment = None ;
126
- }
127
- else cause
128
-
129
- let exn_ref_as_obj e : J.expression =
130
- let cause = { J. expression_desc = e; comment = None ; } in
131
- new_error
132
- (E. record_access cause Js_dump_lit. exception_id 0l )
133
- {
134
- J. expression_desc = Object [ (Lit Js_dump_lit. cause, cause) ];
135
- comment = None ;
136
- }
118
+ if is_exception then
119
+ match el with
120
+ | [extension_id] -> E. runtime_call Js_runtime_modules. caml_js_exceptions " internalMakeExn" [extension_id]
121
+ | _ -> E. runtime_call Js_runtime_modules. caml_js_exceptions " internalFromExtension" [extension]
122
+ else extension
137
123
138
124
let rec iter_lst cxt (f : P.t ) ls element inter =
139
125
match ls with
@@ -774,8 +760,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
774
760
(Lit Literals. polyvar_value, value);
775
761
])
776
762
| _ -> assert false )
777
- | Caml_block (el , _ , _ , ((Blk_extension _ | Blk_record_ext _ ) as ext )) ->
778
- expression cxt ~level f (exn_block_as_obj ~stack: false el ext)
763
+ | Caml_block (el , _ , _ , ((Blk_extension { is_exception } | Blk_record_ext { is_exception} ) as ext )) ->
764
+ expression cxt ~level f (exn_block_as_obj ~is_exception el ext)
779
765
| Caml_block (el , _ , tag , Blk_record_inlined p ) ->
780
766
let untagged = Ast_untagged_variants. process_untagged p.attrs in
781
767
let objs =
@@ -1234,12 +1220,6 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
1234
1220
P. newline f;
1235
1221
statements false cxt f def))
1236
1222
| Throw e ->
1237
- let e =
1238
- match e.expression_desc with
1239
- | Caml_block (el , _ , _ , ((Blk_extension _ | Blk_record_ext _ ) as ext )) ->
1240
- { e with expression_desc = (exn_block_as_obj ~stack: true el ext).expression_desc }
1241
- | exp -> { e with expression_desc = (exn_ref_as_obj exp).expression_desc }
1242
- in
1243
1223
P. string f L. throw;
1244
1224
P. space f;
1245
1225
P. group f 0 (fun _ ->
0 commit comments