-
Notifications
You must be signed in to change notification settings - Fork 91
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
wasm-edit -- Valid edits can throw with default decode options. #405
Comments
Thanks for the detailed report. As you've no doubt worked out this issue is due to the presence of a custom name section within your wasm binary. The binary encoded form of wasm doesn't retain function / local names, instead these are all referenced by index. When generating a wasm binary you can optionally supply this information in the form of a custom section. With
The default behaviour of Unfortunately the The
I might give this a go. |
Hi @TimHambourger, thanks for your bug reports (and the great test suite, do you mind if we use it?). This issue is due to a design bug. Here's the definition of a ModuleExport: https://github.com/xtuc/webassemblyjs/blob/master/packages/ast/src/types/nodes.js#L289-L301, where
Here are the fixes I have in mind:
|
Just to clarify, it sounds like you are proposing that the transformation that uses the custom name section to update index-based references to named references should not be destructive? i.e. remove That gets a 👍 from me! |
Yes, that's right, for example a ModuleExport would have an index and optionnally a name. We can then use the information we need depending on what we do. |
Agreed, this sounds like a great approach! @xtuc, yes, feel free to use any of my tests as you see fit. |
Description
Because of the
assertNotIdentifier
calls in wasm-gen/lib/encoder/index.js, editing, say, a module export name can throw with the default decode options.Steps to repro
Start with input WASM corresponding to the WAT
(from MDN's examples).
Then edit the export name like
This throws with "Unsupported node Identifier" due to the assertion at
If you instead decode with
ignoreCustomNameSection: true
then the edit succeeds:At the relevant assertion,
n.node.descr
now has type'NumberLiteral'
instead of'Identifier'
.Expected behavior
That valid edits succeed with default decode options. The current behavior feels restrictive.
Other Cases?
This behavior with export names seems to repro reliably across input .wasm files. I also found a possible repro with import names, but that one only affected some of the files I tested and might be due to a bug with
decode
. I'll file that separately.The text was updated successfully, but these errors were encountered: