Skip to content

Conversation

@mlasson
Copy link
Collaborator

@mlasson mlasson commented Aug 27, 2025

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 ocsigen/js_of_ocaml#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)|])

@hhugo
Copy link
Contributor

hhugo commented Nov 3, 2025

I've tried to update the PR with the latest change from jsoo ocsigen/js_of_ocaml#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
Copy link
Contributor

hhugo commented Nov 3, 2025

This new feature needs to be documented

@vouillon
Copy link
Contributor

vouillon commented Nov 3, 2025

@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").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants