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

[BUG] Using two Js_of_ocaml compiled libraries in the same runtime causes issues with js stubs #1622

Closed
troederjs opened this issue Jun 10, 2024 · 5 comments
Labels

Comments

@troederjs
Copy link

Describe the bug
If two separate ocaml libraries have JS stubs which define the same symbol ion joo_global_object (e.g. two different versions of src-bindings/node/dune in the OCaml VSCode extension) they will conflict when both libraries are loaded by different Js_of_ocaml executable.

This happens because joo_global_object is the globalThis, and so the two values override each other.

Normally, when running a single application this is not a problem since we can control all the dependencies and ensure they don't conflict. But specifically in the case of the VSCode extension, this causes issues when there are two Js_of_ocaml extensions that use incompatible versions of the nodejs binding stubs.

Expected behavior
Both Js_of_ocaml executable should be able to run independently in the same JS environment.

@troederjs troederjs added the bug label Jun 10, 2024
@hhugo
Copy link
Member

hhugo commented Jun 10, 2024

First note that joo_global_object should be avoided, support will be removed at some point. One should use globalThis instead.

It seems to me that vscode-ocaml-platform is part of the problem here. It should not update the global object,it should defined its own stubs.

@troederjs
Copy link
Author

What is the correct way to access a JS stub without making it available on some global context like globalThis?

@hhugo
Copy link
Member

hhugo commented Jun 10, 2024

https://ocsigen.org/js_of_ocaml/latest/manual/linker gives some information.

In short,

//Provides: customAdd
function customAdd(a,b){
  return a + b
}
 external add : int -> int -> int = "customAdd"

@hhugo
Copy link
Member

hhugo commented Oct 9, 2024

I've worked on a bunch of changes to limit global side effects (#1708, #1696)
Assuming bindings are written correctly (not by mutating the global object), two jsoo programs should be able to coexists without too much interference. I'll try to list and document the remaining side effects at some point.

@hhugo
Copy link
Member

hhugo commented Oct 10, 2024

I'm opening ocamllabs/vscode-ocaml-platform#1617 and will close this one

@hhugo hhugo closed this as completed Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants