Skip to content

Commit

Permalink
add Printexc.exn_slot_id to the runtime
Browse files Browse the repository at this point in the history
add changelog entry
  • Loading branch information
anmonteiro committed Feb 11, 2023
1 parent b575d90 commit a616e48
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Unreleased
([#472](https://github.com/melange-re/melange/pull/472))
- melange: Make `Pervasives` exactly match the `Stdlib` behavior
([#476](https://github.com/melange-re/melange/pull/476))
- melange:
- melange: fix unbound error when trying to use `Printexc.exn_slot_id`
([#482](https://github.com/melange-re/melange/pull/482))

0.3.2 2022-11-19
---------------
Expand Down
17 changes: 16 additions & 1 deletion jscomp/runtime/caml_exceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,26 @@ let create (str : string) : string =
This is not a problem in `try .. with` since the logic above is not expressible, see more design in [destruct_exn.md]
*)
let caml_is_extension (type a ) (e : a) : bool =
if Js.testAny e then false
if Js.testAny e then false
else Js.typeof (Obj.magic e : t) .id = "string"




(**FIXME: remove the trailing `/` *)
let caml_exn_slot_name (x : t) : string = x.id
let caml_exn_slot_id : t -> int = [%raw{|function(x){
if (x.RE_EXN_ID != null) {
var parts = x.RE_EXN_ID.split("/");
if (parts.length > 1) {
return Number(parts[parts.length - 1])
} else {
return -1;
}
} else {
return -1;
}
}
|}]


10 changes: 7 additions & 3 deletions test/print-exn.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ An example that uses exceptions runtime
> try f () with
> | exn -> Printexc.exn_slot_id exn
> let result = run (fun _ -> failwith "oops")
>
> exception Custom
> let () =
> Js.log2 (Printexc.exn_slot_id Custom) (Printexc.exn_slot_id Not_found)
>
> EOF
$ cat > dune-project <<EOF
> (lang dune 3.7)
Expand All @@ -21,6 +26,5 @@ An example that uses exceptions runtime
> (module_system commonjs))
> EOF
$ dune build @melange
$ node ./_build/default/melange/x.js 2>&1 | awk '/exn_slot_id/'
return Printexc.exn_slot_id(Caml_js_exceptions.internalToOCamlException(raw_exn));
TypeError: Printexc.exn_slot_id is not a function
$ node ./_build/default/melange/x.js
7 -1

0 comments on commit a616e48

Please sign in to comment.