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

Eliminate JS API footgun by making sure we don't invalidate the variables passed across js-wasm bound #262

Closed
2 tasks
fl0rek opened this issue Apr 5, 2024 · 2 comments

Comments

@fl0rek
Copy link
Member

fl0rek commented Apr 5, 2024

Currently, WasmNode expects to take ownership over the config when it's passed from JS. Nothing stops JS from still holding the config reference it has though, which causes an exception on access.

  • does the same hold for JsValue or is it relevant for to types?
  • Make sure we're taking parameters from JS safely, potentially cloning or taking by reference instead
@fl0rek
Copy link
Member Author

fl0rek commented Apr 12, 2024

Another observation: &mut borrows can also be problematic, as they can allow concurrent rw borrows from js, and these can only be checked at runtime.

Consider the example

struct Foo;
impl Foo {
  async fn wait(&mut self) {
    // do some computation
  }
}
let foo = new Foo();
foo.wait();
foo.wait();

Since second wait call will usually happen before the first promise is resolved, Foo is still mutably borrowed there. This results in runtime error from bindgen:

Uncaught Error: recursive use of an object detected which would lead to unsafe aliasing in rust

This case is most easily tiggered with async fn which borrows &mut (as in example), but generally can happen anywhere where looser js rules violate Rust's single mutable borrow rule.

@zvolin zvolin moved this to Todo in Lumina Oct 4, 2024
@zvolin zvolin added this to Lumina Oct 4, 2024
@fl0rek
Copy link
Member Author

fl0rek commented Oct 11, 2024

closed by #396

@fl0rek fl0rek closed this as completed Oct 11, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Lumina Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant