Skip to content

Commit 8a2e35c

Browse files
Ms2gerbathos
andcommitted
Add support for AsyncContext
Co-authored-by: Darien Maillet Valentine <[email protected]>
1 parent 10e559d commit 8a2e35c

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

index.bs

+45-19
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ urlPrefix: https://tc39.es/ecma262/; spec: ecmascript
7272
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: RESIZABLE-BUFFERS-PROPOSAL
7373
type: abstract-op
7474
text: IsResizableArrayBuffer; url: sec-isresizablearraybuffer
75+
urlPrefix: https://tc39.es/proposal-async-context/; spec: ASYNC-CONTEXT-PROPOSAL
76+
type: abstract-op
77+
text: AsyncContextSnapshot; url: sec-asynccontextsnapshot
78+
text: AsyncContextSwap; url: sec-asynccontextswap
79+
type: dfn
80+
text: async context mapping records; url: sec-asynccontext-mapping-record-specification-type
7581
</pre>
7682

7783
<style>
@@ -6013,8 +6019,9 @@ about the execution context at the time the language binding specific object ref
60136019
converted to an IDL value.
60146020

60156021
Note: For ECMAScript objects, the [=callback context=] is used to hold a reference to the
6016-
<a spec="HTML">incumbent settings object</a> at the time the Object value is converted to an IDL
6017-
callback interface type value. See [[#es-callback-interface]].
6022+
<a spec="HTML">incumbent settings object</a> and the [=list=] of [=Async Context Mapping Records=]
6023+
at the time the Object value is converted to an IDL callback interface type value.
6024+
See [[#es-callback-interface]].
60186025

60196026
There is no way to represent a constant object reference value for a particular
60206027
[=callback interface type=] in IDL.
@@ -6061,10 +6068,10 @@ the [=callback function=], the values can be references to objects that are not
60616068
An IDL value of the callback function type is represented by a tuple of an object
60626069
reference and a [=callback context=].
60636070

6064-
Note: As with [=callback interface types=], the [=callback context=] is used to hold a
6065-
reference to the <a spec="HTML">incumbent settings object</a> at
6066-
the time an ECMAScript Object value is converted to an IDL
6067-
callback function type value. See [[#es-callback-function]].
6071+
Note: As with [=callback interface types=], the [=callback context=] is used to hold a reference to
6072+
the <a spec="HTML">incumbent settings object</a> and the [=list=] of [=Async Context Mapping
6073+
Records=] at the time the Object value is converted to an IDL callback function type value.
6074+
See [[#es-callback-function]].
60686075

60696076
There is no way to represent a constant [=callback function=]
60706077
value in IDL.
@@ -7671,8 +7678,10 @@ values are represented by ECMAScript Object values (including [=function objects
76717678
to an IDL [=callback interface type=] value by running the following algorithm:
76727679

76737680
1. If <a abstract-op>Type</a>(|V|) is not Object, then [=ECMAScript/throw=] a <l spec=ecmascript>{{TypeError}}</l>.
7681+
1. Let |incumbent| be the <a spec="HTML">incumbent settings object</a>.
7682+
1. Let |context| be [$AsyncContextSnapshot$]().
76747683
1. Return the IDL [=callback interface type=] value that represents a reference to |V|, with
7675-
the <a spec="HTML">incumbent settings object</a> as the [=callback context=].
7684+
(|incumbent|, |context|) as the [=callback context=].
76767685
</div>
76777686

76787687
<p id="callback-interface-to-es">
@@ -7792,9 +7801,11 @@ IDL [=callback function types=] are represented by ECMAScript [=function objects
77927801
[=callback function=]
77937802
that is annotated with [{{LegacyTreatNonObjectAsNull}}],
77947803
then [=ECMAScript/throw=] a <l spec=ecmascript>{{TypeError}}</l>.
7804+
1. Let |incumbent| be the <a spec="HTML">incumbent settings object</a>.
7805+
1. Let |context| be [$AsyncContextSnapshot$]().
77957806
1. Return the IDL [=callback function type=] value
7796-
that represents a reference to the same object that |V| represents, with the
7797-
<a spec="HTML">incumbent settings object</a> as the [=callback context=].
7807+
that represents a reference to the same object that |V| represents, with
7808+
(|incumbent|, |context|) as the [=callback context=].
77987809
</div>
77997810

78007811
<p id="callback-function-to-es">
@@ -14149,17 +14160,20 @@ the special value “missing”, which represents a missing optional argument.
1414914160

1415014161
To <dfn id="call-a-user-objects-operation" export>call a user object's operation</dfn>,
1415114162
given a [=callback interface type=] value |value|,
14152-
operation name |opName|, [=Web IDL arguments list=] |args|, and optional
14153-
<dfn id="dfn-callback-this-value" export>callback this value</dfn> |thisArg|,
14154-
perform the following steps.
14163+
operation name |opName|, [=Web IDL arguments list=] |args|, optional
14164+
<dfn id="dfn-callback-this-value" export>callback this value</dfn> |thisArg|, and
14165+
an optional [=boolean=] |useCreationTimeAsyncContext|, perform the following steps.
1415514166
These steps will either return an IDL value or throw an exception.
1415614167

14168+
1. If |useCreationTimeAsyncContext| was not given, let |useCreationTimeAsyncContext| be false.
1415714169
1. Let |completion| be an uninitialized variable.
1415814170
1. If |thisArg| was not given, let |thisArg| be <emu-val>undefined</emu-val>.
1415914171
1. Let |O| be the ECMAScript object corresponding to |value|.
1416014172
1. Let |realm| be |O|'s [=associated realm=].
1416114173
1. Let |relevant settings| be |realm|'s [=realm/settings object=].
14162-
1. Let |stored settings| be |value|'s [=callback context=].
14174+
1. Let (|stored settings|, |async context mapping|) be |value|'s [=callback context=].
14175+
1. If |useCreationTimeAsyncContext| is true, then:
14176+
1. Let |previous async context mapping| be [$AsyncContextSwap$](|async context mapping|).
1416314177
1. [=Prepare to run script=] with |relevant settings|.
1416414178
1. [=Prepare to run a callback=] with |stored settings|.
1416514179
1. Let |X| be |O|.
@@ -14188,6 +14202,8 @@ the special value “missing”, which represents a missing optional argument.
1418814202
point |completion| will be set to an IDL value or an [=abrupt completion=].
1418914203
1. [=Clean up after running a callback=] with |stored settings|.
1419014204
1. [=Clean up after running script=] with |relevant settings|.
14205+
1. If |useCreationTimeAsyncContext| is true, then:
14206+
1. [$AsyncContextSwap$](|previous async context mapping|).
1419114207
1. If |completion| is an IDL value, return |completion|.
1419214208
1. If |completion| is an [=abrupt completion=] and the operation has a [=return type=]
1419314209
that is <em>not</em> a [=promise type=], throw |completion|.\[[Value]].
@@ -14245,12 +14261,13 @@ described in the previous section).
1424514261

1424614262
To <dfn id="invoke-a-callback-function" export>invoke</dfn> a
1424714263
[=callback function type=] value |callable| with a [=Web IDL arguments list=] |args|
14248-
and an optional [=callback this value|callback this value=] |thisArg|,
14249-
perform the following steps.
14264+
and an optional [=callback this value|callback this value=] |thisArg|, and
14265+
an optional [=boolean=] |useCreationTimeAsyncContext|, perform the following steps.
1425014266
These steps will either return an IDL value or throw an exception.
1425114267

1425214268
1. Let |completion| be an uninitialized variable.
1425314269
1. If |thisArg| was not given, let |thisArg| be <emu-val>undefined</emu-val>.
14270+
1. If |useCreationTimeAsyncContext| was not given, let |useCreationTimeAsyncContext| be false.
1425414271
1. Let |F| be the ECMAScript object corresponding to |callable|.
1425514272
1. If <a abstract-op>IsCallable</a>(|F|) is <emu-val>false</emu-val>:
1425614273
1. Note: This is only possible when the [=callback function=] came from an attribute
@@ -14259,7 +14276,9 @@ described in the previous section).
1425914276
<emu-val>undefined</emu-val> to the callback function's return type.
1426014277
1. Let |realm| be |F|'s [=associated realm=].
1426114278
1. Let |relevant settings| be |realm|'s [=realm/settings object=].
14262-
1. Let |stored settings| be |callable|'s [=callback context=].
14279+
1. Let (|stored settings|, |async context mapping|) be |callable|'s [=callback context=].
14280+
1. If |useCreationTimeAsyncContext| is true, then:
14281+
1. Let |previous async context mapping| be [$AsyncContextSwap$](|async context mapping|).
1426314282
1. [=Prepare to run script=] with |relevant settings|.
1426414283
1. [=Prepare to run a callback=] with |stored settings|.
1426514284
1. Let |esArgs| be the result of [=Web IDL arguments list/converting=] |args| to an ECMAScript
@@ -14277,6 +14296,8 @@ described in the previous section).
1427714296
point |completion| will be set to an IDL value or an [=abrupt completion=].
1427814297
1. [=Clean up after running a callback=] with |stored settings|.
1427914298
1. [=Clean up after running script=] with |relevant settings|.
14299+
1. If |useCreationTimeAsyncContext| is true, then:
14300+
1. [$AsyncContextSwap$](|previous async context mapping|).
1428014301
1. If |completion| is an IDL value, return |completion|.
1428114302
1. If |completion| is an [=abrupt completion=] and the callback function has a
1428214303
[=return type=] that is <em>not</em> a [=promise type=], throw |completion|.\[[Value]].
@@ -14292,17 +14313,20 @@ a return type that is a [=promise type=].
1429214313
<div algorithm>
1429314314

1429414315
To <dfn id="construct-a-callback-function" export>construct</dfn> a
14295-
[=callback function type=] value |callable| with a [=Web IDL arguments list=] |args|,
14296-
perform the following steps.
14316+
[=callback function type=] value |callable| with a [=Web IDL arguments list=] |args|, and
14317+
an optional [=boolean=] |useCreationTimeAsyncContext|, perform the following steps.
1429714318
These steps will either return an IDL value or throw an exception.
1429814319

14320+
1. If |useCreationTimeAsyncContext| was not given, let |useCreationTimeAsyncContext| be false.
1429914321
1. Let |completion| be an uninitialized variable.
1430014322
1. Let |F| be the ECMAScript object corresponding to |callable|.
1430114323
1. If <a abstract-op>IsConstructor</a>(|F|) is <emu-val>false</emu-val>, throw a
1430214324
<l spec=ecmascript>{{TypeError}}</l> exception.
1430314325
1. Let |realm| be |F|'s [=associated realm=].
1430414326
1. Let |relevant settings| be |realm|'s [=realm/settings object=].
14305-
1. Let |stored settings| be |callable|'s [=callback context=].
14327+
1. Let (|stored settings|, |async context mapping|) be |callable|'s [=callback context=].
14328+
1. If |useCreationTimeAsyncContext| is true, then:
14329+
1. Let |previous async context mapping| be [$AsyncContextSwap$](|async context mapping|).
1430614330
1. [=Prepare to run script=] with |relevant settings|.
1430714331
1. [=Prepare to run a callback=] with |stored settings|.
1430814332
1. Let |esArgs| be the result of [=Web IDL arguments list/converting=] |args| to an ECMAScript
@@ -14320,6 +14344,8 @@ a return type that is a [=promise type=].
1432014344
point |completion| will be set to an IDL value or an [=abrupt completion=].
1432114345
1. [=Clean up after running a callback=] with |stored settings|.
1432214346
1. [=Clean up after running script=] with |relevant settings|.
14347+
1. If |useCreationTimeAsyncContext| is true, then:
14348+
1. [$AsyncContextSwap$](|previous async context mapping|).
1432314349
1. If |completion| is an [=abrupt completion=], throw |completion|.\[[Value]].
1432414350
1. Return |completion|.
1432514351
</div>

0 commit comments

Comments
 (0)