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

Commit 059df76

Browse files
authored
[js-api] Add description of interface additions to overview document (#154)
1 parent 7159387 commit 059df76

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

proposals/exception-handling/Exceptions.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,38 @@ specially mark non-catchable exceptions.
341341
be intercepted in JS, and types of exceptions generated from stack overflow and
342342
out of memory are implementation-defined.)
343343

344+
#### API additions
345+
346+
The following additional classes are added to the JS API in order to allow JavaScript to interact with WebAssembly exceptions:
347+
348+
* `WebAssembly.Tag`
349+
* `WebAssembly.Exception`.
350+
351+
The `WebAssembly.Tag` class represents a typed tag defined in the tag section and exported from a WebAssembly module. It allows querying the type of a tag following the [JS type reflection proposal](https://github.com/WebAssembly/js-types/blob/master/proposals/js-types/Overview.md). Constructing an instance of `Tag` creates a fresh tag, and the new tag can be passed to a WebAssembly module as a tag import.
352+
353+
In the future, `WebAssembly.Tag` may be used for other proposals that require a typed tag and its constructor may be extended to accept other types and/or a tag attribute to differentiate them from tags used for exceptions.
354+
355+
The `WebAssembly.Exception` class represents an exception thrown from WebAssembly, or an exception that is constructed in JavaScript and is to be thrown to a WebAssembly exception handler. The `Exception` constructor accepts a `Tag` argument and a sequence of arguments for the exception's data fields. The `Tag` argument determines the exception tag to use. The data field arguments must match the types specified by the `Tag`'s type. The `is` method can be used to query if the `Exception` matches a given tag. The `getArg` method allows access to the data fields of a `Exception` if a matching tag is given. This last check ensures that without access to a WebAssembly module's exported exception tag, the associated data fields cannot be read.
356+
357+
More formally, the added interfaces look like the following:
358+
359+
```WebIDL
360+
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
361+
interface Tag {
362+
constructor(TagType type);
363+
TagType type();
364+
};
365+
366+
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
367+
interface Exception {
368+
constructor(Tag tag, sequence<any> payload);
369+
any getArg(Tag tag, unsigned long index);
370+
boolean is(Tag tag);
371+
};
372+
```
373+
374+
Where `type TagType = {parameters: ValueType[]}`, following the format of the type reflection proposal (`TagType` corresponds to a `FunctionType` without a `results` property). `TagType` could be extended in the future for other proposals that require a richer type specification.
375+
344376
## Changes to the text format
345377

346378
This section describes change in the [instruction syntax

0 commit comments

Comments
 (0)