# \[ANN\] Bindings to QuickJS

**URL:** https://discuss.ocaml.org/t/ann-bindings-to-quickjs/14263
**Category:** Ecosystem
**Tags:** announce
**Created:** [March 7, 2024, 2:14pm UTC](https://discuss.ocaml.org/t/ann-bindings-to-quickjs/14263 "2024-03-07T14:14:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![davesnx](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/davesnx/32/2949_2.png) [@davesnx](https://discuss.ocaml.org/u/davesnx)
#### Post date: [March 7, 2024, 2:14pm UTC](https://discuss.ocaml.org/t/ann-bindings-to-quickjs/14263/1 "2024-03-07T14:14:44Z")

</div>

Hello discuss,

I’m happy to announce a new library ([quickjs.ml](https://opam.ocaml.org/packages/quickjs/)) that I have been working on, sometimes on-stream with the help of a few people (specially @welltypedwitch) and other times, just coding lonely.

It’s an early project to bind to quickjs **[QuickJS Javascript Engine](https://bellard.org/quickjs)** a small and embeddable JavaScript engine. It supports the ES2023 specification including modules, asynchronous generators, proxies and BigInt.

It passes nearly 100% of the ECMAScript Test Suite tests when selecting the ES2023 features. A summary is available at [Test262 Report](https://test262.fyi/) and has very low startup time (compared to other JS Engines).

The need to bind to a JavaScript engine on OCaml appeared while working with server-reason-react components. While moving ReasonReact components from the browser into the server.

Those components relied on JavaScript APIs such as DOM APIs, but also some “pure” JS. The part of the browser isn’t available on the server (obv) so we discard it with a ppx (called browser\_ppx [https://twitter.com/davesnx/status/1765059888550686892](https://twitter.com/davesnx/status/1765059888550686892)) but still there were some (”pure JS”) code that could run on the server such as Array/List/String operations, RegExp, i18n, Date, etc.

On the browser, those apis are available under `melange.js` (which are bindings to JS: [https://melange.re/v2.0.0/communicate-with-javascript](https://melange.re/v2.0.0/communicate-with-javascript/)) and I made an effort of having similar implemenations on `server-reason-react.js` which implemented in OCaml the same APIs, but there were a few issues that I couldn’t resolve in OCaml (or I didn’t want to resolve), for example the JavaScript RegExp engine had backtracing and named groups which Pcre (the first approach I used) doesn’t have.

Those APIs are available (with a full test suite) on many JS engines, so It was a matter of choosing one and bind to it… which brings to release [quickjs.ml](http://quickjs.ml) into opam with RegExp support and ongoing **BigInt, Date, parse numbers, and encode/decode URI.**

Let me know if you find it useful, and feel free to collab!

PS: I’m very aware that the meme writes itself, OCaml to JS and now we bring JS into OCaml.

---

<div class="post-metadata">

### Author: ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)
#### Post date: [March 7, 2024, 2:19pm UTC](https://discuss.ocaml.org/t/ann-bindings-to-quickjs/14263/2 "2024-03-07T14:19:45Z")

</div>

Sounds interesting! However, I could not access the documentation for the full library API… do you have a direct link?

Cheers,  
Nicolas

---

<div class="post-metadata">

### Author: ![davesnx](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/davesnx/32/2949_2.png) [@davesnx](https://discuss.ocaml.org/u/davesnx)
#### Post date: [March 7, 2024, 2:24pm UTC](https://discuss.ocaml.org/t/ann-bindings-to-quickjs/14263/3 "2024-03-07T14:24:26Z")

</div>

I didn’t find anywhere the documentation for the API published, but it’s one file on the repo: [quickjs/quickjs.h at master · bellard/quickjs · GitHub](https://github.com/bellard/quickjs/blob/master/quickjs.h)

Worth mentioning (I forgot to say it earlier) that I don’t bind to the public interface (for example: js\_\_regex\_exec) but rather the internal `(lre_exec)` since the outside requieres JS\_Value, JS\_Context and many JS\_\* that aren’t desired/possible to bind with OCaml.
