[JS API] Throw useful exceptions on parse errors#8264
Open
kripken wants to merge 2 commits intoWebAssembly:mainfrom
Open
[JS API] Throw useful exceptions on parse errors#8264kripken wants to merge 2 commits intoWebAssembly:mainfrom
kripken wants to merge 2 commits intoWebAssembly:mainfrom
Conversation
spotandjake
approved these changes
Feb 5, 2026
Contributor
spotandjake
left a comment
There was a problem hiding this comment.
This looks great to me.
| @@ -3264,7 +3285,7 @@ Object.defineProperty(Module, 'readBinary', { writable: true }); | |||
| Module['readBinary'] = function(data) { | |||
Contributor
There was a problem hiding this comment.
Just a nit but with #8122 I started trying to add some documentation with jsdoc how would we feel about continuing that pattern when possible?
Suggested change
| Module['readBinary'] = function(data) { | |
| /** | |
| * Creates a module from binary data. | |
| * | |
| * @param {Uint8Array} data - A Uint8Array containing a valid WebAssembly binary. | |
| * | |
| * @return {Module} The constructed wasm module. | |
| * | |
| * @throws {Error} If the input is invalid or parsing fails. | |
| */ | |
| Module['readBinary'] = function(data) { |
Member
There was a problem hiding this comment.
Is this to autogenerate some doc? The comment here seems kind of obvious.
| @@ -3273,7 +3294,7 @@ Module['readBinary'] = function(data) { | |||
| Module['parseText'] = function(text) { | |||
Contributor
There was a problem hiding this comment.
Same as above:
Suggested change
| Module['parseText'] = function(text) { | |
| /** | |
| * Creates a module from Binaryen's s-expression text format (not official stack-style text format). | |
| * | |
| * @param {string} text - A string containing a WebAssembly text module (Binaryen-style WAT). | |
| * | |
| * @return {Module} The constructed wasm module. | |
| * | |
| * @throws {Error} If the input is invalid or parsing fails. | |
| */ | |
| Module['parseText'] = function(text) { |
Member
|
Emscripten supports printing exception messages when run with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
wasm-opt will just fatally error on invalid module inputs, but binaryen.js
is a library and users want to get something they can handle, and see
the actual error. This PR throws a C++ exception instead, and converts
it on the JS side.
Fixes #8256