[ANN] Js_of_ocaml 5.9.0

I’m pleased to announce the release of js_of_ocaml 5.9.0. It should soon be available in opam.

Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it
possible to run pure OCaml programs in JavaScript environment like browsers and
Node.js.

Most significant changes:

  • Support for OCaml 5.3
  • Speedup sourcemap generation and improve sourcemap accuracy.
  • Prepare the merge of the wasm_of_ocaml fork back into the js_of_ocaml repo.
  • JS backtraces are really expansive. They now need to be explicitly requested with OCAMLRUNPARAM=b=1. This speeds up programs linked with libraries enabling backtraces programmatically using Printexc.record_backtrace true.

See the Changelog for other changes.

10 Likes

That’s a bit misterious. When and where do you specify that ? The browser execution context has no notion of environment variable.

That’s a bit misterious. When and where do you specify that ? The browser execution context has no notion of environment variable.

You can set environment variable for jsoo by setting the jsoo_env global variable. globalThis.jsoo_env = { "OCAMLRUNPARAM": "b=1"}

Alternatively, you can explicitly request backtraces at compile time with the --enable with-js-error command line argument.

2 Likes

This speeds up programs linked with libraries enabling backtraces programmatically using Printexc.record_backtrace true.

Are there really libraries calling record_backtrace? Do we know which? I use it in my executables, but any library doing so is taking too many liberties, much like libraries that print to stdout/stderr unconditionally.

1 Like

I’m pretty sure I did this in some of my testing libraries (none of which is publicly released though) in order to report location of failing tests. So perhaps that’s the kind of libraries were this can be found.

base does this, see base/src/backtrace.ml at master · janestreet/base · GitHub

1 Like

Note that I’m starting to think that

is not such a good idea.

  1. It’s the kind of “fixing” that ends up confusing everyone at some point. Here goes future discussions: “but I did explicitly require backtraces with Printexc.record_backtraces”, “ah but in js_of_ocaml…”.
  2. I still prefer to call Printexc.record_backtraces in my js_of_ocaml programs to enable backtraces rather than have to set some fake js_of_ocaml notion of process environment.

Why rather not ask base to have a more sensitive default when Sys.backend_type = Other "js_of_ocaml" ?

6 Likes