gen_js_api icon indicating copy to clipboard operation
gen_js_api copied to clipboard

Support for primitives bindings

Open mlasson opened this issue 6 months ago • 6 comments

Description

This PR adds support for a new attribute [@js.runtime "string"] that allows bindings a js_of_ocaml pritimitive using Jsoo_runtime.Sys.external_ from https://github.com/ocsigen/js_of_ocaml/pull/2086

For instance:

  val path: Ojs.t [@@js.runtime "node_path"]

expands to

  let (path : Ojs.t) = Jsoo_runtime.Sys.external_ "node_path"

I also added an extension of the existing "js.scope" attribute by adding an "@" to the parameter you can refer to a runtime primitive.

Example:

[@@@js.scope "@node_fs.promises"]
...
val unlink: string -> unit Promise.t [@@js.global]

expands to

let (unlink : string -> unit Promise.t) =
 fun (x50 : string) ->
   Promise.t_of_js Ojs.unit_of_js
     (Ojs.call
        (Ojs.get_prop_ascii (Jsoo_runtime.Sys.external_ "node_fs")
           "promises") "unlink" [|(Ojs.string_to_js x50)|])

mlasson avatar Aug 27 '25 16:08 mlasson

I've tried to update the PR with the latest change from jsoo https://github.com/ocsigen/js_of_ocaml/pull/2086 (see branch https://github.com/hhugo/gen_js_api/tree/runtime-primitives-bindings-hh). I've also tried to check that it works fine with wasmoo, but tests fail because of boxed floats I guess. @vouillon, would you be able to fix the gen_js_api tests for wasmoo ?

hhugo avatar Nov 03 '25 12:11 hhugo

This new feature needs to be documented

hhugo avatar Nov 03 '25 12:11 hhugo

@vouillon, would you be able to fix the gen_js_api tests for wasmoo ?

I think you just need to replace the occurrences of "123" by (Ojs.string_to_js "123").

vouillon avatar Nov 03 '25 18:11 vouillon

@hhugo I cherry-picked your branch, adapted the PR and document the new features, I'll wait https://github.com/ocsigen/js_of_ocaml/pull/2086 to merge this and make a new release of gen_js_api.

mlasson avatar Nov 19 '25 10:11 mlasson

@hhugo I cherry-picked your branch, adapted the PR and document the new features, I'll wait ocsigen/js_of_ocaml#2086 to merge this and make a new release of gen_js_api.

ocsigen/js_of_ocaml#2086 has been merged ! @hhugo: can we expect a release of JSOO soon?

nojb avatar Dec 01 '25 20:12 nojb

Gentle reminder

smorimoto avatar Dec 23 '25 17:12 smorimoto

Gentle ping

smorimoto avatar Jan 06 '26 04:01 smorimoto

Bump

smorimoto avatar Feb 16 '26 07:02 smorimoto

@smorimoto thanks for the ping. Now that js_of_ocaml has had a release, this one can go forward. We'll try to merge & cut a release shortly.

nojb avatar Feb 16 '26 07:02 nojb