Skip to content

Could WebAssembly.validate optionally provide a diagnostic? #1000

Open
@bnjbvr

Description

@bnjbvr

At the moment, WebAssembly.validate only returns a simple boolean answer, which is enough for feature detection. It might be useful to also get an error message and an indication where the error is. Currently, the only way to get a meaningful error message is to create a Module and catch the error, as done in the test harness.

The proposal is the following: we might have a second argument to WebAssembly.validate, which would be a function callback onError. Whenever we hit an error in the binary code passed to validate, the onError callback would be called with an object containing the following properties:

  • an absolute offset into the module binary, which would be a Number.
  • a String error message describing what is going wrong.

Another possibility is that the onError callback be just called with a string that contains the offset, but that is harder to programmatically handle, which might be useful for e.g. wasm Web IDEs. Devtools may also use the offset to create a link to the corresponding wasm text format (or source map) around the offset.

Going the opposite direction, we could also have an extended object with more properties describing the error, including error codes. Each error code would be documented and could have specific information in supplementary object properties. For instance, there could be one error code describing a type mismatch when consuming arguments to an opcode; additional error-code specific properties in the object could be expected (an array of types that were expected on the top of the stack) and observed (an array of the types present on the top of the stack).

As this would be a facultative argument, the diagnostic string wouldn't get generated if the argument is not provided, making this feature "pay-as-you-go", which is nice for implementations.

Having a callback per WebAssembly.validate call is a bit clumsy, since the onError callback would be probably stable across calls. Another option would be to have a global property WebAssembly.validate.onerror (the same way we have window.onerror), defaulting to null, enabling diagnostic string generation for all the validated modules iff it's set to a function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions