Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Details of the JS API for exception handling #150

Closed
@takikawa

Description

@takikawa

Now that the semantics for the current iteration of the proposal are fairly solid and two browser implementations are underway, I was wondering if this is a good time to figure out the details for the JS API for exceptions.

@Ms2ger has written up draft JS API spec text which provides a good baseline to expand on. This draft was made during the previous iteration of the semantics, so it needs an update to remove exnref. But it already describes WebAssembly.Exception and WebAssembly.RuntimeException that are discussed below and additional API features can be incorporated into it.

Here are some of the aspects that the final JS API could/should likely provide, along with some design questions on how these aspects should work:

  • Provide an interface for exported exception types such as WebAssembly.Exception.
    • Previous discussions have generally assumed this should exist, and be called WA.Exception.
    • Should it support the type reflection API proposal? i.e., a type() method on exceptions.
    • Should it be possible to construct these in JS (given a function type or just a list of parameters from the type reflection API), to create a unique exception tag on the JS side? (which a Wasm module could import)
  • Provide an interface for Wasm exceptions caught in JS such as WebAssembly.RuntimeException.
    • A previous discussion reached a consensus to call this WebAssembly.RuntimeException and to keep it separate from WebAssembly.RuntimeError.
    • Should it allow access to exception values? (e.g., values() or getArg() method, using ToJSValue to coerce Wasm values to JS as usual)
    • If values are accessible, it should require a capability (i.e., the exception type export) to access. See this comment for why.
    • As discussed in the link in the previous bullet, should it have a method to let you check the tag against an exception type?
    • Should JS be allowed to construct these? (e.g., given an exception type, and values that would be coerced via ToWasmValue)

In terms of features, IMO it would make sense to allow accessing the values (requiring the exception type for access) and to allow constructing exception objects. Not adding this functionality won't actually prevent JS hosts from doing these operations (both limitations can be hacked around by constructing a new Wasm module) but adding it will make it more convenient.

There was some past discussion here and here on how/whether to allow constructing exception objects in JS, given the values to put in the exception. Ms2ger's draft assumes that the WA.RuntimeException constructor would also take a WA.Exception argument as well. IMO this would make sense to keep in the API in order to extract the tag out of the exception type. Not having this argument would make the constructor pretty useless, as without a tag such exceptions could only be caught by catch_all.

Are there any other aspects of the JS API that should also be discussed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions