Skip to content

Add a utility for handling modules embedded in JS - #9119

Open
tlively wants to merge 2 commits into
reduce-js-refactorfrom
reduce-js-parsing
Open

tlively wants to merge 2 commits into
reduce-js-refactorfrom
reduce-js-parsing

Conversation

@tlively

@tlively tlively commented Sep 18, 2026

Copy link
Copy Markdown
Member

Add a function that will search JS source for literal byte arrays that might contain Wasm modules. Handle skipping strings and comments, and handle signed and unsigned byte values in decimal, octal, and hex formats. Reject byte arrays that do not begin with the Wasm magic values, but do not otherwise verify that the bytes encode a well-formed or valid Wasm module.

Also add a function for printing a byte sequence as a JS byte array, formatted with 16 hex values per line.

A future PR will use these functions in wasm-reduce to reduce Wasm modules embedded in JS files.

Add a function that will search JS source for literal byte arrays that might contain Wasm modules. Handle skipping strings and comments, and handle signed and unsigned byte values in decimal, octal, and hex formats. Reject byte arrays that do not begin with the Wasm magic values, but do not otherwise verify that the bytes encode a well-formed or valid Wasm module.

Also add a function for printing a byte sequence as a JS byte array, formatted with 16 hex values per line.

A future PR will use these functions in wasm-reduce to reduce Wasm modules embedded in JS files.
@tlively
tlively requested a review from a team as a code owner September 18, 2026 22:57
@tlively
tlively requested review from kripken and removed request for a team September 18, 2026 22:57
@kripken

kripken commented Sep 18, 2026

Copy link
Copy Markdown
Member

@tlively

tlively commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

No. It would make sense to deduplicate the logic. I would be happy to replace those scripts with a small new wasm-embed tool with an --extract option, or an arrangement similar to that. I still think using those scripts (or other similar scripts) as the well-lit path for running wasm-reduce on modules embedded in JS would be too complicated for folks who might want to do such reductions frequently but are not Binaryen developers.

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.

2 participants