ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 59

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     57      58      59     

 

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 59

 

 

6.  Suspend 

methodContext

.

7.  Set 

generator

.[[GeneratorState]] to 

executing

.

8.  Push 

genContext

 onto the 

execution context stack

genContext

 is now the 

running execution context

.

9.  Resume the suspended evaluation of 

genContext

 using 

NormalCompletion

(

value

) as the result of the operation

that suspended it. Let 

result

 be the value returned by the resumed computation.

10. 

Assert

: When we return here, 

genContext

 has already been removed from the 

execution context stack

 and

methodContext

 is the currently 

running execution context

.

11.  Return 

Completion

(

result

).

The abstract operation GeneratorResumeAbrupt takes arguments 

generator

abruptCompletion

 (a 

Completion Record

whose [[Type]] is 

return

 or 

throw

), and 

generatorBrand

. It performs the following steps when called:

1.  Let 

state

 be ? 

GeneratorValidate

(

generator

generatorBrand

).

2.  If 

state

 is 

suspendedStart

, then

a.  Set 

generator

.[[GeneratorState]] to 

completed

.

b.  Once a generator enters the 

completed

 state it never leaves it and its associated 

execution context

 is

never resumed. Any execution state associated with 

generator

 can be discarded at this point.

c.  Set 

state

 to 

completed

.

3.  If 

state

 is 

completed

, then

a.  If 

abruptCompletion

.[[Type]] is 

return

, then

i.  Return 

CreateIterResultObject

(

abruptCompletion

.[[Value]], 

true

).

b.  Return 

Completion

(

abruptCompletion

).

4. 

Assert

state

 is 

suspendedYield

.

5.  Let 

genContext

 be 

generator

.[[GeneratorContext]].

6.  Let 

methodContext

 be the 

running execution context

.

7.  Suspend 

methodContext

.

8.  Set 

generator

.[[GeneratorState]] to 

executing

.

9.  Push 

genContext

 onto the 

execution context stack

genContext

 is now the 

running execution context

.

10.  Resume the suspended evaluation of 

genContext

 using 

abruptCompletion

 as the result of the operation that

suspended it. Let 

result

 be the completion record returned by the resumed computation.

11. 

Assert

: When we return here, 

genContext

 has already been removed from the 

execution context stack

 and

methodContext

 is the currently 

running execution context

.

12.  Return 

Completion

(

result

).

The abstract operation GetGeneratorKind takes no arguments. It performs the following steps when called:

1.  Let 

genContext

 be the 

running execution context

.

2.  If 

genContext

 does not have a Generator component, return 

non-generator

.

3.  Let 

generator

 be the Generator component of 

genContext

.

4.  If 

generator

 has an [[AsyncGeneratorState]] internal slot, return 

async

.

5.  Else, return 

sync

.

27.5.3.4  GeneratorResumeAbrupt ( 

generator

abruptCompletion

generatorBrand

 )

27.5.3.5  GetGeneratorKind ( )

27.5.3.6  GeneratorYield ( 

iterNextObj

 )

784

The abstract operation GeneratorYield takes argument 

iterNextObj

. It performs the following steps when called:

1. 

Assert

iterNextObj

 is an Object that implements the 

IteratorResult

 interface.

2.  Let 

genContext

 be the 

running execution context

.

3. 

Assert

genContext

 is the 

execution context

 of a generator.

4.  Let 

generator

 be the value of the Generator component of 

genContext

.

5. 

Assert

GetGeneratorKind

() is 

sync

.

6.  Set 

generator

.[[GeneratorState]] to 

suspendedYield

.

7.  Remove 

genContext

 from the 

execution context stack

 and restore the 

execution context

 that is at the top of the

execution context stack

 as the 

running execution context

.

8.  Set the code evaluation state of 

genContext

 such that when evaluation is resumed with a 

Completion

resumptionValue

 the following steps will be performed:

a.  Return 

resumptionValue

.

b.  NOTE: This returns to the evaluation of the 

YieldExpression

 that originally called this abstract operation.

9.  Return 

NormalCompletion

(

iterNextObj

).

10.  NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of

genContext

.

The abstract operation Yield takes argument 

value

 (an 

ECMAScript language value

). It performs the following steps

when called:

1.  Let 

generatorKind

 be ! 

GetGeneratorKind

().

2.  If 

generatorKind

 is 

async

, return ? 

AsyncGeneratorYield

(

value

).

3.  Otherwise, return ? 

GeneratorYield

(! 

CreateIterResultObject

(

value

false

)).

The abstract operation CreateIteratorFromClosure takes arguments 

closure

 (an 

Abstract Closure

 with no parameters),

generatorBrand

, and 

generatorPrototype

 (an Object). It performs the following steps when called:

1.  NOTE: 

closure

 can contain uses of the 

Yield

 shorthand to yield an IteratorResult object.

2.  Let 

internalSlotsList

 be « [[GeneratorState]], [[GeneratorContext]], [[GeneratorBrand]] ».

3.  Let 

generator

 be ! 

OrdinaryObjectCreate

(

generatorPrototype

internalSlotsList

).

4.  Set 

generator

.[[GeneratorBrand]] to 

generatorBrand

.

5.  Set 

generator

.[[GeneratorState]] to 

undefined

.

6.  Perform ! 

GeneratorStart

(

generator

closure

).

7.  Return 

generator

.

An AsyncGenerator object is an instance of an async generator function and conforms to both the AsyncIterator and
AsyncIterable interfaces.

AsyncGenerator instances directly inherit properties from the object that is the initial value of the 

"prototype"

property of the AsyncGenerator function that created the instance. AsyncGenerator instances indirectly inherit
properties from the AsyncGenerator Prototype intrinsic, 

%AsyncGeneratorFunction.prototype.prototype%

.

27.5.3.7  Yield ( 

value

 )

27.5.3.8  CreateIteratorFromClosure ( 

closure

generatorBrand

generatorPrototype

 )

27.6  AsyncGenerator Objects

785

The 

AsyncGenerator prototype object

:

is 

%AsyncGeneratorFunction.prototype.prototype%

.

is an 

ordinary object

.

is not an AsyncGenerator instance and does not have an [[AsyncGeneratorState]] internal slot.
has a [[Prototype]] internal slot whose value is 

%AsyncIteratorPrototype%

.

has properties that are indirectly inherited by all AsyncGenerator instances.

The initial value of 

AsyncGenerator.prototype.constructor

AsyncGenerator.prototype.constructor

 is 

%AsyncGeneratorFunction.prototype%

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

1.  Let 

generator

 be the 

this

 value.

2.  Let 

completion

 be 

NormalCompletion

(

value

).

3.  Return ! 

AsyncGeneratorEnqueue

(

generator

completion

empty

).

1.  Let 

generator

 be the 

this

 value.

2.  Let 

completion

 be 

Completion

 { [[Type]]: 

return

, [[Value]]: 

value

, [[Target]]: 

empty

 }.

3.  Return ! 

AsyncGeneratorEnqueue

(

generator

completion

empty

).

1.  Let 

generator

 be the 

this

 value.

2.  Let 

completion

 be 

ThrowCompletion

(

exception

).

3.  Return ! 

AsyncGeneratorEnqueue

(

generator

completion

empty

).

The initial value of the 

@@toStringTag

 property is the String value 

"AsyncGenerator"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

AsyncGenerator instances are initially created with the internal slots described below:

27.6.1  Properties of the AsyncGenerator Prototype Object

27.6.1.1  AsyncGenerator.prototype.constructor

27.6.1.2  AsyncGenerator.prototype.next ( 

value

 )

27.6.1.3  AsyncGenerator.prototype.return ( 

value

 )

27.6.1.4  AsyncGenerator.prototype.throw ( 

exception

 )

27.6.1.5  AsyncGenerator.prototype [ @@toStringTag ]

27.6.2  Properties of AsyncGenerator Instances

786

Table 74: Internal Slots of AsyncGenerator Instances

Internal Slot

Description

[[AsyncGeneratorState]]

The current execution state of the async generator. The possible values are: 

undefined

,

suspendedStart

suspendedYield

executing

awaiting-return

, and 

completed

.

[[AsyncGeneratorContext]] The 

execution context

 that is used when executing the code of this async generator.

[[AsyncGeneratorQueue]]

List

 of AsyncGeneratorRequest records which represent requests to resume the

async generator.

[[GeneratorBrand]]

A brand used to distinguish different kinds of async generators. The
[[GeneratorBrand]] of async generators declared by ECMAScript source text is always

empty

.

The AsyncGeneratorRequest is a 

Record

 value used to store information about how an async generator should be

resumed and contains capabilities for fulfilling or rejecting the corresponding promise.

They have the following fields:

Table 75: AsyncGeneratorRequest 

Record

 Fields

Field Name

Value

Meaning

[[Completion]] A 

Completion

 record

The completion which should be used to resume the async
generator.

[[Capability]]

PromiseCapability

Record

The promise capabilities associated with this request.

The abstract operation AsyncGeneratorStart takes arguments 

generator

 and 

generatorBody

 (a 

Parse Node

 or an 

Abstract

Closure

 with no parameters). It performs the following steps when called:

1. 

Assert

generator

 is an AsyncGenerator instance.

2. 

Assert

generator

.[[AsyncGeneratorState]] is 

undefined

.

3.  Let 

genContext

 be the 

running execution context

.

4.  Set the Generator component of 

genContext

 to 

generator

.

5.  Set the code evaluation state of 

genContext

 such that when evaluation is resumed for that 

execution context

 the

following steps will be performed:

a.  If 

generatorBody

 is a 

Parse Node

, then

i.  Let 

result

 be the result of evaluating 

generatorBody

.

b.  Else,

i. 

Assert

generatorBody

 is an 

Abstract Closure

 with no parameters.

27.6.3  AsyncGenerator Abstract Operations

27.6.3.1  AsyncGeneratorRequest Records

27.6.3.2  AsyncGeneratorStart ( 

generator

generatorBody

 )

787

ii.  Let 

result

 be 

generatorBody

().

c. 

Assert

: If we return here, the async generator either threw an exception or performed either an implicit

or explicit return.

d.  Remove 

genContext

 from the 

execution context stack

 and restore the 

execution context

 that is at the top

of the 

execution context stack

 as the 

running execution context

.

e.  Set 

generator

.[[AsyncGeneratorState]] to 

completed

.

f.  If 

result

 is a normal completion, let 

resultValue

 be 

undefined

.

g.  Else,

i.  Let 

resultValue

 be 

result

.[[Value]].

ii.  If 

result

.[[Type]] is not 

return

, then

1.  Return ! 

AsyncGeneratorReject

(

generator

resultValue

).

h.  Return ! 

AsyncGeneratorResolve

(

generator

resultValue

true

).

6.  Set 

generator

.[[AsyncGeneratorContext]] to 

genContext

.

7.  Set 

generator

.[[AsyncGeneratorState]] to 

suspendedStart

.

8.  Set 

generator

.[[AsyncGeneratorQueue]] to a new empty 

List

.

9.  Return 

undefined

.

The abstract operation AsyncGeneratorValidate takes arguments 

generator

 and 

generatorBrand

. It performs the

following steps when called:

1.  Perform ? 

RequireInternalSlot

(

generator

, [[AsyncGeneratorContext]]).

2.  Perform ? 

RequireInternalSlot

(

generator

, [[AsyncGeneratorState]]).

3.  Perform ? 

RequireInternalSlot

(

generator

, [[AsyncGeneratorQueue]]).

4.  If 

generator

.[[GeneratorBrand]] is not the same value as 

generatorBrand

, throw a 

TypeError

 exception.

The abstract operation AsyncGeneratorResolve takes arguments 

generator

value

, and 

done

 (a Boolean). It performs the

following steps when called:

1. 

Assert

generator

 is an AsyncGenerator instance.

2.  Let 

queue

 be 

generator

.[[AsyncGeneratorQueue]].

3. 

Assert

queue

 is not an empty 

List

.

4.  Let 

next

 be the first element of 

queue

.

5.  Remove the first element from 

queue

.

6.  Let 

promiseCapability

 be 

next

.[[Capability]].

7.  Let 

iteratorResult

 be ! 

CreateIterResultObject

(

value

done

).

8.  Perform ! 

Call

(

promiseCapability

.[[Resolve]], 

undefined

, « 

iteratorResult

 »).

9.  Perform ! 

AsyncGeneratorResumeNext

(

generator

).

10.  Return 

undefined

.

The abstract operation AsyncGeneratorReject takes arguments 

generator

 and 

exception

. It performs the following steps

when called:

1. 

Assert

generator

 is an AsyncGenerator instance.

27.6.3.3  AsyncGeneratorValidate ( 

generator

generatorBrand

 )

27.6.3.4  AsyncGeneratorResolve ( 

generator

value

done

 )

27.6.3.5  AsyncGeneratorReject ( 

generator

exception

 )

788

2.  Let 

queue

 be 

generator

.[[AsyncGeneratorQueue]].

3. 

Assert

queue

 is not an empty 

List

.

4.  Let 

next

 be the first element of 

queue

.

5.  Remove the first element from 

queue

.

6.  Let 

promiseCapability

 be 

next

.[[Capability]].

7.  Perform ! 

Call

(

promiseCapability

.[[Reject]], 

undefined

, « 

exception

 »).

8.  Perform ! 

AsyncGeneratorResumeNext

(

generator

).

9.  Return 

undefined

.

The abstract operation AsyncGeneratorResumeNext takes argument 

generator

. It performs the following steps when

called:

1. 

Assert

generator

 is an AsyncGenerator instance.

2.  Let 

state

 be 

generator

.[[AsyncGeneratorState]].

3. 

Assert

state

 is not 

executing

.

4.  If 

state

 is 

awaiting-return

, return 

undefined

.

5.  Let 

queue

 be 

generator

.[[AsyncGeneratorQueue]].

6.  If 

queue

 is an empty 

List

, return 

undefined

.

7.  Let 

next

 be the value of the first element of 

queue

.

8. 

Assert

next

 is an AsyncGeneratorRequest record.

9.  Let 

completion

 be 

next

.[[Completion]].

10.  If 

completion

 is an 

abrupt completion

, then

a.  If 

state

 is 

suspendedStart

, then

i.  Set 

generator

.[[AsyncGeneratorState]] to 

completed

.

ii.  Set 

state

 to 

completed

.

b.  If 

state

 is 

completed

, then

i.  If 

completion

.[[Type]] is 

return

, then

1.  Set 

generator

.[[AsyncGeneratorState]] to 

awaiting-return

.

2.  Let 

promise

 be ? 

PromiseResolve

(

%Promise%

completion

.[[Value]]).

3.  Let 

stepsFulfilled

 be the algorithm steps defined in 

AsyncGeneratorResumeNext Return

Processor Fulfilled Functions

.

4.  Let 

lengthFulfilled

 be the number of non-optional parameters of the function definition in

AsyncGeneratorResumeNext Return Processor Fulfilled Functions

.

5.  Let 

onFulfilled

 be ! 

CreateBuiltinFunction

(

stepsFulfilled

lengthFulfilled

""

, « [[Generator]] »).

6.  Set 

onFulfilled

.[[Generator]] to 

generator

.

7.  Let 

stepsRejected

 be the algorithm steps defined in 

AsyncGeneratorResumeNext Return

Processor Rejected Functions

.

8.  Let 

lengthRejected

 be the number of non-optional parameters of the function definition in

AsyncGeneratorResumeNext Return Processor Rejected Functions

.

9.  Let 

onRejected

 be ! 

CreateBuiltinFunction

(

stepsRejected

lengthRejected

""

, « [[Generator]] »).

10.  Set 

onRejected

.[[Generator]] to 

generator

.

11.  Perform ! 

PerformPromiseThen

(

promise

onFulfilled

onRejected

).

12.  Return 

undefined

.

ii.  Else,

1. 

Assert

completion

.[[Type]] is 

throw

.

2.  Perform ! 

AsyncGeneratorReject

(

generator

completion

.[[Value]]).

27.6.3.6  AsyncGeneratorResumeNext ( 

generator

 )

789

3.  Return 

undefined

.

11.  Else if 

state

 is 

completed

, return ! 

AsyncGeneratorResolve

(

generator

undefined

true

).

12. 

Assert

state

 is either 

suspendedStart

 or 

suspendedYield

.

13.  Let 

genContext

 be 

generator

.[[AsyncGeneratorContext]].

14.  Let 

callerContext

 be the 

running execution context

.

15.  Suspend 

callerContext

.

16.  Set 

generator

.[[AsyncGeneratorState]] to 

executing

.

17.  Push 

genContext

 onto the 

execution context stack

genContext

 is now the 

running execution context

.

18.  Resume the suspended evaluation of 

genContext

 using 

completion

 as the result of the operation that suspended

it. Let 

result

 be the completion record returned by the resumed computation.

19. 

Assert

result

 is never an 

abrupt completion

.

20. 

Assert

: When we return here, 

genContext

 has already been removed from the 

execution context stack

 and

callerContext

 is the currently 

running execution context

.

21.  Return 

undefined

.

An 

AsyncGeneratorResumeNext

 return processor fulfilled function is an anonymous built-in function that is used as

part of the 

AsyncGeneratorResumeNext

 specification device to unwrap promises passed in to the

AsyncGenerator.prototype.return ( 

value

 )

 method. Each 

AsyncGeneratorResumeNext

 return processor fulfilled

function has a [[Generator]] internal slot.

When an 

AsyncGeneratorResumeNext

 return processor fulfilled function is called with argument 

value

, the following

steps are taken:

1.  Let 

F

 be the 

active function object

.

2.  Set 

F

.[[Generator]].[[AsyncGeneratorState]] to 

completed

.

3.  Return ! 

AsyncGeneratorResolve

(

F

.[[Generator]], 

value

true

).

The 

"length"

 property of an 

AsyncGeneratorResumeNext

 return processor fulfilled function is 

1

𝔽

.

An 

AsyncGeneratorResumeNext

 return processor rejected function is an anonymous built-in function that is used as

part of the 

AsyncGeneratorResumeNext

 specification device to unwrap promises passed in to the

AsyncGenerator.prototype.return ( 

value

 )

 method. Each 

AsyncGeneratorResumeNext

 return processor rejected

function has a [[Generator]] internal slot.

When an 

AsyncGeneratorResumeNext

 return processor rejected function is called with argument 

reason

, the following

steps are taken:

1.  Let 

F

 be the 

active function object

.

2.  Set 

F

.[[Generator]].[[AsyncGeneratorState]] to 

completed

.

3.  Return ! 

AsyncGeneratorReject

(

F

.[[Generator]], 

reason

).

The 

"length"

 property of an 

AsyncGeneratorResumeNext

 return processor rejected function is 

1

𝔽

.

The abstract operation AsyncGeneratorEnqueue takes arguments 

generator

completion

 (a 

Completion Record

), and

27.6.3.6.1  AsyncGeneratorResumeNext Return Processor Fulfilled Functions

27.6.3.6.2  AsyncGeneratorResumeNext Return Processor Rejected Functions

27.6.3.7  AsyncGeneratorEnqueue ( 

generator

completion

generatorBrand

 )

790

generatorBrand

. It performs the following steps when called:

1.  Let 

promiseCapability

 be ! 

NewPromiseCapability

(

%Promise%

).

2.  Let 

check

 be 

AsyncGeneratorValidate

(

generator

generatorBrand

).

3.  If 

check

 is an 

abrupt completion

, then

a.  Let 

badGeneratorError

 be a newly created 

TypeError

 object.

b.  Perform ! 

Call

(

promiseCapability

.[[Reject]], 

undefined

, « 

badGeneratorError

 »).

c.  Return 

promiseCapability

.[[Promise]].

4.  Let 

queue

 be 

generator

.[[AsyncGeneratorQueue]].

5.  Let 

request

 be AsyncGeneratorRequest { [[Completion]]: 

completion

, [[Capability]]: 

promiseCapability

 }.

6.  Append 

request

 to the end of 

queue

.

7.  Let 

state

 be 

generator

.[[AsyncGeneratorState]].

8.  If 

state

 is not 

executing

, then

a.  Perform ! 

AsyncGeneratorResumeNext

(

generator

).

9.  Return 

promiseCapability

.[[Promise]].

The abstract operation AsyncGeneratorYield takes argument 

value

. It performs the following steps when called:

1.  Let 

genContext

 be the 

running execution context

.

2. 

Assert

genContext

 is the 

execution context

 of a generator.

3.  Let 

generator

 be the value of the Generator component of 

genContext

.

4. 

Assert

GetGeneratorKind

() is 

async

.

5.  Set 

value

 to ? 

Await

(

value

).

6.  Set 

generator

.[[AsyncGeneratorState]] to 

suspendedYield

.

7.  Remove 

genContext

 from the 

execution context stack

 and restore the 

execution context

 that is at the top of the

execution context stack

 as the 

running execution context

.

8.  Set the code evaluation state of 

genContext

 such that when evaluation is resumed with a 

Completion

resumptionValue

 the following steps will be performed:

a.  If 

resumptionValue

.[[Type]] is not 

return

, return 

Completion

(

resumptionValue

).

b.  Let 

awaited

 be 

Await

(

resumptionValue

.[[Value]]).

c.  If 

awaited

.[[Type]] is 

throw

, return 

Completion

(

awaited

).

d. 

Assert

awaited

.[[Type]] is 

normal

.

e.  Return 

Completion

 { [[Type]]: 

return

, [[Value]]: 

awaited

.[[Value]], [[Target]]: 

empty

 }.

f.  NOTE: When one of the above steps returns, it returns to the evaluation of the 

YieldExpression

production that originally called this abstract operation.

9.  Return ! 

AsyncGeneratorResolve

(

generator

value

false

).

10.  NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of

genContext

.

The abstract operation CreateAsyncIteratorFromClosure takes arguments 

closure

 (an 

Abstract Closure

 with no

parameters), 

generatorBrand

, and 

generatorPrototype

 (an Object). It performs the following steps when called:

1.  NOTE: 

closure

 can contain uses of the 

Await

 shorthand and uses of the 

Yield

 shorthand to yield an

IteratorResult object.

2.  Let 

internalSlotsList

 be « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]],

27.6.3.8  AsyncGeneratorYield ( 

value

 )

27.6.3.9  CreateAsyncIteratorFromClosure ( 

closure

generatorBrand

generatorPrototype

 )

791

[[GeneratorBrand]] ».

3.  Let 

generator

 be ! 

OrdinaryObjectCreate

(

generatorPrototype

internalSlotsList

).

4.  Set 

generator

.[[GeneratorBrand]] to 

generatorBrand

.

5.  Set 

generator

.[[AsyncGeneratorState]] to 

undefined

.

6.  Perform ! 

AsyncGeneratorStart

(

generator

closure

).

7.  Return 

generator

.

AsyncFunction objects are functions that are usually created by evaluating 

AsyncFunctionDeclaration

s, 

AsyncFunctionExpression

s, 

AsyncMethod

s, and 

AsyncArrowFunction

s. They may also be created by calling the

%AsyncFunction%

 intrinsic.

The AsyncFunction 

constructor

:

is 

%AsyncFunction%

.

is a subclass of 

Function

Function

.

creates and initializes a new AsyncFunction object when called as a function rather than as a 

constructor

. Thus

the function call 

AsyncFunction(…)

AsyncFunction(…)

 is equivalent to the object creation expression

new AsyncFunction(…)

new AsyncFunction(…)

 with the same arguments.

is designed to be subclassable. It may be used as the value of an 

extends

extends

 clause of a class definition. Subclass

constructors that intend to inherit the specified AsyncFunction behaviour must include a 

super

super

 call to the

AsyncFunction 

constructor

 to create and initialize a subclass instance with the internal slots necessary for built-

in async function behaviour. All ECMAScript syntactic forms for defining async function objects create direct
instances of AsyncFunction. There is no syntactic means to create instances of AsyncFunction subclasses.

The last argument specifies the body (executable code) of an async function. Any preceding arguments specify formal
parameters.

When the 

AsyncFunction

AsyncFunction

 function is called with some arguments 

p1

p2

, … , 

pn

body

 (where 

n

 might be 0, that is,

there are no 

p

 arguments, and where 

body

 might also not be provided), the following steps are taken:

1.  Let 

C

 be the 

active function object

.

2.  Let 

args

 be the 

argumentsList

 that was passed to this function by [[Call]] or [[Construct]].

3.  Return 

CreateDynamicFunction

(

C

, NewTarget, 

async

args

).

NOTE

The AsyncFunction 

constructor

:

is a standard built-in 

function object

 that inherits from the Function 

constructor

.

See NOTE for 

20.2.1.1

.

27.7  AsyncFunction Objects

27.7.1  The AsyncFunction Constructor

27.7.1.1  AsyncFunction ( 

p1

p2

, … , 

pn

body

 )

27.7.2  Properties of the AsyncFunction Constructor

792

has a [[Prototype]] internal slot whose value is 

%Function%

.

has a 

"name"

 property whose value is 

"AsyncFunction"

.

has the following properties:

This is a 

data property

 with a value of 1. This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

,

[[Configurable]]: 

true

 }.

The initial value of 

AsyncFunction.prototype

AsyncFunction.prototype

 is the 

AsyncFunction prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The 

AsyncFunction prototype object

:

is 

%AsyncFunction.prototype%

.

is an 

ordinary object

.

is not a 

function object

 and does not have an [[ECMAScriptCode]] internal slot or any other of the internal slots

listed in 

Table 29

.

has a [[Prototype]] internal slot whose value is 

%Function.prototype%

.

The initial value of 

AsyncFunction.prototype.constructor

AsyncFunction.prototype.constructor

 is 

%AsyncFunction%

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

The initial value of the 

@@toStringTag

 property is the String value 

"AsyncFunction"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

Every AsyncFunction instance is an ECMAScript 

function object

 and has the internal slots listed in 

Table 29

. The value

of the [[IsClassConstructor]] internal slot for all such instances is 

false

. AsyncFunction instances are not constructors

and do not have a [[Construct]] internal method. AsyncFunction instances do not have a prototype property as they
are not constructible.

Each AsyncFunction instance has the following own properties:

The specification for the 

"length"

 property of Function instances given in 

20.2.4.1

 also applies to AsyncFunction

27.7.2.1  AsyncFunction.length

27.7.2.2  AsyncFunction.prototype

27.7.3  Properties of the AsyncFunction Prototype Object

27.7.3.1  AsyncFunction.prototype.constructor

27.7.3.2  AsyncFunction.prototype [ @@toStringTag ]

27.7.4  AsyncFunction Instances

27.7.4.1  length

793

instances.

The specification for the 

"name"

 property of Function instances given in 

20.2.4.2

 also applies to AsyncFunction

instances.

The abstract operation AsyncFunctionStart takes arguments 

promiseCapability

 (a 

PromiseCapability Record

) and

asyncFunctionBody

. It performs the following steps when called:

1.  Let 

runningContext

 be the 

running execution context

.

2.  Let 

asyncContext

 be a copy of 

runningContext

.

3.  NOTE: Copying the execution state is required for the step below to resume its execution. It is ill-defined to

resume a currently executing context.

4.  Set the code evaluation state of 

asyncContext

 such that when evaluation is resumed for that 

execution context

the following steps will be performed:

a.  Let 

result

 be the result of evaluating 

asyncFunctionBody

.

b. 

Assert

: If we return here, the async function either threw an exception or performed an implicit or

explicit return; all awaiting is done.

c.  Remove 

asyncContext

 from the 

execution context stack

 and restore the 

execution context

 that is at the top

of the 

execution context stack

 as the 

running execution context

.

d.  If 

result

.[[Type]] is 

normal

, then

i.  Perform ! 

Call

(

promiseCapability

.[[Resolve]], 

undefined

, « 

undefined

 »).

e.  Else if 

result

.[[Type]] is 

return

, then

i.  Perform ! 

Call

(

promiseCapability

.[[Resolve]], 

undefined

, « 

result

.[[Value]] »).

f.  Else,

i. 

Assert

result

.[[Type]] is 

throw

.

ii.  Perform ! 

Call

(

promiseCapability

.[[Reject]], 

undefined

, « 

result

.[[Value]] »).

g.  Return.

5.  Push 

asyncContext

 onto the 

execution context stack

asyncContext

 is now the 

running execution context

.

6.  Resume the suspended evaluation of 

asyncContext

. Let 

result

 be the value returned by the resumed

computation.

7. 

Assert

: When we return here, 

asyncContext

 has already been removed from the 

execution context stack

 and

runningContext

 is the currently 

running execution context

.

8. 

Assert

result

 is a normal completion with a value of 

undefined

. The possible sources of completion values are

Await

 or, if the async function doesn't await anything, step 

4.g

 above.

9.  Return.

27.7.4.2  name

27.7.5  Async Functions Abstract Operations

27.7.5.1  AsyncFunctionStart ( 

promiseCapability

asyncFunctionBody

 )

28  Reflection

794

The Reflect object:

is 

%Reflect%

.

is the initial value of the 

"Reflect"

 property of the 

global object

.

is an 

ordinary object

.

has a [[Prototype]] internal slot whose value is 

%Object.prototype%

.

is not a 

function object

.

does not have a [[Construct]] internal method; it cannot be used as a 

constructor

 with the 

new

new

 operator.

does not have a [[Call]] internal method; it cannot be invoked as a function.

When the 

apply

apply

 function is called with arguments 

target

thisArgument

, and 

argumentsList

, the following steps are

taken:

1.  If 

IsCallable

(

target

) is 

false

, throw a 

TypeError

 exception.

2.  Let 

args

 be ? 

CreateListFromArrayLike

(

argumentsList

).

3.  Perform 

PrepareForTailCall

().

4.  Return ? 

Call

(

target

thisArgument

args

).

When the 

construct

construct

 function is called with arguments 

target

argumentsList

, and 

newTarget

, the following steps are

taken:

1.  If 

IsConstructor

(

target

) is 

false

, throw a 

TypeError

 exception.

2.  If 

newTarget

 is not present, set 

newTarget

 to 

target

.

3.  Else if 

IsConstructor

(

newTarget

) is 

false

, throw a 

TypeError

 exception.

4.  Let 

args

 be ? 

CreateListFromArrayLike

(

argumentsList

).

5.  Return ? 

Construct

(

target

args

newTarget

).

When the 

defineProperty

defineProperty

 function is called with arguments 

target

propertyKey

, and 

attributes

, the following

steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Let 

key

 be ? 

ToPropertyKey

(

propertyKey

).

3.  Let 

desc

 be ? 

ToPropertyDescriptor

(

attributes

).

4.  Return ? 

target

.[[DefineOwnProperty]](

key

desc

).

When the 

deleteProperty

deleteProperty

 function is called with arguments 

target

 and 

propertyKey

, the following steps are

taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

28.1  The Reflect Object

28.1.1  Reflect.apply ( 

target

thisArgument

argumentsList

 )

28.1.2  Reflect.construct ( 

target

argumentsList

 [ , 

newTarget

 ] )

28.1.3  Reflect.defineProperty ( 

target

propertyKey

attributes

 )

28.1.4  Reflect.deleteProperty ( 

target

propertyKey

 )

795

2.  Let 

key

 be ? 

ToPropertyKey

(

propertyKey

).

3.  Return ? 

target

.[[Delete]](

key

).

When the 

get

get

 function is called with arguments 

target

propertyKey

, and 

receiver

, the following steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Let 

key

 be ? 

ToPropertyKey

(

propertyKey

).

3.  If 

receiver

 is not present, then

a.  Set 

receiver

 to 

target

.

4.  Return ? 

target

.[[Get]](

key

receiver

).

When the 

getOwnPropertyDescriptor

getOwnPropertyDescriptor

 function is called with arguments 

target

 and 

propertyKey

, the following

steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Let 

key

 be ? 

ToPropertyKey

(

propertyKey

).

3.  Let 

desc

 be ? 

target

.[[GetOwnProperty]](

key

).

4.  Return 

FromPropertyDescriptor

(

desc

).

When the 

getPrototypeOf

getPrototypeOf

 function is called with argument 

target

, the following steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Return ? 

target

.[[GetPrototypeOf]]().

When the 

has

has

 function is called with arguments 

target

 and 

propertyKey

, the following steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Let 

key

 be ? 

ToPropertyKey

(

propertyKey

).

3.  Return ? 

target

.[[HasProperty]](

key

).

When the 

isExtensible

isExtensible

 function is called with argument 

target

, the following steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Return ? 

target

.[[IsExtensible]]().

When the 

ownKeys

ownKeys

 function is called with argument 

target

, the following steps are taken:

28.1.5  Reflect.get ( 

target

propertyKey

 [ , 

receiver

 ] )

28.1.6  Reflect.getOwnPropertyDescriptor ( 

target

propertyKey

 )

28.1.7  Reflect.getPrototypeOf ( 

target

 )

28.1.8  Reflect.has ( 

target

propertyKey

 )

28.1.9  Reflect.isExtensible ( 

target

 )

28.1.10  Reflect.ownKeys ( 

target

 )

796

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Let 

keys

 be ? 

target

.[[OwnPropertyKeys]]().

3.  Return 

CreateArrayFromList

(

keys

).

When the 

preventExtensions

preventExtensions

 function is called with argument 

target

, the following steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Return ? 

target

.[[PreventExtensions]]().

When the 

set

set

 function is called with arguments 

target

V

propertyKey

, and 

receiver

, the following steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  Let 

key

 be ? 

ToPropertyKey

(

propertyKey

).

3.  If 

receiver

 is not present, then

a.  Set 

receiver

 to 

target

.

4.  Return ? 

target

.[[Set]](

key

V

receiver

).

When the 

setPrototypeOf

setPrototypeOf

 function is called with arguments 

target

 and 

proto

, the following steps are taken:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  If 

Type

(

proto

) is not Object and 

proto

 is not 

null

, throw a 

TypeError

 exception.

3.  Return ? 

target

.[[SetPrototypeOf]](

proto

).

The initial value of the 

@@toStringTag

 property is the String value 

"Reflect"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

The Proxy 

constructor

:

is 

%Proxy%

.

is the initial value of the 

"Proxy"

 property of the 

global object

.

creates and initializes a new 

Proxy exotic object

 when called as a 

constructor

.

is not intended to be called as a function and will throw an exception when called in that manner.

28.1.11  Reflect.preventExtensions ( 

target

 )

28.1.12  Reflect.set ( 

target

propertyKey

V

 [ , 

receiver

 ] )

28.1.13  Reflect.setPrototypeOf ( 

target

proto

 )

28.1.14  Reflect [ @@toStringTag ]

28.2  Proxy Objects

28.2.1  The Proxy Constructor

28.2.1.1  Proxy ( 

target

handler

 )

797

 

 

 

 

 

 

 

Content      ..     57      58      59