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

Commit 2a24576

Browse files
committed
[js-api] Add stack trace support.
1 parent 547e810 commit 2a24576

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

document/js-api/index.bs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,11 +1043,11 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
10431043
1. Note: The expectation is that [=func_invoke=] will be updated to return (|store|, <var ignore>val</var>* | [=error=] | (exception |exntag| |payload|)).
10441044
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
10451045
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>.
1046-
1. If |ret| is exception |exntag| |payload|, then
1046+
1. If |ret| is exception |exntag| |payload| |opaqueData|, then
10471047
1. If |exntag| is the [=JavaScript exception tag=], then
10481048
1. Let « [=ref.extern=] |externaddr| » be |payload|.
10491049
1. Throw the result of [=retrieving an extern value=] from |externaddr|.
1050-
1. Let |exception| be [=create an Exception object|a new Exception=] for |exntag| and |payload|.
1050+
1. Let |exception| be [=create an Exception object|a new Exception=] for |exntag|, |payload| and |opaqueData|.
10511051
1. Throw |exception|.
10521052
1. Let |outArity| be the [=list/size=] of |ret|.
10531053
1. If |outArity| is 0, return undefined.
@@ -1105,10 +1105,16 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
11051105
1. If |v| [=implements=] {{Exception}},
11061106
1. Let |type| be |v|.\[[Type]].
11071107
1. Let |payload| be |v|.\[[Payload]].
1108+
1. If |v|.\[[Stack]] is undefined,
1109+
1. Let |opaqueValue| be [=ref.null=] [=externref=].
1110+
1. Otherwise,
1111+
1. Assert: [=Type=](|v|.\[[Stack]]) is String.
1112+
1. Let |opaqueValue| be [=ToWebAssemblyValue=](|v|.\[[Stack]], [=externref=])
11081113
1. Otherwise,
11091114
1. Let |type| be the [=JavaScript exception tag=].
11101115
1. Let |payload| be [=ToWebAssemblyValue=](|v|, [=externref=]).
1111-
1. [=WebAssembly/Throw=] with |type| and |payload|.
1116+
1. Let |opaqueValue| be [=ref.null=] [=externref=].
1117+
1. [=WebAssembly/Throw=] with |type|, |payload| and |opaqueValue|.
11121118
1. Otherwise, return |result|.\[[Value]].
11131119
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
11141120
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).
@@ -1258,20 +1264,25 @@ Advisement: This method is only expected to be implemented or shipped when both
12581264
<h4 id="runtime-exceptions">Runtime exceptions</h4>
12591265

12601266
<pre class="idl">
1267+
dictionary ExceptionOptions {
1268+
boolean traceStack = false;
1269+
};
1270+
12611271
[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
12621272
interface Exception {
1263-
constructor(Tag exceptionTag, sequence&lt;any> payload);
1273+
constructor(Tag exceptionTag, sequence&lt;any> payload, optional ExceptionOptions options = {});
12641274
any getArg(Tag exceptionTag, unsigned long index);
12651275
boolean is(Tag exceptionTag);
1276+
readonly attribute (DOMString or undefined) stack;
12661277
};
12671278
</pre>
12681279

12691280
An {{Exception}} value represents an exception.
12701281

12711282
<div algorithm>
12721283

1273-
To <dfn>create an Exception object</dfn> from a [=tag address=] |tagAddress| and [=list=]
1274-
of WebAssembly values |payload|, perform the following steps:
1284+
To <dfn>create an Exception object</dfn> from a [=tag address=] |tagAddress|, [=list=] of
1285+
WebAssembly values |payload|, and [=externref=] |opaqueData|, perform the following steps:
12751286

12761287
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
12771288
1. Let |types| be [=tag_parameters=](|store|, |tagAddress|).
@@ -1281,14 +1292,20 @@ of WebAssembly values |payload|, perform the following steps:
12811292
1. Let |exception| be a [=new=] {{Exception}}.
12821293
1. Set |exception|.\[[Type]] to |tagAddress|.
12831294
1. Set |exception|.\[[Payload]] to |payload|.
1295+
1. If |opaqueData| is [=ref.null=] [=externref=],
1296+
1. Set |exception|.\[[Stack]] to undefined.
1297+
1. Otherwise,
1298+
1. Let |stack| be the result of [=retrieving an extern value=] from |opaqueData|.
1299+
1. Assert: [=Type=](|stack|) is String.
1300+
1. Set |exception|.\[[Stack]] to |stack|.
12841301
1. Return |exception|.
12851302

12861303
</div>
12871304

12881305
<div algorithm>
12891306

12901307
The <dfn constructor for=Exception
1291-
lt="Exception(exceptionTag, payload)">new Exception(|exceptionTag|, |payload|)</dfn>
1308+
lt="Exception(exceptionTag, payload, options)">new Exception(|exceptionTag|, |payload|, |options|)</dfn>
12921309
constructor steps are:
12931310

12941311
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
@@ -1300,6 +1317,10 @@ constructor steps are:
13001317
1. [=list/Append=] ? [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|.
13011318
1. Set **this**.\[[Type]] to |exceptionTag|.\[[Address]].
13021319
1. Set **this**.\[[Payload]] to |wasmPayload|.
1320+
1. If |options|["traceStack"] is true,
1321+
1. Set **this**.\[[Stack]] to either a {{DOMString}} representation of the current call stack or undefined.
1322+
1. Otherwise,
1323+
1. Set **this**.\[[Stack]] to undefined.
13031324

13041325
</div>
13051326

@@ -1326,6 +1347,14 @@ The <dfn method for="Exception">is(|exceptionTag|)</dfn> method steps are:
13261347

13271348
</div>
13281349

1350+
<div algorithm>
1351+
1352+
The <dfn attribute for="Exception">stack</dfn> getter steps are:
1353+
1354+
1. Return **this**.\[[Stack]].
1355+
1356+
</div>
1357+
13291358
<h4 id="js-exceptions">JavaScript exceptions</h4>
13301359

13311360
The <dfn>JavaScript exception tag</dfn> is a [=tag address=] reserved by this
@@ -1338,10 +1367,10 @@ For any [=associated store=] |store|, the result of
13381367

13391368
<div algorithm>
13401369

1341-
To <dfn for=WebAssembly>throw</dfn> with a [=tag address=] |type| and matching [=list=] of WebAssembly values |payload|, perform the following steps:
1370+
To <dfn for=WebAssembly>throw</dfn> with a [=tag address=] |type|, a matching [=list=] of WebAssembly values |payload|, and an [=externref=] |opaqueData|, perform the following steps:
13421371

13431372
1. Unwind the stack until reaching the *catching try block* given |type|.
1344-
1. Invoke the catch block with |payload|.
1373+
1. Invoke the catch block with |payload| and |opaqueData|.
13451374

13461375
Note: This algorithm is expected to be moved into the core specification.
13471376

0 commit comments

Comments
 (0)