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

Use the wasm_bindgen_downcast crate for downcasting JsValues #3400

Merged
merged 1 commit into from
Dec 1, 2022

Conversation

Michael-F-Bryan
Copy link
Contributor

@Michael-F-Bryan Michael-F-Bryan commented Dec 1, 2022

We need this because @wasmer/wasi gets minified, which breaks the JsValue -> WasmerRuntimeError downcast in the same way that was mentioned in rustwasm/wasm-bindgen#2231 (comment).

The wasm-bindgen-downcast crate works by associating a unique JavaScript Symbol with each Rust type implementing the DowncastJS trait. That gives us something we can check before downcasting a JsValue back to a WasmerRuntimeError.

The underlying issue is that @wasmer/wasi implements the exit() syscall by raising a WasmerRuntimeError with the exit code as a JavaScript exception and catching it from the outside. To get the exit code back, we try to downcast the JsValue we caught back to a WasmerRuntimeError, but because the minifier renamed "WasmerRuntimeError" to "H", the string-based generic_of_jsval() downcast doesn't work.

Using symbols fixes this issue because a symbol is guaranteed to be unique and unchanging once you create it (wasm-bindgen-downcast stores it in a once-cell).

See wasmerio/wasmer-js#310 for a much more in-depth explanation of the issue.

We need this because @wasmer/wasi gets minified, which breaks our downcast check.
@syrusakbary syrusakbary merged commit ecde2aa into master Dec 1, 2022
@syrusakbary syrusakbary deleted the fix-downcasting branch December 1, 2022 15:27
Michael-F-Bryan pushed a commit to wasmerio/wasmer-js that referenced this pull request Dec 1, 2022
@MTRNord
Copy link

MTRNord commented May 7, 2023

Hi is it intentional that https://github.com/wasmerio/wasm-bindgen-downcast is not public? The crates.io page claims it to be MIT and Apache2 licensed however the github repo is not public.

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