Skip to content

Commit 6e0e311

Browse files
authored
Revert #6611 (#7016)
* Revert #6611 * format * update CHANGELOG.md
1 parent d9d5800 commit 6e0e311

File tree

238 files changed

+15673
-18232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+15673
-18232
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 12.0.0-alpha.3 (Unreleased)
1414

15+
#### :bug: Bug fix
16+
17+
- Revert Throws an instance of JavaScript's `new Error()` and adds the extension payload for `cause` option introduced in https://github.com/rescript-lang/rescript-compiler/pull/6611. https://github.com/rescript-lang/rescript-compiler/pull/7016
18+
1519
# 12.0.0-alpha.2
1620

1721
#### :rocket: New Feature
@@ -2623,4 +2627,4 @@ Features:
26232627
26242628
# 1.0.0
26252629
2626-
Initial release
2630+
Initial release

jscomp/core/js_dump.ml

+10-30
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ type cxt = Ext_pp_scope.t
9797
let semi f = P.string f L.semi
9898
let comma f = P.string f L.comma
9999

100-
let new_error name cause =
101-
E.new_ (E.js_global Js_dump_lit.error) [ name; cause ]
102-
103100
let exn_block_as_obj ~(stack : bool) (el : J.expression list) (ext : J.tag_info)
104-
: J.expression =
101+
: J.expression_desc =
105102
let field_name =
106103
match ext with
107104
| Blk_extension -> (
@@ -111,29 +108,12 @@ let exn_block_as_obj ~(stack : bool) (el : J.expression list) (ext : J.tag_info)
111108
fun i -> match i with 0 -> Literals.exception_id | i -> ss.(i - 1))
112109
| _ -> assert false
113110
in
114-
let cause =
115-
{
116-
J.expression_desc =
117-
Object (List.mapi (fun i e -> (Js_op.Lit (field_name i), e)) el);
118-
comment = None;
119-
}
120-
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-
}
111+
Object
112+
(if stack then
113+
Ext_list.mapi_append el
114+
(fun i e -> (Js_op.Lit (field_name i), e))
115+
[ (Js_op.Lit "Error", E.new_ (E.js_global "Error") []) ]
116+
else Ext_list.mapi el (fun i e -> (Js_op.Lit (field_name i), e)))
137117

138118
let rec iter_lst cxt (f : P.t) ls element inter =
139119
match ls with
@@ -777,7 +757,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
777757
])
778758
| _ -> assert false)
779759
| Caml_block (el, _, _, ((Blk_extension | Blk_record_ext _) as ext)) ->
780-
expression cxt ~level f (exn_block_as_obj ~stack:false el ext)
760+
expression_desc cxt ~level f (exn_block_as_obj ~stack:false el ext)
781761
| Caml_block (el, _, tag, Blk_record_inlined p) ->
782762
let untagged = Ast_untagged_variants.process_untagged p.attrs in
783763
let objs =
@@ -1239,8 +1219,8 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
12391219
let e =
12401220
match e.expression_desc with
12411221
| Caml_block (el, _, _, ((Blk_extension | Blk_record_ext _) as ext)) ->
1242-
{ e with expression_desc = (exn_block_as_obj ~stack:true el ext).expression_desc }
1243-
| exp -> { e with expression_desc = (exn_ref_as_obj exp).expression_desc }
1222+
{ e with expression_desc = exn_block_as_obj ~stack:true el ext }
1223+
| _ -> e
12441224
in
12451225
P.string f L.throw;
12461226
P.space f;

jscomp/core/js_dump_lit.ml

-6
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,3 @@ let block_variant = "variant"
168168
let block_simple_variant = "simpleVariant"
169169

170170
let case = "case"
171-
172-
let cause = "cause"
173-
174-
let error = "Error"
175-
176-
let exception_id = "RE_EXN_ID"

jscomp/core/js_exp_make.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ let poly_var_value_access (e : t) =
416416
comment = None;
417417
}
418418

419-
let extension_access (e : t) ?name (pos : int32) : t =
419+
let extension_access (e : t) name (pos : int32) : t =
420420
match e.expression_desc with
421421
| Array (l, _) (* Float i -- should not appear here *)
422422
| Caml_block (l, _, _, _)

jscomp/core/js_exp_make.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ val variant_access : t -> int32 -> t
170170

171171
val cons_access : t -> int32 -> t
172172

173-
val extension_access : t -> ?name:string -> Int32.t -> t
173+
val extension_access : t -> string option -> Int32.t -> t
174174

175175
val record_assign : t -> int32 -> string -> t -> t
176176

jscomp/core/js_of_lam_block.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ let field (field_info : Lam_compat.field_dbg_info) e (i : int32) =
3838
e i
3939
| Fld_poly_var_content -> E.poly_var_value_access e
4040
| Fld_poly_var_tag -> E.poly_var_tag_access e
41-
| Fld_record_extension { name } -> E.extension_access e ~name i
42-
| Fld_extension -> E.extension_access e i
41+
| Fld_record_extension { name } -> E.extension_access e (Some name) i
42+
| Fld_extension -> E.extension_access e None i
4343
| Fld_variant -> E.variant_access e i
4444
| Fld_cons -> E.cons_access e i
4545
| Fld_record_inline { name } -> E.inline_record_access e name i

jscomp/core/lam_convert.ml

+6-9
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
let caml_id_field_info : Lambda.field_dbg_info =
26+
Fld_record { name = Literals.exception_id; mutable_flag = Immutable }
27+
28+
let lam_caml_id : Lam_primitive.t = Pfield (0, caml_id_field_info)
2529
let prim = Lam.prim
2630

27-
let lam_extension_id =
28-
let lam_caml_id : Lam_primitive.t =
29-
let caml_id_field_info : Lambda.field_dbg_info =
30-
Fld_record { name = Js_dump_lit.exception_id; mutable_flag = Immutable }
31-
in
32-
Pfield (0, caml_id_field_info)
33-
in
34-
fun loc (head : Lam.t) ->
35-
prim ~primitive:lam_caml_id ~args:[ head ] loc
31+
let lam_extension_id loc (head : Lam.t) =
32+
prim ~primitive:lam_caml_id ~args:[ head ] loc
3633

3734
let lazy_block_info : Lam_tag_info.t =
3835
Blk_record

jscomp/runtime/caml_format.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ let float_of_string: (string, exn) => float = %raw(`function(s,exn){
709709
return Infinity;
710710
if (/^-inf(inity)?$/i.test(s))
711711
return -Infinity;
712-
throw new Error(exn.RE_EXN_ID, { cause: exn });;
712+
throw exn;
713713
}
714714
`)
715715

jscomp/runtime/caml_js_exceptions.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ type js_error = {cause: exn}
2929
[Error] is defined here
3030
*/
3131
let internalToOCamlException = (e: unknown) =>
32-
if Caml_exceptions.is_extension((Obj.magic(e): js_error).cause) {
33-
(Obj.magic(e): js_error).cause
32+
if Caml_exceptions.is_extension(e) {
33+
(Obj.magic(e): exn)
3434
} else {
3535
JsError(e)
3636
}

jscomp/runtime/caml_lexer.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ let caml_lex_engine_aux: (
160160
if (state < 0) {
161161
lexbuf.lex_curr_pos = lexbuf.lex_last_pos;
162162
if (lexbuf.lex_last_action == -1)
163-
throw new Error(exn.RE_EXN_ID, { cause: exn })
163+
throw exn
164164
else
165165
return lexbuf.lex_last_action;
166166
}
@@ -308,7 +308,7 @@ let caml_new_lex_engine_aux: (
308308
if (state < 0) {
309309
lexbuf.lex_curr_pos = lexbuf.lex_last_pos;
310310
if (lexbuf.lex_last_action == -1)
311-
throw new Error(exn.RE_EXN_ID, { cause: exn });
311+
throw exn;
312312
else
313313
return lexbuf.lex_last_action;
314314
}

jscomp/test/406_primitive_test.js

+6-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/UncurriedExternals.js

+4-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/adt_optimize_test.js

+9-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/argv_test.js

+18-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/arith_parser.js

+10-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/arity_infer.js

+12-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/array_safe_get.js

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)