You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
urlPrefix: https://webassembly.github.io/reference-types/js-api/; spec: WebAssembly JS API (reference types); type: dfn
189
+
text: retrieving an extern value; url: #retrieving-an-extern-value
184
190
</pre>
185
191
186
192
<pre class='link-defaults'>
@@ -727,6 +733,8 @@ interface Table {
727
733
};
728
734
</pre>
729
735
736
+
Issue: Should we support putting [=exnref=] values in tables?
737
+
730
738
<div>
731
739
A {{Table}} object represents a single [=table instance=]
732
740
which can be simultaneously referenced by multiple {{Instance}} objects. Each
@@ -995,6 +1003,14 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
995
1003
1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |argsSeq|).
996
1004
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
997
1005
1. If |ret| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by <a href="#errors">the WebAssembly error mapping</a>.
1006
+
1. If |ret| is exception [=exnref=] |exception|,
1007
+
1. If |exception|'s [=exnref/exception tag=] is the [=JavaScript exception tag=], then
1008
+
1. Let [=ref.extern=] |externaddr| be |exception|'s [=exnref/payload=].
1009
+
1. Let |jsException| be the result of [=retrieving an extern value=] from |externaddr|.
1010
+
1. Throw |jsException|.
1011
+
1. Throw a {{RuntimeError}} exception.
1012
+
1013
+
Issue: Probably shouldn't be a {{RuntimeError}}.
998
1014
1. If |ret| is empty, return undefined.
999
1015
1. Otherwise, return [=ToJSValue=](|v|), where |v| is the singular element of |ret|.
1000
1016
</div>
@@ -1024,7 +1040,9 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1024
1040
1. Let |hostfunc| be a [=host function=] which performs the following steps when called with arguments |arguments|:
1025
1041
1. Let |result| be the result of [=run a host function|running a host function=] from |func|, |functype|, and |arguments|.
1026
1042
1. Assert: |result|.\[[Type]] is <emu-const>throw</emu-const> or <emu-const>return</emu-const>.
1027
-
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then trigger a WebAssembly trap, and propagate |result|.\[[Value]] to the enclosing JavaScript.
1043
+
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then:
1044
+
1. Let |exception| be [=ToWebAssemblyValue=](|result|.\[[Value]], [=anyref=]).
1045
+
1. [=WebAssembly/Throw=] |exception| with the [=JavaScript exception tag=].
1028
1046
1. Otherwise, return |result|.\[[Value]].
1029
1047
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1030
1048
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).
@@ -1096,6 +1114,32 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|, |error|) coerces a Java
1096
1114
</div>
1097
1115
1098
1116
1117
+
<h3 id="exceptions">Exceptions</h3>
1118
+
1119
+
A new type <dfn>exnref</dfn> is introduced for references to exceptions.
1120
+
Values of this type have an <dfn for=exnref>exception tag</dfn> and a <dfn for=exnref>payload</dfn>
1121
+
(whose type is dependent on the value of the [=exnref/exception tag=]).
1122
+
The concrete representation of values of this type is undefined.
1123
+
1124
+
The <dfn>JavaScript exception tag</dfn> is an [=exnref/exception tag=] reserved by this
1125
+
specification to distinguish exceptions originating from JavaScript.
1126
+
1127
+
Issue: Should it be possible for `br_on_exn` to extract the payload from an exception with this tag.
1128
+
1129
+
<div algorithm>
1130
+
1131
+
To <dfn for=WebAssembly>throw</dfn> a WebAssembly value |payload| given an [=exception tag=] |tag|,
1132
+
perform the following steps:
1133
+
1134
+
1. Let |exception| be a new [=exnref=] value with |payload| and |tag|.
1135
+
1. Unwind the stack until reaching the *catching try block*.
1136
+
1. Push |exception| onto the operand stack.
1137
+
1. Transfer control to the catch block.
1138
+
1139
+
Note: This algorithm is expected to be moved into the core specification.
1140
+
1141
+
</div>
1142
+
1099
1143
<h3 id="error-objects">Error Objects</h3>
1100
1144
1101
1145
WebAssembly defines the following Error classes: <dfn exception>CompileError</dfn>, <dfn exception>LinkError</dfn>, and <dfn exception>RuntimeError</dfn>.
0 commit comments