Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception rethrow #6933

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 _ ->
Expand Down
4 changes: 0 additions & 4 deletions jscomp/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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 }
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/js_exp_make.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 10 additions & 14 deletions jscomp/runtime/caml_hash.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 23 additions & 34 deletions jscomp/runtime/caml_obj.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.t>), (Obj.magic(b): array<Obj.t>), 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.t>), (Obj.magic(b): array<Obj.t>), 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)
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions jscomp/test/406_primitive_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions jscomp/test/UncurriedExternals.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions jscomp/test/array_safe_get.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions jscomp/test/array_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions jscomp/test/custom_error_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 20 additions & 22 deletions jscomp/test/equal_exception_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions jscomp/test/exception_alias.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions jscomp/test/exception_rebound_err_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading