diff --git a/jscomp/core/js_dump.ml b/jscomp/core/js_dump.ml index a09885ae2f..be468f21b3 100644 --- a/jscomp/core/js_dump.ml +++ b/jscomp/core/js_dump.ml @@ -100,7 +100,7 @@ let comma f = P.string f L.comma let new_error name cause = E.new_ (E.js_global Js_dump_lit.error) [ name; cause ] -let exn_block_as_obj ~(stack : bool) (el : J.expression list) (ext : J.tag_info) +let exn_block_as_obj (el : J.expression list) (ext : J.tag_info) : J.expression = let field_name = match ext with @@ -118,18 +118,7 @@ let exn_block_as_obj ~(stack : bool) (el : J.expression list) (ext : J.tag_info) comment = None; } in - if stack then - new_error (List.hd el) - { - J.expression_desc = Object [ (Lit Js_dump_lit.cause, cause) ]; - comment = None; - } - else cause - -let exn_ref_as_obj e : J.expression = - let cause = { J.expression_desc = e; comment = None; } in - new_error - (E.record_access cause Js_dump_lit.exception_id 0l) + new_error (List.hd el) { J.expression_desc = Object [ (Lit Js_dump_lit.cause, cause) ]; comment = None; @@ -749,7 +738,7 @@ and expression_desc cxt ~(level : int) f x : cxt = ]) | _ -> assert false) | Caml_block (el, _, _, ((Blk_extension | Blk_record_ext _) as ext)) -> - expression cxt ~level f (exn_block_as_obj ~stack:false el ext) + expression cxt ~level f (exn_block_as_obj el ext) | Caml_block (el, _, tag, Blk_record_inlined p) -> let untagged = Ast_untagged_variants.process_untagged p.attrs in let objs = @@ -1207,12 +1196,6 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt = P.newline f; statements false cxt f def)) | Throw e -> - let e = - match e.expression_desc with - | Caml_block (el, _, _, ((Blk_extension | Blk_record_ext _) as ext)) -> - { e with expression_desc = (exn_block_as_obj ~stack:true el ext).expression_desc } - | exp -> { e with expression_desc = (exn_ref_as_obj exp).expression_desc } - in P.string f L.throw; P.space f; P.group f 0 (fun _ -> diff --git a/jscomp/core/js_exp_make.ml b/jscomp/core/js_exp_make.ml index 229a99337b..c51729144b 100644 --- a/jscomp/core/js_exp_make.ml +++ b/jscomp/core/js_exp_make.ml @@ -309,9 +309,6 @@ let eight_int_literal : t = let nine_int_literal : t = { expression_desc = Number (Int { i = 9l; c = None }); comment = None } -let obj_int_tag_literal : t = - { expression_desc = Number (Int { i = 248l; c = None }); comment = None } - let int ?comment ?c i : t = { expression_desc = Number (Int { i; c }); comment } let bigint ?comment sign i : t = { expression_desc = Number (BigInt {positive=sign; value=i}); comment} @@ -330,7 +327,6 @@ let small_int i : t = | 7 -> seven_int_literal | 8 -> eight_int_literal | 9 -> nine_int_literal - | 248 -> obj_int_tag_literal | i -> int (Int32.of_int i) let true_ : t = { comment = None; expression_desc = Bool true } diff --git a/jscomp/core/js_exp_make.mli b/jscomp/core/js_exp_make.mli index 63b50a916d..22c0ed63d4 100644 --- a/jscomp/core/js_exp_make.mli +++ b/jscomp/core/js_exp_make.mli @@ -122,7 +122,6 @@ val zero_int_literal : t (* val one_int_literal : t *) val zero_float_lit : t -(* val obj_int_tag_literal : t *) val zero_bigint_literal : t diff --git a/jscomp/runtime/caml_hash.res b/jscomp/runtime/caml_hash.res index b33bedb049..edf0575e2a 100644 --- a/jscomp/runtime/caml_hash.res +++ b/jscomp/runtime/caml_hash.res @@ -117,22 +117,18 @@ let hash = (count: int, _limit, seed: int, obj: Obj.t): int => { if size != 0 { let obj_tag = Obj.tag(obj) let tag = lor(lsl(size, 10), obj_tag) - if obj_tag == 248 /* Obj.object_tag */ { - s.contents = hash_mix_int(s.contents, (Obj.obj(Obj.field(obj, 1)): int)) - } else { - s.contents = hash_mix_int(s.contents, tag) - let block = { - let v = size - 1 - if v < num.contents { - v - } else { - num.contents - } - } - for i in 0 to block { - push_back(queue, Obj.field(obj, i)) + s.contents = hash_mix_int(s.contents, tag) + let block = { + let v = size - 1 + if v < num.contents { + v + } else { + num.contents } } + for i in 0 to block { + push_back(queue, Obj.field(obj, i)) + } } else { let size: int = %raw(`function(obj,cb){ var size = 0 diff --git a/jscomp/runtime/caml_obj.res b/jscomp/runtime/caml_obj.res index f9fcff04f0..2a8e97381b 100644 --- a/jscomp/runtime/caml_obj.res +++ b/jscomp/runtime/caml_obj.res @@ -198,11 +198,7 @@ let rec compare = (a: Obj.t, b: Obj.t): int => } else { let tag_a = Obj.tag(a) let tag_b = Obj.tag(b) - if tag_a == 248 /* object/exception */ { - Pervasives.compare((Obj.magic(Obj.field(a, 1)): int), Obj.magic(Obj.field(b, 1))) - } else if tag_a == 251 /* abstract_tag */ { - raise(Invalid_argument("equal: abstract value")) - } else if tag_a != tag_b { + if tag_a != tag_b { if tag_a < tag_b { -1 } else { @@ -303,53 +299,46 @@ type eq = (Obj.t, Obj.t) => bool basic type is not the same, it will not equal */ let rec equal = (a: Obj.t, b: Obj.t): bool => - /* front and formoest, we do not compare function values */ if a === b { true } else { let a_type = Js.typeof(a) - if ( - a_type == "string" || - (a_type == "number" || - (a_type == "bigint" || - (a_type == "boolean" || - (a_type == "undefined" || a === %raw(`null`))))) - ) { + if a_type !== "object" || a === %raw(`null`) { false } else { let b_type = Js.typeof(b) - if a_type == "function" || b_type == "function" { - raise(Invalid_argument("equal: functional value")) - } /* first, check using reference equality */ - else if ( - /* a_type = "object" || "symbol" */ - b_type == "number" || (b_type == "bigint" || (b_type == "undefined" || b === %raw(`null`))) - ) { + if b_type !== "object" || b === %raw(`null`) { false } else { /* [a] [b] could not be null, so it can not raise */ let tag_a = Obj.tag(a) let tag_b = Obj.tag(b) - if tag_a == 248 /* object/exception */ { - Obj.magic(Obj.field(a, 1)) === Obj.magic(Obj.field(b, 1)) - } else if tag_a == 251 /* abstract_tag */ { - raise(Invalid_argument("equal: abstract value")) - } else if tag_a != tag_b { + if tag_a !== tag_b { false - } else { + } else if O.isArray(a) { let len_a = Obj.size(a) let len_b = Obj.size(b) - if len_a == len_b { - if O.isArray(a) { - aux_equal_length((Obj.magic(a): array), (Obj.magic(b): array), 0, len_a) - } else if %raw(`a instanceof Date && b instanceof Date`) { - !(Js.unsafe_gt(a, b) || Js.unsafe_lt(a, b)) - } else { - aux_obj_equal(a, b) - } + if len_a !== len_b { + false + } else { + aux_equal_length((Obj.magic(a): array), (Obj.magic(b): array), 0, len_a) + } + } else if %raw(`a instanceof Error`) { + let a: {..} = Obj.magic(a) + let b: {..} = Obj.magic(b) + if %raw(`b instanceof Error`) && a["message"] === b["message"] { + equal(a["clause"], b["clause"]) } else { false } + } else if %raw(`a instanceof Date`) { + if %raw(`b instanceof Date`) { + !(Js.unsafe_gt(a, b) || Js.unsafe_lt(a, b)) + } else { + false + } + } else { + aux_obj_equal(a, b) } } } diff --git a/jscomp/test/406_primitive_test.js b/jscomp/test/406_primitive_test.js index 7292ab1928..a6b1ec0a26 100644 --- a/jscomp/test/406_primitive_test.js +++ b/jscomp/test/406_primitive_test.js @@ -49,9 +49,7 @@ function f() { if (exn.RE_EXN_ID === A) { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/UncurriedExternals.js b/jscomp/test/UncurriedExternals.js index c6928253d2..9de2bce5ea 100644 --- a/jscomp/test/UncurriedExternals.js +++ b/jscomp/test/UncurriedExternals.js @@ -29,9 +29,11 @@ function tg(arr) { let tc = Object.assign({}, "abc"); -let te = { - RE_EXN_ID: "Not_found" -}; +let te = new Error("Not_found", { + cause: { + RE_EXN_ID: "Not_found" + } +}); let tcr = {}; diff --git a/jscomp/test/array_safe_get.js b/jscomp/test/array_safe_get.js index ce8a0437bf..8a669d3822 100644 --- a/jscomp/test/array_safe_get.js +++ b/jscomp/test/array_safe_get.js @@ -19,9 +19,7 @@ try { console.log(msg._1); y = 0; } else { - throw new Error(msg.RE_EXN_ID, { - cause: msg - }); + throw msg; } } diff --git a/jscomp/test/array_test.js b/jscomp/test/array_test.js index 3045800bd1..8a589d4487 100644 --- a/jscomp/test/array_test.js +++ b/jscomp/test/array_test.js @@ -34,9 +34,7 @@ function starts_with(xs, prefix, p) { if (exn.RE_EXN_ID === H) { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/custom_error_test.js b/jscomp/test/custom_error_test.js index 0e19bcac08..882aa937a0 100644 --- a/jscomp/test/custom_error_test.js +++ b/jscomp/test/custom_error_test.js @@ -14,9 +14,7 @@ function test_js_error() { console.log(err._1.stack); return; } - throw new Error(err.RE_EXN_ID, { - cause: err - }); + throw err; } return e; } @@ -28,13 +26,9 @@ function test_js_error2() { let e = Caml_js_exceptions.internalToOCamlException(raw_e); if (e.RE_EXN_ID === Js_exn.$$Error) { console.log(e._1.stack); - throw new Error(e.RE_EXN_ID, { - cause: e - }); + throw e; } - throw new Error(e.RE_EXN_ID, { - cause: e - }); + throw e; } } @@ -48,9 +42,7 @@ function example1() { console.log(err._1.stack); return; } - throw new Error(err.RE_EXN_ID, { - cause: err - }); + throw err; } return v; } @@ -63,9 +55,7 @@ function example2() { if (exn.RE_EXN_ID === Js_exn.$$Error) { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/equal_exception_test.js b/jscomp/test/equal_exception_test.js index 263778a862..5a88093de6 100644 --- a/jscomp/test/equal_exception_test.js +++ b/jscomp/test/equal_exception_test.js @@ -77,35 +77,29 @@ function is_exception() { if (exn.RE_EXN_ID === "Not_found") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } function is_normal_exception(_x) { let A = /* @__PURE__ */Caml_exceptions.create("A"); - let v = { - RE_EXN_ID: A, - _1: 3 - }; + let v = new Error(A, { + cause: { + RE_EXN_ID: A, + _1: 3 + } + }); try { - throw new Error(v.RE_EXN_ID, { - cause: v - }); + throw v; } catch (raw_exn) { let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); if (exn.RE_EXN_ID === A) { if (exn._1 === 3) { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -152,9 +146,11 @@ let suites = { tl: suites_1 }; -let e = { - RE_EXN_ID: "Not_found" -}; +let e = new Error("Not_found", { + cause: { + RE_EXN_ID: "Not_found" + } +}); function eq(x) { return x.RE_EXN_ID === "Not_found"; @@ -162,9 +158,11 @@ function eq(x) { let Not_found = /* @__PURE__ */Caml_exceptions.create("Equal_exception_test.Not_found"); -if (Caml_obj.equal(e, { - RE_EXN_ID: Not_found - }) !== false) { +if (Caml_obj.equal(e, new Error(Not_found, { + cause: { + RE_EXN_ID: Not_found + } + })) !== false) { throw new Error("Assert_failure", { cause: { RE_EXN_ID: "Assert_failure", diff --git a/jscomp/test/exception_alias.js b/jscomp/test/exception_alias.js index da3b52db8c..f88be50702 100644 --- a/jscomp/test/exception_alias.js +++ b/jscomp/test/exception_alias.js @@ -3,9 +3,11 @@ let List = require("../../lib/js/list.js"); -let a0 = { - RE_EXN_ID: "Not_found" -}; +let a0 = new Error("Not_found", { + cause: { + RE_EXN_ID: "Not_found" + } +}); let b = List.length({ hd: 1, diff --git a/jscomp/test/exception_rebound_err_test.js b/jscomp/test/exception_rebound_err_test.js index 403e7a2b7f..80e88c3ed0 100644 --- a/jscomp/test/exception_rebound_err_test.js +++ b/jscomp/test/exception_rebound_err_test.js @@ -72,9 +72,7 @@ function f(g) { if (exn.RE_EXN_ID === "Not_found") { return 1; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/exception_value_test.js b/jscomp/test/exception_value_test.js index dee7400ffb..b0fc663621 100644 --- a/jscomp/test/exception_value_test.js +++ b/jscomp/test/exception_value_test.js @@ -43,10 +43,12 @@ let B = /* @__PURE__ */Caml_exceptions.create("Exception_value_test.B"); let C = /* @__PURE__ */Caml_exceptions.create("Exception_value_test.C"); -let u = { - RE_EXN_ID: A, - _1: 3 -}; +let u = new Error(A, { + cause: { + RE_EXN_ID: A, + _1: 3 + } +}); function test_not_found(f, param) { try { @@ -56,9 +58,7 @@ function test_not_found(f, param) { if (exn.RE_EXN_ID === "Not_found") { return 2; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -69,13 +69,9 @@ function test_js_error2() { let e = Caml_js_exceptions.internalToOCamlException(raw_e); if (e.RE_EXN_ID === Js_exn.$$Error) { console.log(e._1.stack); - throw new Error(e.RE_EXN_ID, { - cause: e - }); + throw e; } - throw new Error(e.RE_EXN_ID, { - cause: e - }); + throw e; } } diff --git a/jscomp/test/ext_bytes_test.js b/jscomp/test/ext_bytes_test.js index d011a861d0..c90ce713d2 100644 --- a/jscomp/test/ext_bytes_test.js +++ b/jscomp/test/ext_bytes_test.js @@ -148,9 +148,7 @@ function starts_with(xs, prefix, p) { if (exn.RE_EXN_ID === H) { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/ext_filename_test.js b/jscomp/test/ext_filename_test.js index e443d10358..9c342e6db1 100644 --- a/jscomp/test/ext_filename_test.js +++ b/jscomp/test/ext_filename_test.js @@ -70,9 +70,7 @@ function chop_extension(locOpt, name) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -84,9 +82,7 @@ function chop_extension_if_any(fname) { if (exn.RE_EXN_ID === "Invalid_argument") { return fname; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/ext_pervasives_test.js b/jscomp/test/ext_pervasives_test.js index 5527fdf735..6ab34d91f4 100644 --- a/jscomp/test/ext_pervasives_test.js +++ b/jscomp/test/ext_pervasives_test.js @@ -11,9 +11,7 @@ function $$finally(v, action, f) { e = f(v); } catch (e$1) { action(v); - throw new Error(e$1.RE_EXN_ID, { - cause: e$1 - }); + throw e$1; } action(v); return e; @@ -49,9 +47,7 @@ function is_pos_pow(n) { if (exn.RE_EXN_ID === E) { return -1; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -85,9 +81,7 @@ function is_pos_pow_2(n) { if (exn.RE_EXN_ID === E) { return -1; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/ext_string_test.js b/jscomp/test/ext_string_test.js index c73d6f37a0..f369e0e4d4 100644 --- a/jscomp/test/ext_string_test.js +++ b/jscomp/test/ext_string_test.js @@ -287,9 +287,7 @@ function find(startOpt, sub, s) { if (exn.RE_EXN_ID === Local_exit) { return i; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -342,9 +340,7 @@ function rfind(sub, s) { if (exn.RE_EXN_ID === Local_exit) { return i; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/extensible_variant_test.js b/jscomp/test/extensible_variant_test.js index dbebc62d58..f4a95a9dae 100644 --- a/jscomp/test/extensible_variant_test.js +++ b/jscomp/test/extensible_variant_test.js @@ -42,11 +42,13 @@ let suites_0 = [ return { TAG: "Eq", _0: 3, - _1: to_int({ - RE_EXN_ID: Int, - _1: 3, - _2: 0 - }) + _1: to_int(new Error(Int, { + cause: { + RE_EXN_ID: Int, + _1: 3, + _2: 0 + } + })) }; }) ]; @@ -58,11 +60,13 @@ let suites_1 = { return { TAG: "Eq", _0: 0, - _1: to_int({ - RE_EXN_ID: Int$1, - _1: 3, - _2: 0 - }) + _1: to_int(new Error(Int$1, { + cause: { + RE_EXN_ID: Int$1, + _1: 3, + _2: 0 + } + })) }; }) ], @@ -73,10 +77,12 @@ let suites_1 = { return { TAG: "Eq", _0: -1, - _1: to_int({ - RE_EXN_ID: Str, - _1: "x" - }) + _1: to_int(new Error(Str, { + cause: { + RE_EXN_ID: Str, + _1: "x" + } + })) }; }) ], diff --git a/jscomp/test/genlex_test.js b/jscomp/test/genlex_test.js index 0638104f8c..6d95b21ebf 100644 --- a/jscomp/test/genlex_test.js +++ b/jscomp/test/genlex_test.js @@ -45,9 +45,7 @@ function to_list(s) { if (exn.RE_EXN_ID === Stream.Failure) { return List.rev(acc); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } _acc = { hd: v, diff --git a/jscomp/test/global_exception_regression_test.js b/jscomp/test/global_exception_regression_test.js index 443bf1ee90..dbc91d4352 100644 --- a/jscomp/test/global_exception_regression_test.js +++ b/jscomp/test/global_exception_regression_test.js @@ -3,17 +3,23 @@ let Mt = require("./mt.js"); -let v = { - RE_EXN_ID: "Not_found" -}; - -let u = { - RE_EXN_ID: "Not_found" -}; - -let s = { - RE_EXN_ID: "End_of_file" -}; +let v = new Error("Not_found", { + cause: { + RE_EXN_ID: "Not_found" + } +}); + +let u = new Error("Not_found", { + cause: { + RE_EXN_ID: "Not_found" + } +}); + +let s = new Error("End_of_file", { + cause: { + RE_EXN_ID: "End_of_file" + } +}); let suites_0 = [ "not_found_equal", diff --git a/jscomp/test/gpr_1245_test.js b/jscomp/test/gpr_1245_test.js index e1e0e9044b..3ed9c70903 100644 --- a/jscomp/test/gpr_1245_test.js +++ b/jscomp/test/gpr_1245_test.js @@ -46,9 +46,7 @@ function a1(f) { if (exn.RE_EXN_ID === E) { return 1; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/gpr_1701_test.js b/jscomp/test/gpr_1701_test.js index 81226bbfca..1437865487 100644 --- a/jscomp/test/gpr_1701_test.js +++ b/jscomp/test/gpr_1701_test.js @@ -22,9 +22,7 @@ function test(n) { if (exn.RE_EXN_ID === Foo) { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -42,9 +40,7 @@ function read_lines(inc) { if (exn.RE_EXN_ID === "End_of_file") { l = undefined; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } if (l === undefined) { @@ -70,9 +66,7 @@ function read_lines2(inc) { if (exn.RE_EXN_ID === "End_of_file") { return List.rev(acc); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } _acc = { hd: l, @@ -95,9 +89,7 @@ function read_lines3(inc) { if (exn.RE_EXN_ID === "End_of_file") { return List.rev(acc); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } }; return loop(/* [] */0); diff --git a/jscomp/test/gpr_2316_test.js b/jscomp/test/gpr_2316_test.js index 9740acfc1a..baa078aab7 100644 --- a/jscomp/test/gpr_2316_test.js +++ b/jscomp/test/gpr_2316_test.js @@ -43,9 +43,7 @@ try { if (msg.RE_EXN_ID === "Failure") { y = msg._1; } else { - throw new Error(msg.RE_EXN_ID, { - cause: msg - }); + throw msg; } } @@ -65,9 +63,7 @@ try { if (msg$1.RE_EXN_ID === "Failure") { x = msg$1._1; } else { - throw new Error(msg$1.RE_EXN_ID, { - cause: msg$1 - }); + throw msg$1; } } diff --git a/jscomp/test/gpr_405_test.js b/jscomp/test/gpr_405_test.js index fc7a5c6494..004e3a8077 100644 --- a/jscomp/test/gpr_405_test.js +++ b/jscomp/test/gpr_405_test.js @@ -19,9 +19,7 @@ function Make(funarg) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } }; let min_cutset = function (gr, first_node) { diff --git a/jscomp/test/inline_record_test.js b/jscomp/test/inline_record_test.js index 28e795d78f..fc6580ce1a 100644 --- a/jscomp/test/inline_record_test.js +++ b/jscomp/test/inline_record_test.js @@ -56,11 +56,13 @@ console.log(f(v1)); let A0 = /* @__PURE__ */Caml_exceptions.create("Inline_record_test.A0"); -let v3 = { - RE_EXN_ID: A0, - lbl: 3, - more: /* [] */0 -}; +let v3 = new Error(A0, { + cause: { + RE_EXN_ID: A0, + lbl: 3, + more: /* [] */0 + } +}); let tmp; @@ -146,12 +148,14 @@ eq("File \"inline_record_test.res\", line 80, characters 2-9", tmp$2, 22); let A4 = /* @__PURE__ */Caml_exceptions.create("Inline_record_test.A4"); -let v6 = { - RE_EXN_ID: A4, - x: 0, - y: 0, - z: 0 -}; +let v6 = new Error(A4, { + cause: { + RE_EXN_ID: A4, + x: 0, + y: 0, + z: 0 + } +}); function ff0(x) { if (x.RE_EXN_ID === A4) { diff --git a/jscomp/test/js_exception_catch_test.js b/jscomp/test/js_exception_catch_test.js index 4f0fa303d2..fa1647ab3e 100644 --- a/jscomp/test/js_exception_catch_test.js +++ b/jscomp/test/js_exception_catch_test.js @@ -71,9 +71,7 @@ try { }; })); } else { - throw new Error(x.RE_EXN_ID, { - cause: x - }); + throw x; } } @@ -205,9 +203,7 @@ eq("File \"js_exception_catch_test.res\", line 52, characters 5-12", test(functi }), "C_any"); eq("File \"js_exception_catch_test.res\", line 53, characters 5-12", test(function () { - throw new Error(new Error("x").RE_EXN_ID, { - cause: new Error("x") - }); + throw new Error("x"); }), "Js_error"); eq("File \"js_exception_catch_test.res\", line 54, characters 5-12", test(function () { diff --git a/jscomp/test/large_record_duplication_test.js b/jscomp/test/large_record_duplication_test.js index bee19e3350..df14304f93 100644 --- a/jscomp/test/large_record_duplication_test.js +++ b/jscomp/test/large_record_duplication_test.js @@ -27,35 +27,45 @@ let Small = /* @__PURE__ */Caml_exceptions.create("Large_record_duplication_test function f_small(x) { if (x.RE_EXN_ID === Small) { - return { - RE_EXN_ID: Small, - x: 2, - y: x.y - }; + return new Error(Small, { + cause: { + RE_EXN_ID: Small, + x: 2, + y: x.y + } + }); } else { - return { - RE_EXN_ID: "Not_found" - }; + return new Error("Not_found", { + cause: { + RE_EXN_ID: "Not_found" + } + }); } } -let h = { - RE_EXN_ID: Small, - x: 1, - y: "" -}; - -eq("File \"large_record_duplication_test.res\", line 70, characters 3-10", f_small(h), { - RE_EXN_ID: Small, - x: 2, - y: "" +let h = new Error(Small, { + cause: { + RE_EXN_ID: Small, + x: 1, + y: "" + } }); -eq("File \"large_record_duplication_test.res\", line 72, characters 3-10", Caml_obj.equal(h, { - RE_EXN_ID: Small, - x: 2, - y: "" -}), false); +eq("File \"large_record_duplication_test.res\", line 70, characters 3-10", f_small(h), new Error(Small, { + cause: { + RE_EXN_ID: Small, + x: 2, + y: "" + } +})); + +eq("File \"large_record_duplication_test.res\", line 72, characters 3-10", Caml_obj.equal(h, new Error(Small, { + cause: { + RE_EXN_ID: Small, + x: 2, + y: "" + } +})), false); let v1 = { TAG: "A0", @@ -166,40 +176,44 @@ function get_x0$2(x) { } -let v3 = { - RE_EXN_ID: A0, - x0: 9, - x1: 9, - x2: 9, - x3: 9, - x4: 9, - x5: 9, - x6: 9, - x7: 9, - x8: 9, - x9: 9, - x10: 9, - x11: 9, - x12: 9, - x13: 9, - x14: 9, - x15: 9, - x16: 9, - x17: 9, - x18: 9, - x19: 9, - x20: 9, - x21: 9, - x22: 9 -}; +let v3 = new Error(A0, { + cause: { + RE_EXN_ID: A0, + x0: 9, + x1: 9, + x2: 9, + x3: 9, + x4: 9, + x5: 9, + x6: 9, + x7: 9, + x8: 9, + x9: 9, + x10: 9, + x11: 9, + x12: 9, + x13: 9, + x14: 9, + x15: 9, + x16: 9, + x17: 9, + x18: 9, + x19: 9, + x20: 9, + x21: 9, + x22: 9 + } +}); eq("File \"large_record_duplication_test.res\", line 275, characters 3-10", get_x0$2(f3(v3)), 1); eq("File \"large_record_duplication_test.res\", line 276, characters 3-10", get_x0$2(v3), 9); -eq("File \"large_record_duplication_test.res\", line 277, characters 3-10", get_x0$2({ - RE_EXN_ID: "Not_found" -}), undefined); +eq("File \"large_record_duplication_test.res\", line 277, characters 3-10", get_x0$2(new Error("Not_found", { + cause: { + RE_EXN_ID: "Not_found" + } +})), undefined); Mt.from_pair_suites("Large_record_duplication_test", suites.contents); diff --git a/jscomp/test/libqueue_test.js b/jscomp/test/libqueue_test.js index d3db327772..82cddb81bf 100644 --- a/jscomp/test/libqueue_test.js +++ b/jscomp/test/libqueue_test.js @@ -43,9 +43,7 @@ function does_raise(f, q) { if (exn.RE_EXN_ID === Queue.Empty) { return true; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/local_exception_test.js b/jscomp/test/local_exception_test.js index 702e86d985..88bc1f509f 100644 --- a/jscomp/test/local_exception_test.js +++ b/jscomp/test/local_exception_test.js @@ -5,24 +5,30 @@ let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); let A = /* @__PURE__ */Caml_exceptions.create("Local_exception_test.A"); -let v = { - RE_EXN_ID: A, - _1: 3, - _2: true -}; +let v = new Error(A, { + cause: { + RE_EXN_ID: A, + _1: 3, + _2: true + } +}); let B = /* @__PURE__ */Caml_exceptions.create("Local_exception_test.B"); -let u = { - RE_EXN_ID: B -}; +let u = new Error(B, { + cause: { + RE_EXN_ID: B + } +}); let D = /* @__PURE__ */Caml_exceptions.create("Local_exception_test.D"); -let d = { - RE_EXN_ID: D, - _1: 3 -}; +let d = new Error(D, { + cause: { + RE_EXN_ID: D, + _1: 3 + } +}); exports.A = A; exports.v = v; diff --git a/jscomp/test/ocaml_re_test.js b/jscomp/test/ocaml_re_test.js index 7bf28c6f0b..ed8f53d0a0 100644 --- a/jscomp/test/ocaml_re_test.js +++ b/jscomp/test/ocaml_re_test.js @@ -1522,9 +1522,7 @@ function find_state(re, desc) { Re_automata_State.Table.add(re.states, desc, st); return st; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -1604,9 +1602,7 @@ function final(info, st, cat) { }; return res; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -1626,9 +1622,7 @@ function find_initial_state(re, cat) { }; return st; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -1753,9 +1747,7 @@ function trans_set(cache, cm, s) { cache.contents = add(v, l, cache.contents); return l; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -3374,9 +3366,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { if (exn$1.RE_EXN_ID === Pervasives.Exit) { return false; } - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } }; let get = function () { @@ -3832,9 +3822,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } if (!accept_s(":]")) { throw new Error(Parse_error, { diff --git a/jscomp/test/record_debug_test.js b/jscomp/test/record_debug_test.js index c1591413b6..73fa862693 100644 --- a/jscomp/test/record_debug_test.js +++ b/jscomp/test/record_debug_test.js @@ -40,16 +40,20 @@ let A = /* @__PURE__ */Caml_exceptions.create("Record_debug_test.A"); let B = /* @__PURE__ */Caml_exceptions.create("Record_debug_test.B"); -let v0 = { - RE_EXN_ID: A, - _1: 3 -}; +let v0 = new Error(A, { + cause: { + RE_EXN_ID: A, + _1: 3 + } +}); -let v1 = { - RE_EXN_ID: B, - _1: 3, - _2: 2 -}; +let v1 = new Error(B, { + cause: { + RE_EXN_ID: B, + _1: 3, + _2: 2 + } +}); let N = { a: 0, diff --git a/jscomp/test/record_extension_test.js b/jscomp/test/record_extension_test.js index 79d2317167..54fbfb2380 100644 --- a/jscomp/test/record_extension_test.js +++ b/jscomp/test/record_extension_test.js @@ -27,11 +27,13 @@ function f(x) { } -let v0 = { - RE_EXN_ID: Inline_record, - x: 3, - y: "4" -}; +let v0 = new Error(Inline_record, { + cause: { + RE_EXN_ID: Inline_record, + x: 3, + y: "4" + } +}); eq("File \"record_extension_test.res\", line 18, characters 3-10", f(v0), 7); diff --git a/jscomp/test/recursive_module.js b/jscomp/test/recursive_module.js index e3c0df5885..c1e50cdc42 100644 --- a/jscomp/test/recursive_module.js +++ b/jscomp/test/recursive_module.js @@ -106,9 +106,7 @@ try { if (exn.RE_EXN_ID === Lazy.Undefined) { tmp = -1; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -183,9 +181,7 @@ try { if (exn$1.RE_EXN_ID === "Undefined_recursive_module") { tmp$1 = 4; } else { - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } diff --git a/jscomp/test/sexpm.js b/jscomp/test/sexpm.js index bf9221f37e..b0c1a1850c 100644 --- a/jscomp/test/sexpm.js +++ b/jscomp/test/sexpm.js @@ -84,9 +84,7 @@ function _must_escape(s) { if (exn.RE_EXN_ID === Pervasives.Exit) { return true; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/stack_comp_test.js b/jscomp/test/stack_comp_test.js index 915fafeb4c..b667c6bbda 100644 --- a/jscomp/test/stack_comp_test.js +++ b/jscomp/test/stack_comp_test.js @@ -64,9 +64,7 @@ function does_raise(f, s) { if (exn.RE_EXN_ID === Stack.Empty) { return true; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/string_test.js b/jscomp/test/string_test.js index 7d8042cada..f1c4a0f9e0 100644 --- a/jscomp/test/string_test.js +++ b/jscomp/test/string_test.js @@ -72,9 +72,7 @@ function rev_split_by_char(c, s) { tl: l }; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } }; return loop(0, /* [] */0); @@ -102,9 +100,7 @@ function xsplit(delim, s) { tl: l }; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } let l_0 = $$String.sub(s, i$p + 1 | 0, (x - i$p | 0) - 1 | 0); let l$1 = { diff --git a/jscomp/test/test_exception.js b/jscomp/test/test_exception.js index d8fd225654..06d1a7a447 100644 --- a/jscomp/test/test_exception.js +++ b/jscomp/test/test_exception.js @@ -51,9 +51,11 @@ function xx() { let Nullary = /* @__PURE__ */Caml_exceptions.create("Test_exception.Nullary"); -let a = { - RE_EXN_ID: Nullary -}; +let a = new Error(Nullary, { + cause: { + RE_EXN_ID: Nullary + } +}); exports.Local = Local; exports.f = f; diff --git a/jscomp/test/test_literal.js b/jscomp/test/test_literal.js index d83f67d7df..9eda170308 100644 --- a/jscomp/test/test_literal.js +++ b/jscomp/test/test_literal.js @@ -5,11 +5,13 @@ let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); let Custom_inline = /* @__PURE__ */Caml_exceptions.create("Test_literal.Custom_inline"); -let v = { - RE_EXN_ID: Custom_inline, - _1: 1, - _2: 2 -}; +let v = new Error(Custom_inline, { + cause: { + RE_EXN_ID: Custom_inline, + _1: 1, + _2: 2 + } +}); let vv = [ 1, diff --git a/jscomp/test/test_match_exception.js b/jscomp/test/test_match_exception.js index 6fe415efa7..ee79886634 100644 --- a/jscomp/test/test_match_exception.js +++ b/jscomp/test/test_match_exception.js @@ -11,9 +11,7 @@ function f(g, x) { if (exn.RE_EXN_ID === "Not_found") { return 3; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/jscomp/test/test_seq.js b/jscomp/test/test_seq.js index 10c3093667..5325aa29c5 100644 --- a/jscomp/test/test_seq.js +++ b/jscomp/test/test_seq.js @@ -72,9 +72,7 @@ function add_help(speclist) { tl: /* [] */0 }; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } let add2; @@ -96,9 +94,7 @@ function add_help(speclist) { tl: /* [] */0 }; } else { - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } return Pervasives.$at(speclist, Pervasives.$at(add1, add2)); diff --git a/jscomp/test/test_static_catch_ident.js b/jscomp/test/test_static_catch_ident.js index 0f07ea108a..71f35bcd64 100644 --- a/jscomp/test/test_static_catch_ident.js +++ b/jscomp/test/test_static_catch_ident.js @@ -10,9 +10,7 @@ function scanf_bad_input(ib, x) { if (x.RE_EXN_ID === Scan_failure || x.RE_EXN_ID === "Failure") { s = x._1; } else { - throw new Error(x.RE_EXN_ID, { - cause: x - }); + throw x; } for (let i = 0; i <= 100; ++i) { console.log(s); diff --git a/jscomp/test/test_string_const.js b/jscomp/test/test_string_const.js index cadb0599f9..67c811f372 100644 --- a/jscomp/test/test_string_const.js +++ b/jscomp/test/test_string_const.js @@ -16,9 +16,7 @@ try { console.log(e._1); hh = /* 'a' */97; } else { - throw new Error(e.RE_EXN_ID, { - cause: e - }); + throw e; } } diff --git a/jscomp/test/test_trywith.js b/jscomp/test/test_trywith.js index f327c553a7..b1a6a29c7c 100644 --- a/jscomp/test/test_trywith.js +++ b/jscomp/test/test_trywith.js @@ -18,9 +18,7 @@ function ff(g, x) { } catch (raw_exn) { let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); if (exn.RE_EXN_ID !== "Not_found") { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -29,9 +27,7 @@ function ff(g, x) { } catch (raw_exn$1) { let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); if (exn$1.RE_EXN_ID !== Out_of_memory) { - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } @@ -40,9 +36,7 @@ function ff(g, x) { } catch (raw_exn$2) { let exn$2 = Caml_js_exceptions.internalToOCamlException(raw_exn$2); if (exn$2.RE_EXN_ID !== Sys_error) { - throw new Error(exn$2.RE_EXN_ID, { - cause: exn$2 - }); + throw exn$2; } } @@ -51,9 +45,7 @@ function ff(g, x) { } catch (raw_exn$3) { let exn$3 = Caml_js_exceptions.internalToOCamlException(raw_exn$3); if (exn$3.RE_EXN_ID !== "Invalid_argument") { - throw new Error(exn$3.RE_EXN_ID, { - cause: exn$3 - }); + throw exn$3; } } @@ -62,9 +54,7 @@ function ff(g, x) { } catch (raw_exn$4) { let exn$4 = Caml_js_exceptions.internalToOCamlException(raw_exn$4); if (exn$4.RE_EXN_ID !== "End_of_file") { - throw new Error(exn$4.RE_EXN_ID, { - cause: exn$4 - }); + throw exn$4; } } @@ -73,9 +63,7 @@ function ff(g, x) { } catch (raw_exn$5) { let exn$5 = Caml_js_exceptions.internalToOCamlException(raw_exn$5); if (exn$5.RE_EXN_ID !== "Match_failure") { - throw new Error(exn$5.RE_EXN_ID, { - cause: exn$5 - }); + throw exn$5; } } @@ -84,9 +72,7 @@ function ff(g, x) { } catch (raw_exn$6) { let exn$6 = Caml_js_exceptions.internalToOCamlException(raw_exn$6); if (exn$6.RE_EXN_ID !== Stack_overflow) { - throw new Error(exn$6.RE_EXN_ID, { - cause: exn$6 - }); + throw exn$6; } } @@ -95,9 +81,7 @@ function ff(g, x) { } catch (raw_exn$7) { let exn$7 = Caml_js_exceptions.internalToOCamlException(raw_exn$7); if (exn$7.RE_EXN_ID !== Sys_blocked_io) { - throw new Error(exn$7.RE_EXN_ID, { - cause: exn$7 - }); + throw exn$7; } } @@ -106,9 +90,7 @@ function ff(g, x) { } catch (raw_exn$8) { let exn$8 = Caml_js_exceptions.internalToOCamlException(raw_exn$8); if (exn$8.RE_EXN_ID !== "Assert_failure") { - throw new Error(exn$8.RE_EXN_ID, { - cause: exn$8 - }); + throw exn$8; } } @@ -119,9 +101,7 @@ function ff(g, x) { if (exn$9.RE_EXN_ID === "Undefined_recursive_module") { return; } - throw new Error(exn$9.RE_EXN_ID, { - cause: exn$9 - }); + throw exn$9; } } diff --git a/jscomp/test/ticker.js b/jscomp/test/ticker.js index adb9217fd2..1c3fd264e4 100644 --- a/jscomp/test/ticker.js +++ b/jscomp/test/ticker.js @@ -32,9 +32,7 @@ function split(delim, s) { tl: l }; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } let l_0 = $$String.sub(s, i$p + 1 | 0, (x - i$p | 0) - 1 | 0); let l$1 = { diff --git a/jscomp/test/uncurried_cast.js b/jscomp/test/uncurried_cast.js index 1546d3777a..2ace297d14 100644 --- a/jscomp/test/uncurried_cast.js +++ b/jscomp/test/uncurried_cast.js @@ -5,9 +5,7 @@ let Belt_List = require("../../lib/js/belt_List.js"); let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); function raise(e) { - throw new Error(e.RE_EXN_ID, { - cause: e - }); + throw e; } let map = Belt_List.mapU; diff --git a/jscomp/test/variant.js b/jscomp/test/variant.js index d288abaca6..4dfd88b403 100644 --- a/jscomp/test/variant.js +++ b/jscomp/test/variant.js @@ -93,9 +93,7 @@ function rollback_path(subst, p) { return "Pident | Papply"; } } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } } @@ -131,9 +129,7 @@ function fooExn(f) { let match = n._1; return match[0] + match[1] | 0; } - throw new Error(n.RE_EXN_ID, { - cause: n - }); + throw n; } } diff --git a/lib/es6/arg.js b/lib/es6/arg.js index bd24d4e8e7..9963537d76 100644 --- a/lib/es6/arg.js +++ b/lib/es6/arg.js @@ -90,9 +90,7 @@ function add_help(speclist) { tl: /* [] */0 }; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } let add2; @@ -114,9 +112,7 @@ function add_help(speclist) { tl: /* [] */0 }; } else { - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } return Pervasives.$at(speclist, Pervasives.$at(add1, add2)); @@ -161,9 +157,7 @@ function bool_of_string_opt(x) { if (exn.RE_EXN_ID === "Invalid_argument") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -175,9 +169,7 @@ function int_of_string_opt(x) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -189,9 +181,7 @@ function float_of_string_opt(x) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -229,15 +219,19 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist TAG: "Unknown", _0: "--help" })) { - return { - RE_EXN_ID: Help, - _1: Buffer.contents(b) - }; + return new Error(Help, { + cause: { + RE_EXN_ID: Help, + _1: Buffer.contents(b) + } + }); } else { - return { - RE_EXN_ID: Bad, - _1: Buffer.contents(b) - }; + return new Error(Bad, { + cause: { + RE_EXN_ID: Bad, + _1: Buffer.contents(b) + } + }); } }; current.contents = current.contents + 1 | 0; @@ -273,14 +267,10 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist } }); } - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } let follow = match[1]; @@ -500,24 +490,15 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist } catch (raw_m) { let m = Caml_js_exceptions.internalToOCamlException(raw_m); if (m.RE_EXN_ID === Bad) { - throw new Error(convert_error({ + throw convert_error({ TAG: "Message", _0: m._1 - }).RE_EXN_ID, { - cause: convert_error({ - TAG: "Message", - _0: m._1 - }) }); } if (m.RE_EXN_ID === Stop) { - throw new Error(convert_error(m._1).RE_EXN_ID, { - cause: convert_error(m._1) - }); + throw convert_error(m._1); } - throw new Error(m.RE_EXN_ID, { - cause: m - }); + throw m; } current.contents = current.contents + 1 | 0; }; @@ -554,9 +535,7 @@ function parse(l, f, msg) { console.log(msg$1._1); return Pervasives.exit(0); } - throw new Error(msg$1.RE_EXN_ID, { - cause: msg$1 - }); + throw msg$1; } } @@ -573,9 +552,7 @@ function parse_dynamic(l, f, msg) { console.log(msg$1._1); return Pervasives.exit(0); } - throw new Error(msg$1.RE_EXN_ID, { - cause: msg$1 - }); + throw msg$1; } } @@ -601,9 +578,7 @@ function parse_expand(l, f, msg) { console.log(msg$1._1); return Pervasives.exit(0); } - throw new Error(msg$1.RE_EXN_ID, { - cause: msg$1 - }); + throw msg$1; } } @@ -638,18 +613,14 @@ function second_word(s) { if (exn$1.RE_EXN_ID === "Not_found") { return len; } - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } if (exit === 2) { return loop(n$1 + 1 | 0); } } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } return loop(n + 1 | 0); diff --git a/lib/es6/array.js b/lib/es6/array.js index badec4a0e5..4dd50594ee 100644 --- a/lib/es6/array.js +++ b/lib/es6/array.js @@ -342,9 +342,7 @@ function sort(cmp, a) { if (i$2.RE_EXN_ID === Bottom) { return Caml_array.set(a, i$2._1, e); } - throw new Error(i$2.RE_EXN_ID, { - cause: i$2 - }); + throw i$2; } }; let bubble = function (l, i) { @@ -362,9 +360,7 @@ function sort(cmp, a) { if (i$2.RE_EXN_ID === Bottom) { return i$2._1; } - throw new Error(i$2.RE_EXN_ID, { - cause: i$2 - }); + throw i$2; } }; let trickleup = function (_i, e) { diff --git a/lib/es6/arrayLabels.js b/lib/es6/arrayLabels.js index db8c5e22db..52f645c54f 100644 --- a/lib/es6/arrayLabels.js +++ b/lib/es6/arrayLabels.js @@ -342,9 +342,7 @@ function sort(cmp, a) { if (i$2.RE_EXN_ID === Bottom) { return Caml_array.set(a, i$2._1, e); } - throw new Error(i$2.RE_EXN_ID, { - cause: i$2 - }); + throw i$2; } }; let bubble = function (l, i) { @@ -362,9 +360,7 @@ function sort(cmp, a) { if (i$2.RE_EXN_ID === Bottom) { return i$2._1; } - throw new Error(i$2.RE_EXN_ID, { - cause: i$2 - }); + throw i$2; } }; let trickleup = function (_i, e) { diff --git a/lib/es6/bytes.js b/lib/es6/bytes.js index ef34d50b27..dde76307b6 100644 --- a/lib/es6/bytes.js +++ b/lib/es6/bytes.js @@ -633,9 +633,7 @@ function contains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -660,9 +658,7 @@ function rcontains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/es6/bytesLabels.js b/lib/es6/bytesLabels.js index ef34d50b27..dde76307b6 100644 --- a/lib/es6/bytesLabels.js +++ b/lib/es6/bytesLabels.js @@ -633,9 +633,7 @@ function contains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -660,9 +658,7 @@ function rcontains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/es6/caml_format.js b/lib/es6/caml_format.js index debf240abf..b4ce22552f 100644 --- a/lib/es6/caml_format.js +++ b/lib/es6/caml_format.js @@ -777,10 +777,12 @@ let float_of_string = (function(s,exn){ }); function float_of_string$1(s) { - return float_of_string(s, { - RE_EXN_ID: "Failure", - _1: "float_of_string" - }); + return float_of_string(s, new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: "float_of_string" + } + })); } export { diff --git a/lib/es6/caml_hash.js b/lib/es6/caml_hash.js index 054d821630..9d9412f65c 100644 --- a/lib/es6/caml_hash.js +++ b/lib/es6/caml_hash.js @@ -66,15 +66,11 @@ function hash(count, _limit, seed, obj) { if (size !== 0) { let obj_tag = obj$1.TAG; let tag = (size << 10) | obj_tag; - if (obj_tag === 248) { - s = Caml_hash_primitive.hash_mix_int(s, obj$1[1]); - } else { - s = Caml_hash_primitive.hash_mix_int(s, tag); - let v = size - 1 | 0; - let block = v < num ? v : num; - for (let i = 0; i <= block; ++i) { - push_back(queue, obj$1[i]); - } + s = Caml_hash_primitive.hash_mix_int(s, tag); + let v = size - 1 | 0; + let block = v < num ? v : num; + for (let i = 0; i <= block; ++i) { + push_back(queue, obj$1[i]); } } else { let size$1 = (function(obj,cb){ diff --git a/lib/es6/caml_js_exceptions.js b/lib/es6/caml_js_exceptions.js index 878ee0080e..6693ea8176 100644 --- a/lib/es6/caml_js_exceptions.js +++ b/lib/es6/caml_js_exceptions.js @@ -9,10 +9,12 @@ function internalToOCamlException(e) { if (Caml_exceptions.is_extension(e.cause)) { return e.cause; } else { - return { - RE_EXN_ID: "JsError", - _1: e - }; + return new Error("JsError", { + cause: { + RE_EXN_ID: "JsError", + _1: e + } + }); } } diff --git a/lib/es6/caml_lexer.js b/lib/es6/caml_lexer.js index b50a5a45f6..e3495a6479 100644 --- a/lib/es6/caml_lexer.js +++ b/lib/es6/caml_lexer.js @@ -104,10 +104,12 @@ let caml_lex_engine_aux = (function (tbl, start_state, lexbuf, exn){ let empty_token_lit = "lexing: empty token"; function lex_engine(tbls, i, buf) { - return caml_lex_engine_aux(tbls, i, buf, { - RE_EXN_ID: "Failure", - _1: empty_token_lit - }); + return caml_lex_engine_aux(tbls, i, buf, new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: empty_token_lit + } + })); } /***********************************************/ @@ -245,10 +247,12 @@ let caml_new_lex_engine_aux = (function (tbl, start_state, lexbuf, exn) { }); function new_lex_engine(tbl, i, buf) { - return caml_new_lex_engine_aux(tbl, i, buf, { - RE_EXN_ID: "Failure", - _1: empty_token_lit - }); + return caml_new_lex_engine_aux(tbl, i, buf, new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: empty_token_lit + } + })); } export { diff --git a/lib/es6/caml_obj.js b/lib/es6/caml_obj.js index 8fc4b04320..2e8803446f 100644 --- a/lib/es6/caml_obj.js +++ b/lib/es6/caml_obj.js @@ -132,17 +132,6 @@ function compare(a, b) { } let tag_a = a.TAG; let tag_b = b.TAG; - if (tag_a === 248) { - return Caml.int_compare(a[1], b[1]); - } - if (tag_a === 251) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "equal: abstract value" - } - }); - } if (tag_a !== tag_b) { if (tag_a < tag_b) { return -1; @@ -256,87 +245,85 @@ function aux_obj_compare(a, b) { } } -function equal(a, b) { - if (a === b) { - return true; - } - let a_type = typeof a; - if (a_type === "string" || a_type === "number" || a_type === "bigint" || a_type === "boolean" || a_type === "undefined" || a === null) { - return false; - } - let b_type = typeof b; - if (a_type === "function" || b_type === "function") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "equal: functional value" - } - }); - } - if (b_type === "number" || b_type === "bigint" || b_type === "undefined" || b === null) { - return false; - } - let tag_a = a.TAG; - let tag_b = b.TAG; - if (tag_a === 248) { - return a[1] === b[1]; - } - if (tag_a === 251) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "equal: abstract value" - } - }); - } - if (tag_a !== tag_b) { - return false; - } - let len_a = a.length | 0; - let len_b = b.length | 0; - if (len_a === len_b) { +function equal(_a, _b) { + while (true) { + let b = _b; + let a = _a; + if (a === b) { + return true; + } + let a_type = typeof a; + if (a_type !== "object" || a === null) { + return false; + } + let b_type = typeof b; + if (b_type !== "object" || b === null) { + return false; + } + let tag_a = a.TAG; + let tag_b = b.TAG; + if (tag_a !== tag_b) { + return false; + } if (Array.isArray(a)) { - let _i = 0; - while (true) { - let i = _i; - if (i === len_a) { - return true; - } - if (!equal(a[i], b[i])) { + let len_a = a.length | 0; + let len_b = b.length | 0; + if (len_a !== len_b) { + return false; + } else { + let _i = 0; + while (true) { + let i = _i; + if (i === len_a) { + return true; + } + if (!equal(a[i], b[i])) { + return false; + } + _i = i + 1 | 0; + continue; + }; + } + } + if (!(a instanceof Error)) { + if ((a instanceof Date)) { + if ((b instanceof Date)) { + return !(a > b || a < b); + } else { return false; } - _i = i + 1 | 0; - continue; - }; - } else if ((a instanceof Date && b instanceof Date)) { - return !(a > b || a < b); - } else { - let result = { - contents: true - }; - let do_key_a = function (key) { - if (!Object.prototype.hasOwnProperty.call(b, key)) { - result.contents = false; - return; - } - - }; - let do_key_b = function (key) { - if (!Object.prototype.hasOwnProperty.call(a, key) || !equal(b[key], a[key])) { - result.contents = false; - return; + } else { + let result = { + contents: true + }; + let do_key_a = function (key) { + if (!Object.prototype.hasOwnProperty.call(b, key)) { + result.contents = false; + return; + } + + }; + let do_key_b = function (key) { + if (!Object.prototype.hasOwnProperty.call(a, key) || !equal(b[key], a[key])) { + result.contents = false; + return; + } + + }; + for_in(a, do_key_a); + if (result.contents) { + for_in(b, do_key_b); } - - }; - for_in(a, do_key_a); - if (result.contents) { - for_in(b, do_key_b); + return result.contents; } - return result.contents; } - } else { - return false; - } + if (!((b instanceof Error) && a.message === b.message)) { + return false; + } + _b = b.clause; + _a = a.clause; + continue; + }; } function equal_null(x, y) { diff --git a/lib/es6/camlinternalLazy.js b/lib/es6/camlinternalLazy.js index 4e8978398a..b9f8aaafcc 100644 --- a/lib/es6/camlinternalLazy.js +++ b/lib/es6/camlinternalLazy.js @@ -33,13 +33,9 @@ function force(lzv) { return forward_with_closure(lzv, closure); } catch (e) { lzv.VAL = (function () { - throw new Error(e.RE_EXN_ID, { - cause: e - }); - }); - throw new Error(e.RE_EXN_ID, { - cause: e + throw e; }); + throw e; } } } diff --git a/lib/es6/filename.js b/lib/es6/filename.js index 7eff32f9f3..a87d942470 100644 --- a/lib/es6/filename.js +++ b/lib/es6/filename.js @@ -123,9 +123,7 @@ try { if (exn.RE_EXN_ID === "Not_found") { temp_dir_name = "/tmp"; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -205,9 +203,7 @@ try { if (exn$1.RE_EXN_ID === "Not_found") { temp_dir_name$1 = "."; } else { - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } diff --git a/lib/es6/genlex.js b/lib/es6/genlex.js index 9e2005ad19..639f9610a2 100644 --- a/lib/es6/genlex.js +++ b/lib/es6/genlex.js @@ -60,9 +60,7 @@ function make_lexer(keywords) { _0: id }; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } }; let keyword_or_error = function (c) { @@ -79,9 +77,7 @@ function make_lexer(keywords) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } }; let next_token = function (strm__) { @@ -127,9 +123,7 @@ function make_lexer(keywords) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } let match = Stream.peek(strm__); if (match !== undefined) { @@ -482,9 +476,7 @@ function make_lexer(keywords) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } store(c$1); continue; @@ -519,9 +511,7 @@ function make_lexer(keywords) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } else { throw new Error(Stream.Failure, { diff --git a/lib/es6/hashtbl.js b/lib/es6/hashtbl.js index 6a8a0e8b92..6151c423ea 100644 --- a/lib/es6/hashtbl.js +++ b/lib/es6/hashtbl.js @@ -470,14 +470,10 @@ function iter(f, h) { } } catch (exn) { if (old_trav) { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } flip_ongoing_traversal(h); - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -527,14 +523,10 @@ function filter_map_inplace(f, h) { return; } catch (exn) { if (old_trav) { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } flip_ongoing_traversal(h); - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -570,14 +562,10 @@ function fold(f, h, init) { return accu; } catch (exn) { if (old_trav) { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } flip_ongoing_traversal(h); - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/es6/int32.js b/lib/es6/int32.js index 044b7687ef..dff650c3e9 100644 --- a/lib/es6/int32.js +++ b/lib/es6/int32.js @@ -36,9 +36,7 @@ function of_string_opt(s) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/es6/int64.js b/lib/es6/int64.js index 1c102d7b2f..37fd9241c7 100644 --- a/lib/es6/int64.js +++ b/lib/es6/int64.js @@ -29,9 +29,7 @@ function of_string_opt(s) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/es6/js_exn.js b/lib/es6/js_exn.js index 5d9a1f8fa9..74add0dd3a 100644 --- a/lib/es6/js_exn.js +++ b/lib/es6/js_exn.js @@ -2,45 +2,31 @@ function raiseError(str) { - throw new Error(new Error(str).RE_EXN_ID, { - cause: new Error(str) - }); + throw new Error(str); } function raiseEvalError(str) { - throw new Error(new EvalError(str).RE_EXN_ID, { - cause: new EvalError(str) - }); + throw new EvalError(str); } function raiseRangeError(str) { - throw new Error(new RangeError(str).RE_EXN_ID, { - cause: new RangeError(str) - }); + throw new RangeError(str); } function raiseReferenceError(str) { - throw new Error(new ReferenceError(str).RE_EXN_ID, { - cause: new ReferenceError(str) - }); + throw new ReferenceError(str); } function raiseSyntaxError(str) { - throw new Error(new SyntaxError(str).RE_EXN_ID, { - cause: new SyntaxError(str) - }); + throw new SyntaxError(str); } function raiseTypeError(str) { - throw new Error(new TypeError(str).RE_EXN_ID, { - cause: new TypeError(str) - }); + throw new TypeError(str); } function raiseUriError(str) { - throw new Error(new URIError(str).RE_EXN_ID, { - cause: new URIError(str) - }); + throw new URIError(str); } let $$Error$1 = "JsError"; diff --git a/lib/es6/js_null.js b/lib/es6/js_null.js index 4a30b70360..9ac6a94514 100644 --- a/lib/es6/js_null.js +++ b/lib/es6/js_null.js @@ -10,9 +10,7 @@ function getExn(f) { if (f !== null) { return f; } - throw new Error(new Error("Js.Null.getExn").RE_EXN_ID, { - cause: new Error("Js.Null.getExn") - }); + throw new Error("Js.Null.getExn"); } function bind(x, f) { diff --git a/lib/es6/js_option.js b/lib/es6/js_option.js index b24505acab..0667fcd74d 100644 --- a/lib/es6/js_option.js +++ b/lib/es6/js_option.js @@ -26,9 +26,7 @@ function getExn(x) { if (x !== undefined) { return Caml_option.valFromOption(x); } - throw new Error(new Error("getExn").RE_EXN_ID, { - cause: new Error("getExn") - }); + throw new Error("getExn"); } function equal(eq, a, b) { diff --git a/lib/es6/js_undefined.js b/lib/es6/js_undefined.js index 762283d3da..8d5125bc03 100644 --- a/lib/es6/js_undefined.js +++ b/lib/es6/js_undefined.js @@ -14,9 +14,7 @@ function getExn(f) { if (f !== undefined) { return f; } - throw new Error(new Error("Js.Undefined.getExn").RE_EXN_ID, { - cause: new Error("Js.Undefined.getExn") - }); + throw new Error("Js.Undefined.getExn"); } function bind(x, f) { diff --git a/lib/es6/parsing.js b/lib/es6/parsing.js index bf77a01d44..5a785ac417 100644 --- a/lib/es6/parsing.js +++ b/lib/es6/parsing.js @@ -117,9 +117,7 @@ function yyparse(tables, start, lexer, lexbuf) { undefined ]; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } _arg = match$1[1]; @@ -152,9 +150,7 @@ function yyparse(tables, start, lexer, lexbuf) { return Caml_array.get(tables.transl_const, tok) === curr_char; } }); - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } diff --git a/lib/es6/pervasives.js b/lib/es6/pervasives.js index a80ead8cb4..0236683bd4 100644 --- a/lib/es6/pervasives.js +++ b/lib/es6/pervasives.js @@ -111,9 +111,7 @@ function int_of_string_opt(s) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -153,9 +151,7 @@ function float_of_string_opt(s) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/es6/string.js b/lib/es6/string.js index c19e2db03c..dc4ea62d28 100644 --- a/lib/es6/string.js +++ b/lib/es6/string.js @@ -234,9 +234,7 @@ function contains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -261,9 +259,7 @@ function rcontains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/es6/stringLabels.js b/lib/es6/stringLabels.js index 74f7f99d18..0048d46541 100644 --- a/lib/es6/stringLabels.js +++ b/lib/es6/stringLabels.js @@ -236,9 +236,7 @@ function contains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -263,9 +261,7 @@ function rcontains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/js/arg.js b/lib/js/arg.js index e06814b14b..d0160663e3 100644 --- a/lib/js/arg.js +++ b/lib/js/arg.js @@ -90,9 +90,7 @@ function add_help(speclist) { tl: /* [] */0 }; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } let add2; @@ -114,9 +112,7 @@ function add_help(speclist) { tl: /* [] */0 }; } else { - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } return Pervasives.$at(speclist, Pervasives.$at(add1, add2)); @@ -161,9 +157,7 @@ function bool_of_string_opt(x) { if (exn.RE_EXN_ID === "Invalid_argument") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -175,9 +169,7 @@ function int_of_string_opt(x) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -189,9 +181,7 @@ function float_of_string_opt(x) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -229,15 +219,19 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist TAG: "Unknown", _0: "--help" })) { - return { - RE_EXN_ID: Help, - _1: Buffer.contents(b) - }; + return new Error(Help, { + cause: { + RE_EXN_ID: Help, + _1: Buffer.contents(b) + } + }); } else { - return { - RE_EXN_ID: Bad, - _1: Buffer.contents(b) - }; + return new Error(Bad, { + cause: { + RE_EXN_ID: Bad, + _1: Buffer.contents(b) + } + }); } }; current.contents = current.contents + 1 | 0; @@ -273,14 +267,10 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist } }); } - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } let follow = match[1]; @@ -500,24 +490,15 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist } catch (raw_m) { let m = Caml_js_exceptions.internalToOCamlException(raw_m); if (m.RE_EXN_ID === Bad) { - throw new Error(convert_error({ + throw convert_error({ TAG: "Message", _0: m._1 - }).RE_EXN_ID, { - cause: convert_error({ - TAG: "Message", - _0: m._1 - }) }); } if (m.RE_EXN_ID === Stop) { - throw new Error(convert_error(m._1).RE_EXN_ID, { - cause: convert_error(m._1) - }); + throw convert_error(m._1); } - throw new Error(m.RE_EXN_ID, { - cause: m - }); + throw m; } current.contents = current.contents + 1 | 0; }; @@ -554,9 +535,7 @@ function parse(l, f, msg) { console.log(msg$1._1); return Pervasives.exit(0); } - throw new Error(msg$1.RE_EXN_ID, { - cause: msg$1 - }); + throw msg$1; } } @@ -573,9 +552,7 @@ function parse_dynamic(l, f, msg) { console.log(msg$1._1); return Pervasives.exit(0); } - throw new Error(msg$1.RE_EXN_ID, { - cause: msg$1 - }); + throw msg$1; } } @@ -601,9 +578,7 @@ function parse_expand(l, f, msg) { console.log(msg$1._1); return Pervasives.exit(0); } - throw new Error(msg$1.RE_EXN_ID, { - cause: msg$1 - }); + throw msg$1; } } @@ -638,18 +613,14 @@ function second_word(s) { if (exn$1.RE_EXN_ID === "Not_found") { return len; } - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } if (exit === 2) { return loop(n$1 + 1 | 0); } } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } return loop(n + 1 | 0); diff --git a/lib/js/array.js b/lib/js/array.js index 81d2af9cb4..1a82f2de72 100644 --- a/lib/js/array.js +++ b/lib/js/array.js @@ -342,9 +342,7 @@ function sort(cmp, a) { if (i$2.RE_EXN_ID === Bottom) { return Caml_array.set(a, i$2._1, e); } - throw new Error(i$2.RE_EXN_ID, { - cause: i$2 - }); + throw i$2; } }; let bubble = function (l, i) { @@ -362,9 +360,7 @@ function sort(cmp, a) { if (i$2.RE_EXN_ID === Bottom) { return i$2._1; } - throw new Error(i$2.RE_EXN_ID, { - cause: i$2 - }); + throw i$2; } }; let trickleup = function (_i, e) { diff --git a/lib/js/arrayLabels.js b/lib/js/arrayLabels.js index cd50a85c00..8938319831 100644 --- a/lib/js/arrayLabels.js +++ b/lib/js/arrayLabels.js @@ -342,9 +342,7 @@ function sort(cmp, a) { if (i$2.RE_EXN_ID === Bottom) { return Caml_array.set(a, i$2._1, e); } - throw new Error(i$2.RE_EXN_ID, { - cause: i$2 - }); + throw i$2; } }; let bubble = function (l, i) { @@ -362,9 +360,7 @@ function sort(cmp, a) { if (i$2.RE_EXN_ID === Bottom) { return i$2._1; } - throw new Error(i$2.RE_EXN_ID, { - cause: i$2 - }); + throw i$2; } }; let trickleup = function (_i, e) { diff --git a/lib/js/bytes.js b/lib/js/bytes.js index b404268df9..5bb81515fd 100644 --- a/lib/js/bytes.js +++ b/lib/js/bytes.js @@ -633,9 +633,7 @@ function contains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -660,9 +658,7 @@ function rcontains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/js/bytesLabels.js b/lib/js/bytesLabels.js index b404268df9..5bb81515fd 100644 --- a/lib/js/bytesLabels.js +++ b/lib/js/bytesLabels.js @@ -633,9 +633,7 @@ function contains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -660,9 +658,7 @@ function rcontains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/js/caml_format.js b/lib/js/caml_format.js index c272d1b695..4602501cc4 100644 --- a/lib/js/caml_format.js +++ b/lib/js/caml_format.js @@ -777,10 +777,12 @@ let float_of_string = (function(s,exn){ }); function float_of_string$1(s) { - return float_of_string(s, { - RE_EXN_ID: "Failure", - _1: "float_of_string" - }); + return float_of_string(s, new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: "float_of_string" + } + })); } exports.format_float = format_float; diff --git a/lib/js/caml_hash.js b/lib/js/caml_hash.js index 0fbd07cb73..925d119941 100644 --- a/lib/js/caml_hash.js +++ b/lib/js/caml_hash.js @@ -66,15 +66,11 @@ function hash(count, _limit, seed, obj) { if (size !== 0) { let obj_tag = obj$1.TAG; let tag = (size << 10) | obj_tag; - if (obj_tag === 248) { - s = Caml_hash_primitive.hash_mix_int(s, obj$1[1]); - } else { - s = Caml_hash_primitive.hash_mix_int(s, tag); - let v = size - 1 | 0; - let block = v < num ? v : num; - for (let i = 0; i <= block; ++i) { - push_back(queue, obj$1[i]); - } + s = Caml_hash_primitive.hash_mix_int(s, tag); + let v = size - 1 | 0; + let block = v < num ? v : num; + for (let i = 0; i <= block; ++i) { + push_back(queue, obj$1[i]); } } else { let size$1 = (function(obj,cb){ diff --git a/lib/js/caml_js_exceptions.js b/lib/js/caml_js_exceptions.js index 732c63689d..cc32585b62 100644 --- a/lib/js/caml_js_exceptions.js +++ b/lib/js/caml_js_exceptions.js @@ -9,10 +9,12 @@ function internalToOCamlException(e) { if (Caml_exceptions.is_extension(e.cause)) { return e.cause; } else { - return { - RE_EXN_ID: "JsError", - _1: e - }; + return new Error("JsError", { + cause: { + RE_EXN_ID: "JsError", + _1: e + } + }); } } diff --git a/lib/js/caml_lexer.js b/lib/js/caml_lexer.js index dfaf1adaca..3b300f7ce1 100644 --- a/lib/js/caml_lexer.js +++ b/lib/js/caml_lexer.js @@ -104,10 +104,12 @@ let caml_lex_engine_aux = (function (tbl, start_state, lexbuf, exn){ let empty_token_lit = "lexing: empty token"; function lex_engine(tbls, i, buf) { - return caml_lex_engine_aux(tbls, i, buf, { - RE_EXN_ID: "Failure", - _1: empty_token_lit - }); + return caml_lex_engine_aux(tbls, i, buf, new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: empty_token_lit + } + })); } /***********************************************/ @@ -245,10 +247,12 @@ let caml_new_lex_engine_aux = (function (tbl, start_state, lexbuf, exn) { }); function new_lex_engine(tbl, i, buf) { - return caml_new_lex_engine_aux(tbl, i, buf, { - RE_EXN_ID: "Failure", - _1: empty_token_lit - }); + return caml_new_lex_engine_aux(tbl, i, buf, new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: empty_token_lit + } + })); } exports.lex_engine = lex_engine; diff --git a/lib/js/caml_obj.js b/lib/js/caml_obj.js index 65e0d78ebc..4790664222 100644 --- a/lib/js/caml_obj.js +++ b/lib/js/caml_obj.js @@ -132,17 +132,6 @@ function compare(a, b) { } let tag_a = a.TAG; let tag_b = b.TAG; - if (tag_a === 248) { - return Caml.int_compare(a[1], b[1]); - } - if (tag_a === 251) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "equal: abstract value" - } - }); - } if (tag_a !== tag_b) { if (tag_a < tag_b) { return -1; @@ -256,87 +245,85 @@ function aux_obj_compare(a, b) { } } -function equal(a, b) { - if (a === b) { - return true; - } - let a_type = typeof a; - if (a_type === "string" || a_type === "number" || a_type === "bigint" || a_type === "boolean" || a_type === "undefined" || a === null) { - return false; - } - let b_type = typeof b; - if (a_type === "function" || b_type === "function") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "equal: functional value" - } - }); - } - if (b_type === "number" || b_type === "bigint" || b_type === "undefined" || b === null) { - return false; - } - let tag_a = a.TAG; - let tag_b = b.TAG; - if (tag_a === 248) { - return a[1] === b[1]; - } - if (tag_a === 251) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "equal: abstract value" - } - }); - } - if (tag_a !== tag_b) { - return false; - } - let len_a = a.length | 0; - let len_b = b.length | 0; - if (len_a === len_b) { +function equal(_a, _b) { + while (true) { + let b = _b; + let a = _a; + if (a === b) { + return true; + } + let a_type = typeof a; + if (a_type !== "object" || a === null) { + return false; + } + let b_type = typeof b; + if (b_type !== "object" || b === null) { + return false; + } + let tag_a = a.TAG; + let tag_b = b.TAG; + if (tag_a !== tag_b) { + return false; + } if (Array.isArray(a)) { - let _i = 0; - while (true) { - let i = _i; - if (i === len_a) { - return true; - } - if (!equal(a[i], b[i])) { + let len_a = a.length | 0; + let len_b = b.length | 0; + if (len_a !== len_b) { + return false; + } else { + let _i = 0; + while (true) { + let i = _i; + if (i === len_a) { + return true; + } + if (!equal(a[i], b[i])) { + return false; + } + _i = i + 1 | 0; + continue; + }; + } + } + if (!(a instanceof Error)) { + if ((a instanceof Date)) { + if ((b instanceof Date)) { + return !(a > b || a < b); + } else { return false; } - _i = i + 1 | 0; - continue; - }; - } else if ((a instanceof Date && b instanceof Date)) { - return !(a > b || a < b); - } else { - let result = { - contents: true - }; - let do_key_a = function (key) { - if (!Object.prototype.hasOwnProperty.call(b, key)) { - result.contents = false; - return; - } - - }; - let do_key_b = function (key) { - if (!Object.prototype.hasOwnProperty.call(a, key) || !equal(b[key], a[key])) { - result.contents = false; - return; + } else { + let result = { + contents: true + }; + let do_key_a = function (key) { + if (!Object.prototype.hasOwnProperty.call(b, key)) { + result.contents = false; + return; + } + + }; + let do_key_b = function (key) { + if (!Object.prototype.hasOwnProperty.call(a, key) || !equal(b[key], a[key])) { + result.contents = false; + return; + } + + }; + for_in(a, do_key_a); + if (result.contents) { + for_in(b, do_key_b); } - - }; - for_in(a, do_key_a); - if (result.contents) { - for_in(b, do_key_b); + return result.contents; } - return result.contents; } - } else { - return false; - } + if (!((b instanceof Error) && a.message === b.message)) { + return false; + } + _b = b.clause; + _a = a.clause; + continue; + }; } function equal_null(x, y) { diff --git a/lib/js/camlinternalLazy.js b/lib/js/camlinternalLazy.js index a1f4efec8a..fdf1daedca 100644 --- a/lib/js/camlinternalLazy.js +++ b/lib/js/camlinternalLazy.js @@ -33,13 +33,9 @@ function force(lzv) { return forward_with_closure(lzv, closure); } catch (e) { lzv.VAL = (function () { - throw new Error(e.RE_EXN_ID, { - cause: e - }); - }); - throw new Error(e.RE_EXN_ID, { - cause: e + throw e; }); + throw e; } } } diff --git a/lib/js/filename.js b/lib/js/filename.js index 4cbda61834..fa7986ca18 100644 --- a/lib/js/filename.js +++ b/lib/js/filename.js @@ -123,9 +123,7 @@ try { if (exn.RE_EXN_ID === "Not_found") { temp_dir_name = "/tmp"; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -205,9 +203,7 @@ try { if (exn$1.RE_EXN_ID === "Not_found") { temp_dir_name$1 = "."; } else { - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } diff --git a/lib/js/genlex.js b/lib/js/genlex.js index e708d6239b..52d02ce2f8 100644 --- a/lib/js/genlex.js +++ b/lib/js/genlex.js @@ -60,9 +60,7 @@ function make_lexer(keywords) { _0: id }; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } }; let keyword_or_error = function (c) { @@ -79,9 +77,7 @@ function make_lexer(keywords) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } }; let next_token = function (strm__) { @@ -127,9 +123,7 @@ function make_lexer(keywords) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } let match = Stream.peek(strm__); if (match !== undefined) { @@ -482,9 +476,7 @@ function make_lexer(keywords) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } store(c$1); continue; @@ -519,9 +511,7 @@ function make_lexer(keywords) { } }); } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } else { throw new Error(Stream.Failure, { diff --git a/lib/js/hashtbl.js b/lib/js/hashtbl.js index 112833ee17..5ba6e2348c 100644 --- a/lib/js/hashtbl.js +++ b/lib/js/hashtbl.js @@ -470,14 +470,10 @@ function iter(f, h) { } } catch (exn) { if (old_trav) { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } flip_ongoing_traversal(h); - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -527,14 +523,10 @@ function filter_map_inplace(f, h) { return; } catch (exn) { if (old_trav) { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } flip_ongoing_traversal(h); - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -570,14 +562,10 @@ function fold(f, h, init) { return accu; } catch (exn) { if (old_trav) { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } flip_ongoing_traversal(h); - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/js/int32.js b/lib/js/int32.js index 00883d1909..2493b20d95 100644 --- a/lib/js/int32.js +++ b/lib/js/int32.js @@ -36,9 +36,7 @@ function of_string_opt(s) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/js/int64.js b/lib/js/int64.js index b46cab5118..c6423d62e4 100644 --- a/lib/js/int64.js +++ b/lib/js/int64.js @@ -29,9 +29,7 @@ function of_string_opt(s) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/js/js_exn.js b/lib/js/js_exn.js index 706c4b6181..34b90db044 100644 --- a/lib/js/js_exn.js +++ b/lib/js/js_exn.js @@ -2,45 +2,31 @@ function raiseError(str) { - throw new Error(new Error(str).RE_EXN_ID, { - cause: new Error(str) - }); + throw new Error(str); } function raiseEvalError(str) { - throw new Error(new EvalError(str).RE_EXN_ID, { - cause: new EvalError(str) - }); + throw new EvalError(str); } function raiseRangeError(str) { - throw new Error(new RangeError(str).RE_EXN_ID, { - cause: new RangeError(str) - }); + throw new RangeError(str); } function raiseReferenceError(str) { - throw new Error(new ReferenceError(str).RE_EXN_ID, { - cause: new ReferenceError(str) - }); + throw new ReferenceError(str); } function raiseSyntaxError(str) { - throw new Error(new SyntaxError(str).RE_EXN_ID, { - cause: new SyntaxError(str) - }); + throw new SyntaxError(str); } function raiseTypeError(str) { - throw new Error(new TypeError(str).RE_EXN_ID, { - cause: new TypeError(str) - }); + throw new TypeError(str); } function raiseUriError(str) { - throw new Error(new URIError(str).RE_EXN_ID, { - cause: new URIError(str) - }); + throw new URIError(str); } let $$Error$1 = "JsError"; diff --git a/lib/js/js_null.js b/lib/js/js_null.js index 7d8ddcb6e1..682a2a31a5 100644 --- a/lib/js/js_null.js +++ b/lib/js/js_null.js @@ -10,9 +10,7 @@ function getExn(f) { if (f !== null) { return f; } - throw new Error(new Error("Js.Null.getExn").RE_EXN_ID, { - cause: new Error("Js.Null.getExn") - }); + throw new Error("Js.Null.getExn"); } function bind(x, f) { diff --git a/lib/js/js_option.js b/lib/js/js_option.js index 0b876c2b9a..5a513afd29 100644 --- a/lib/js/js_option.js +++ b/lib/js/js_option.js @@ -26,9 +26,7 @@ function getExn(x) { if (x !== undefined) { return Caml_option.valFromOption(x); } - throw new Error(new Error("getExn").RE_EXN_ID, { - cause: new Error("getExn") - }); + throw new Error("getExn"); } function equal(eq, a, b) { diff --git a/lib/js/js_undefined.js b/lib/js/js_undefined.js index 567ce8fec5..f67e1ec960 100644 --- a/lib/js/js_undefined.js +++ b/lib/js/js_undefined.js @@ -14,9 +14,7 @@ function getExn(f) { if (f !== undefined) { return f; } - throw new Error(new Error("Js.Undefined.getExn").RE_EXN_ID, { - cause: new Error("Js.Undefined.getExn") - }); + throw new Error("Js.Undefined.getExn"); } function bind(x, f) { diff --git a/lib/js/parsing.js b/lib/js/parsing.js index 72a439cfa8..2eb0198048 100644 --- a/lib/js/parsing.js +++ b/lib/js/parsing.js @@ -117,9 +117,7 @@ function yyparse(tables, start, lexer, lexbuf) { undefined ]; } else { - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } _arg = match$1[1]; @@ -152,9 +150,7 @@ function yyparse(tables, start, lexer, lexbuf) { return Caml_array.get(tables.transl_const, tok) === curr_char; } }); - throw new Error(exn$1.RE_EXN_ID, { - cause: exn$1 - }); + throw exn$1; } } diff --git a/lib/js/pervasives.js b/lib/js/pervasives.js index adb37289e3..5e8213123d 100644 --- a/lib/js/pervasives.js +++ b/lib/js/pervasives.js @@ -111,9 +111,7 @@ function int_of_string_opt(s) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -153,9 +151,7 @@ function float_of_string_opt(s) { if (exn.RE_EXN_ID === "Failure") { return; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/js/string.js b/lib/js/string.js index d6be0fd764..221601687c 100644 --- a/lib/js/string.js +++ b/lib/js/string.js @@ -234,9 +234,7 @@ function contains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -261,9 +259,7 @@ function rcontains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } diff --git a/lib/js/stringLabels.js b/lib/js/stringLabels.js index d66bfccf31..59ca7f890d 100644 --- a/lib/js/stringLabels.js +++ b/lib/js/stringLabels.js @@ -236,9 +236,7 @@ function contains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } } @@ -263,9 +261,7 @@ function rcontains_from(s, i, c) { if (exn.RE_EXN_ID === "Not_found") { return false; } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); + throw exn; } }