Skip to content

Commit d399b9e

Browse files
authored
Expose the JavaScript Exception tag and allow importing it (#269)
As discussed in #202 The JS tag was added to the JS API spec in #301, but it is not observable. This change exposes it on the WebAssembly namespace, allowing it to be imported into wasm modules. This allows wasm modules to explicitly extract the thrown JS objects as externrefs from the caught exrefs, and also to throw fresh exceptions with externref payloads that will propagate into JS and can be caught as bare JS objects not wrapped in a WebAssembly.Exception. It also places the restriction that WebAssembly.Exception objects cannot be created with the JS tag, because it would result in ambiguity or asymmetry when such objects unwind from JS into wasm and back out.
1 parent c97651f commit d399b9e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Diff for: document/js-api/index.bs

+10
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ namespace WebAssembly {
267267

268268
Promise<Instance> instantiate(
269269
Module moduleObject, optional object importObject);
270+
271+
readonly attribute Tag JSTag;
270272
};
271273
</pre>
272274

@@ -505,6 +507,11 @@ The verification of WebAssembly type requirements is deferred to the
505507

506508
Note: A follow-on streaming API is documented in the <a href="https://webassembly.github.io/spec/web-api/index.html">WebAssembly Web API</a>.
507509

510+
The getter of the <dfn attribute for="WebAssembly">JSTag</dfn> attribute of the {{WebAssembly}} Namespace, when invoked, performs the following steps:
511+
1. Let |JSTagAddr| be the result of [=get the JavaScript exception tag|getting the JavaScript exception tag=].
512+
1. Let |JSTagObject| be the result of [=create a Tag object|creating a Tag object=] from |JSTagAddr|.
513+
1. Return |JSTagObject|.
514+
508515
<h3 id="modules">Modules</h3>
509516

510517
<pre class="idl">
@@ -1306,6 +1313,9 @@ The <dfn constructor for=Exception
13061313
lt="Exception(exceptionTag, payload, options)">new Exception(|exceptionTag|, |payload|, |options|)</dfn>
13071314
constructor steps are:
13081315

1316+
1. Let |JSTagAddr| be the result of [=get the JavaScript exception tag|getting the JavaScript exception tag=].
1317+
1. If |exceptionTag|.\[[Address]] is equal to |JSTagAddr|,
1318+
1. Throw a {{TypeError}}.
13091319
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
13101320
1. Let [|types|] → [] be [=tag_type=](|store|, |exceptionTag|.\[[Address]]).
13111321
1. If |types|'s [=list/size=] is not |payload|'s [=list/size=],

0 commit comments

Comments
 (0)