Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AsyncContext #1369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ urlPrefix: https://tc39.es/ecma262/; spec: ecmascript
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: RESIZABLE-BUFFERS-PROPOSAL
type: abstract-op
text: IsResizableArrayBuffer; url: sec-isresizablearraybuffer
urlPrefix: https://tc39.es/proposal-async-context/; spec: ASYNC-CONTEXT-PROPOSAL
type: abstract-op
text: AsyncContextSnapshot; url: sec-asynccontextsnapshot
text: AsyncContextSwap; url: sec-asynccontextswap
type: dfn
text: async context mapping records; url: sec-asynccontext-mapping-record-specification-type
</pre>

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

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

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

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

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

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

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

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

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

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

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

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

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

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