Use the wasm_bindgen_downcast crate for downcasting JsValues #3400
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We need this because
@wasmer/wasi
gets minified, which breaks theJsValue -> 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 JavaScriptSymbol
with each Rust type implementing theDowncastJS
trait. That gives us something we can check before downcasting aJsValue
back to aWasmerRuntimeError
.The underlying issue is that
@wasmer/wasi
implements theexit()
syscall by raising aWasmerRuntimeError
with the exit code as a JavaScript exception and catching it from the outside. To get the exit code back, we try to downcast theJsValue
we caught back to aWasmerRuntimeError
, but because the minifier renamed"WasmerRuntimeError"
to"H"
, the string-basedgeneric_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 aonce-cell
).See wasmerio/wasmer-js#310 for a much more in-depth explanation of the issue.