Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bind a js lib without mutating the global object. #177

Open
hhugo opened this issue Nov 19, 2024 · 0 comments
Open

How to bind a js lib without mutating the global object. #177

hhugo opened this issue Nov 19, 2024 · 0 comments

Comments

@hhugo
Copy link
Contributor

hhugo commented Nov 19, 2024

gen_js_api seems to advertise mutating the global object in order to make js values accessible on the OCaml side using [@@js.get ], [@@js.global], ...

For example,
cat node-test/bindings/imports.mli

[@@@js.scope "__LIB__NODE__IMPORTS"]

val path: Ojs.t [@@js.global]
val fs: Ojs.t [@@js.global]

cat node-test/bindings/imports.js

globalThis.__LIB__NODE__IMPORTS = {
  path: require('path'),
  fs: require('fs'),
};

This causes problems when loading multiple js files generated by jsoo because one could override a global value with an incompatible one , see ocsigen/js_of_ocaml#1622 and ocamllabs/vscode-ocaml-platform#1617.

I'm opening this to understand if this issue has already been solved, if it has already been identified and discuss possible solutions.

Note that jsoo is able to bind to js libs relying on external primitives without mutating the global object.

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

No branches or pull requests

1 participant