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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     19      20      21      22     ..

 

 

 

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

 

 

The abstract operation OrdinarySet takes arguments 

O

 (an Object), 

P

 (a property key), 

V

 (an 

ECMAScript language

value

), and 

Receiver

 (an 

ECMAScript language value

). It performs the following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

ownDesc

 be ? 

O

.[[GetOwnProperty]](

P

).

3.  Return 

OrdinarySetWithOwnDescriptor

(

O

P

V

Receiver

ownDesc

).

The abstract operation OrdinarySetWithOwnDescriptor takes arguments 

O

 (an Object), 

P

 (a property key), 

V

 (an

ECMAScript language value

), 

Receiver

 (an 

ECMAScript language value

), and 

ownDesc

 (a 

Property Descriptor

 or

undefined

). It performs the following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  If 

ownDesc

 is 

undefined

, then

a.  Let 

parent

 be ? 

O

.[[GetPrototypeOf]]().

b.  If 

parent

 is not 

null

, then

i.  Return ? 

parent

.[[Set]](

P

V

Receiver

).

c.  Else,

i.  Set 

ownDesc

 to the PropertyDescriptor { [[Value]]: 

undefined

, [[Writable]]: 

true

, [[Enumerable]]:

true

, [[Configurable]]: 

true

 }.

3.  If 

IsDataDescriptor

(

ownDesc

) is 

true

, then

a.  If 

ownDesc

.[[Writable]] is 

false

, return 

false

.

b.  If 

Type

(

Receiver

) is not Object, return 

false

.

c.  Let 

existingDescriptor

 be ? 

Receiver

.[[GetOwnProperty]](

P

).

d.  If 

existingDescriptor

 is not 

undefined

, then

i.  If 

IsAccessorDescriptor

(

existingDescriptor

) is 

true

, return 

false

.

ii.  If 

existingDescriptor

.[[Writable]] is 

false

, return 

false

.

iii.  Let 

valueDesc

 be the PropertyDescriptor { [[Value]]: 

V

 }.

iv.  Return ? 

Receiver

.[[DefineOwnProperty]](

P

valueDesc

).

e.  Else,

i. 

Assert

Receiver

 does not currently have a property 

P

.

ii.  Return ? 

CreateDataProperty

(

Receiver

P

V

).

4. 

Assert

IsAccessorDescriptor

(

ownDesc

) is 

true

.

5.  Let 

setter

 be 

ownDesc

.[[Set]].

6.  If 

setter

 is 

undefined

, return 

false

.

7.  Perform ? 

Call

(

setter

Receiver

, « 

V

 »).

8.  Return 

true

.

The [[Delete]] internal method of an 

ordinary object

 

O

 takes argument 

P

 (a property key). It performs the following

steps when called:

1.  Return ? 

OrdinaryDelete

(

O

P

).

10.1.9.1  OrdinarySet ( 

O

P

V

Receiver

 )

10.1.9.2  OrdinarySetWithOwnDescriptor ( 

O

P

V

Receiver

ownDesc

 )

10.1.10  [[Delete]] ( 

P

 )

10.1.10.1  OrdinaryDelete ( 

O

P

 )

227

The abstract operation OrdinaryDelete takes arguments 

O

 (an Object) and 

P

 (a property key). It performs the

following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

desc

 be ? 

O

.[[GetOwnProperty]](

P

).

3.  If 

desc

 is 

undefined

, return 

true

.

4.  If 

desc

.[[Configurable]] is 

true

, then

a.  Remove the own property with name 

P

 from 

O

.

b.  Return 

true

.

5.  Return 

false

.

The [[OwnPropertyKeys]] internal method of an 

ordinary object

 

O

 takes no arguments. It performs the following

steps when called:

1.  Return ! 

OrdinaryOwnPropertyKeys

(

O

).

The abstract operation OrdinaryOwnPropertyKeys takes argument 

O

 (an Object). It performs the following steps

when called:

1.  Let 

keys

 be a new empty 

List

.

2.  For each own property key 

P

 of 

O

 such that 

P

 is an 

array index

, in ascending numeric index order, do

a.  Add 

P

 as the last element of 

keys

.

3.  For each own property key 

P

 of 

O

 such that 

Type

(

P

) is String and 

P

 is not an 

array index

, in ascending

chronological order of property creation, do

a.  Add 

P

 as the last element of 

keys

.

4.  For each own property key 

P

 of 

O

 such that 

Type

(

P

) is Symbol, in ascending chronological order of property

creation, do

a.  Add 

P

 as the last element of 

keys

.

5.  Return 

keys

.

The abstract operation OrdinaryObjectCreate takes argument 

proto

 (an Object or 

null

) and optional argument

additionalInternalSlotsList

 (a 

List

 of names of internal slots). It is used to specify the runtime creation of new ordinary

objects. 

additionalInternalSlotsList

 contains the names of additional internal slots that must be defined as part of the

object, beyond [[Prototype]] and [[Extensible]]. If 

additionalInternalSlotsList

 is not provided, a new empty 

List

 is used.

It performs the following steps when called:

1.  Let 

internalSlotsList

 be « [[Prototype]], [[Extensible]] ».

2.  If 

additionalInternalSlotsList

 is present, append each of its elements to 

internalSlotsList

.

3.  Let 

O

 be ! 

MakeBasicObject

(

internalSlotsList

).

4.  Set 

O

.[[Prototype]] to 

proto

.

5.  Return 

O

.

10.1.11  [[OwnPropertyKeys]] ( )

10.1.11.1  OrdinaryOwnPropertyKeys ( 

O

 )

10.1.12  OrdinaryObjectCreate ( 

proto

 [ , 

additionalInternalSlotsList

 ] )

228

NOTE

The abstract operation OrdinaryCreateFromConstructor takes arguments 

constructor

 and 

intrinsicDefaultProto

 and

optional argument 

internalSlotsList

 (a 

List

 of names of internal slots). It creates an 

ordinary object

 whose [[Prototype]]

value is retrieved from a 

constructor

's 

"prototype"

 property, if it exists. Otherwise the intrinsic named by

intrinsicDefaultProto

 is used for [[Prototype]]. 

internalSlotsList

 contains the names of additional internal slots that must

be defined as part of the object. If 

internalSlotsList

 is not provided, a new empty 

List

 is used. It performs the following

steps when called:

1. 

Assert

intrinsicDefaultProto

 is a String value that is this specification's name of an intrinsic object. The

corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.

2.  Let 

proto

 be ? 

GetPrototypeFromConstructor

(

constructor

intrinsicDefaultProto

).

3.  Return ! 

OrdinaryObjectCreate

(

proto

internalSlotsList

).

The abstract operation GetPrototypeFromConstructor takes arguments 

constructor

 and 

intrinsicDefaultProto

. It

determines the [[Prototype]] value that should be used to create an object corresponding to a specific 

constructor

. The

value is retrieved from the 

constructor

's 

"prototype"

 property, if it exists. Otherwise the intrinsic named by

intrinsicDefaultProto

 is used for [[Prototype]]. It performs the following steps when called:

1. 

Assert

intrinsicDefaultProto

 is a String value that is this specification's name of an intrinsic object. The

corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.

2. 

Assert

IsCallable

(

constructor

) is 

true

.

3.  Let 

proto

 be ? 

Get

(

constructor

"prototype"

).

4.  If 

Type

(

proto

) is not Object, then

a.  Let 

realm

 be ? 

GetFunctionRealm

(

constructor

).

b.  Set 

proto

 to 

realm

's intrinsic object named 

intrinsicDefaultProto

.

5.  Return 

proto

.

NOTE

The abstract operation RequireInternalSlot takes arguments 

O

 and 

internalSlot

. It throws an exception unless 

O

 is an

Object and has the given internal slot. It performs the following steps when called:

1.  If 

Type

(

O

) is not Object, throw a 

TypeError

 exception.

2.  If 

O

 does not have an 

internalSlot

 internal slot, throw a 

TypeError

 exception.

Although OrdinaryObjectCreate does little more than call 

MakeBasicObject

, its use

communicates the intention to create an 

ordinary object

, and not an exotic one. Thus, within this

specification, it is not called by any algorithm that subsequently modifies the internal methods of
the object in ways that would make the result non-ordinary. Operations that create exotic objects
invoke 

MakeBasicObject

 directly.

If 

constructor

 does not supply a [[Prototype]] value, the default value that is used is obtained from

the 

realm

 of the 

constructor

 function rather than from the 

running execution context

.

10.1.13  OrdinaryCreateFromConstructor ( 

constructor

intrinsicDefaultProto

 [ ,

internalSlotsList

 ] )

10.1.14  GetPrototypeFromConstructor ( 

constructor

intrinsicDefaultProto

 )

10.1.15  RequireInternalSlot ( 

O

internalSlot

 )

229

ECMAScript function objects encapsulate parameterized ECMAScript code closed over a lexical environment and
support the dynamic evaluation of that code. An ECMAScript 

function object

 is an 

ordinary object

 and has the same

internal slots and the same internal methods as other ordinary objects. The code of an ECMAScript 

function object

may be either 

strict mode code

 (

11.2.2

) or 

non-strict code

. An ECMAScript 

function object

 whose code is 

strict mode

code

 is called a 

strict function

. One whose code is not 

strict mode code

 is called a 

non-strict function

.

In addition to [[Extensible]] and [[Prototype]], ECMAScript function objects also have the internal slots listed in 

Table

29

.

Table 29: Internal Slots of ECMAScript Function Objects

Internal Slot

Type

Description

[[Environment]]

Environment
Record

The 

Environment Record

 that the function was closed over. Used as the

outer environment when evaluating the code of the function.

[[FormalParameters]]

Parse Node

The root parse node of the source text that defines the function's formal
parameter list.

[[ECMAScriptCode]]

Parse Node

The root parse node of the source text that defines the function's body.

[[ConstructorKind]]

base

 |

derived

Whether or not the function is a derived class 

constructor

.

[[Realm]]

Realm
Record

The 

realm

 in which the function was created and which provides any

intrinsic objects that are accessed when evaluating the function.

[[ScriptOrModule]]

Script
Record

 or

Module
Record

The script or module in which the function was created.

[[ThisMode]]

lexical

 |

strict

 |

global

Defines how 

this

this

 references are interpreted within the formal parameters

and code body of the function. 

lexical

 means that 

this

this

 refers to the 

this

value of a lexically enclosing function. 

strict

 means that the 

this

 value is used

exactly as provided by an invocation of the function. 

global

 means that a 

this

value of 

undefined

 or 

null

 is interpreted as a reference to the 

global object

,

and any other 

this

 value is first passed to 

ToObject

.

[[Strict]]

Boolean

true

 if this is a 

strict function

false

 if this is a 

non-strict function

.

[[HomeObject]]

Object

If the function uses 

super

super

, this is the object whose [[GetPrototypeOf]]

provides the object where 

super

super

 property lookups begin.

[[SourceText]]

sequence of
Unicode
code points

The 

source text

 that defines the function.

[[IsClassConstructor]] Boolean

Indicates whether the function is a class 

constructor

. (If 

true

, invoking the

function's [[Call]] will immediately throw a 

TypeError

 exception.)

10.2  ECMAScript Function Objects

230

All ECMAScript function objects have the [[Call]] internal method defined here. ECMAScript functions that are also
constructors in addition have the [[Construct]] internal method.

The [[Call]] internal method of an ECMAScript 

function object

 

F

 takes arguments 

thisArgument

 (an 

ECMAScript

language value

) and 

argumentsList

 (a 

List

 of ECMAScript language values). It performs the following steps when

called:

1. 

Assert

F

 is an ECMAScript 

function object

.

2.  Let 

callerContext

 be the 

running execution context

.

3.  Let 

calleeContext

 be 

PrepareForOrdinaryCall

(

F

undefined

).

4. 

Assert

calleeContext

 is now the 

running execution context

.

5.  If 

F

.[[IsClassConstructor]] is 

true

, then

a.  Let 

error

 be a newly created 

TypeError

 object.

b.  NOTE: 

error

 is created in 

calleeContext

 with 

F

's associated 

Realm Record

.

c.  Remove 

calleeContext

 from the 

execution context stack

 and restore 

callerContext

 as the 

running execution

context

.

d.  Return 

ThrowCompletion

(

error

).

6.  Perform 

OrdinaryCallBindThis

(

F

calleeContext

thisArgument

).

7.  Let 

result

 be 

OrdinaryCallEvaluateBody

(

F

argumentsList

).

8.  Remove 

calleeContext

 from the 

execution context stack

 and restore 

callerContext

 as the 

running execution

context

.

9.  If 

result

.[[Type]] is 

return

, return 

NormalCompletion

(

result

.[[Value]]).

10. 

ReturnIfAbrupt

(

result

).

11.  Return 

NormalCompletion

(

undefined

).

NOTE

The abstract operation PrepareForOrdinaryCall takes arguments 

F

 (a 

function object

) and 

newTarget

 (an 

ECMAScript

language value

). It performs the following steps when called:

1. 

Assert

Type

(

newTarget

) is Undefined or Object.

2.  Let 

callerContext

 be the 

running execution context

.

3.  Let 

calleeContext

 be a new ECMAScript code 

execution context

.

4.  Set the Function of 

calleeContext

 to 

F

.

5.  Let 

calleeRealm

 be 

F

.[[Realm]].

6.  Set the 

Realm

 of 

calleeContext

 to 

calleeRealm

.

7.  Set the ScriptOrModule of 

calleeContext

 to 

F

.[[ScriptOrModule]].

8.  Let 

localEnv

 be 

NewFunctionEnvironment

(

F

newTarget

).

9.  Set the LexicalEnvironment of 

calleeContext

 to 

localEnv

.

10.  Set the VariableEnvironment of 

calleeContext

 to 

localEnv

.

11.  If 

callerContext

 is not already suspended, suspend 

callerContext

.

12.  Push 

calleeContext

 onto the 

execution context stack

calleeContext

 is now the 

running execution context

.

13.  NOTE: Any exception objects produced after this point are associated with 

calleeRealm

.

When 

calleeContext

 is removed from the 

execution context stack

 in step 

8

 it must not be destroyed

if it is suspended and retained for later resumption by an accessible generator object.

10.2.1  [[Call]] ( 

thisArgument

argumentsList

 )

10.2.1.1  PrepareForOrdinaryCall ( 

F

newTarget

 )

231

14.  Return 

calleeContext

.

The abstract operation OrdinaryCallBindThis takes arguments 

F

 (a 

function object

), 

calleeContext

 (an 

execution

context

), and 

thisArgument

 (an 

ECMAScript language value

). It performs the following steps when called:

1.  Let 

thisMode

 be 

F

.[[ThisMode]].

2.  If 

thisMode

 is 

lexical

, return 

NormalCompletion

(

undefined

).

3.  Let 

calleeRealm

 be 

F

.[[Realm]].

4.  Let 

localEnv

 be the LexicalEnvironment of 

calleeContext

.

5.  If 

thisMode

 is 

strict

, let 

thisValue

 be 

thisArgument

.

6.  Else,

a.  If 

thisArgument

 is 

undefined

 or 

null

, then

i.  Let 

globalEnv

 be 

calleeRealm

.[[GlobalEnv]].

ii. 

Assert

globalEnv

 is a 

global Environment Record

.

iii.  Let 

thisValue

 be 

globalEnv

.[[GlobalThisValue]].

b.  Else,

i.  Let 

thisValue

 be ! 

ToObject

(

thisArgument

).

ii.  NOTE: 

ToObject

 produces wrapper objects using 

calleeRealm

.

7. 

Assert

localEnv

 is a 

function Environment Record

.

8. 

Assert

: The next step never returns an 

abrupt completion

 because 

localEnv

.[[ThisBindingStatus]] is not

initialized

.

9.  Return 

localEnv

.BindThisValue(

thisValue

).

With parameters 

functionObject

 and 

argumentsList

 (a 

List

).

FunctionBody

 

:

 

FunctionStatementList

1.  Return ? 

EvaluateFunctionBody

 of 

FunctionBody

 with arguments 

functionObject

 and 

argumentsList

.

ConciseBody

 

:

 

ExpressionBody

1.  Return ? 

EvaluateConciseBody

 of 

ConciseBody

 with arguments 

functionObject

 and 

argumentsList

.

GeneratorBody

 

:

 

FunctionBody

1.  Return ? 

EvaluateGeneratorBody

 of 

GeneratorBody

 with arguments 

functionObject

 and 

argumentsList

.

AsyncGeneratorBody

 

:

 

FunctionBody

1.  Return ? 

EvaluateAsyncGeneratorBody

 of 

AsyncGeneratorBody

 with arguments 

functionObject

 and

argumentsList

.

AsyncFunctionBody

 

:

 

FunctionBody

1.  Return ? 

EvaluateAsyncFunctionBody

 of 

AsyncFunctionBody

 with arguments 

functionObject

 and 

argumentsList

.

AsyncConciseBody

 

:

 

ExpressionBody

10.2.1.2  OrdinaryCallBindThis ( 

F

calleeContext

thisArgument

 )

10.2.1.3  Runtime Semantics: EvaluateBody

232

1.  Return ? 

EvaluateAsyncConciseBody

 of 

AsyncConciseBody

 with arguments 

functionObject

 and 

argumentsList

.

The abstract operation OrdinaryCallEvaluateBody takes arguments 

F

 (a 

function object

) and 

argumentsList

 (a 

List

). It

performs the following steps when called:

1.  Return the result of 

EvaluateBody

 of the parsed code that is 

F

.[[ECMAScriptCode]] passing 

F

 and 

argumentsList

as the arguments.

The [[Construct]] internal method of an ECMAScript 

function object

 

F

 takes arguments 

argumentsList

 (a 

List

 of

ECMAScript language values) and 

newTarget

 (a 

constructor

). It performs the following steps when called:

1. 

Assert

F

 is an ECMAScript 

function object

.

2. 

Assert

Type

(

newTarget

) is Object.

3.  Let 

callerContext

 be the 

running execution context

.

4.  Let 

kind

 be 

F

.[[ConstructorKind]].

5.  If 

kind

 is 

base

, then

a.  Let 

thisArgument

 be ? 

OrdinaryCreateFromConstructor

(

newTarget

"%Object.prototype%"

).

6.  Let 

calleeContext

 be 

PrepareForOrdinaryCall

(

F

newTarget

).

7. 

Assert

calleeContext

 is now the 

running execution context

.

8.  If 

kind

 is 

base

, perform 

OrdinaryCallBindThis

(

F

calleeContext

thisArgument

).

9.  Let 

constructorEnv

 be the LexicalEnvironment of 

calleeContext

.

10.  Let 

result

 be 

OrdinaryCallEvaluateBody

(

F

argumentsList

).

11.  Remove 

calleeContext

 from the 

execution context stack

 and restore 

callerContext

 as the 

running execution

context

.

12.  If 

result

.[[Type]] is 

return

, then

a.  If 

Type

(

result

.[[Value]]) is Object, return 

NormalCompletion

(

result

.[[Value]]).

b.  If 

kind

 is 

base

, return 

NormalCompletion

(

thisArgument

).

c.  If 

result

.[[Value]] is not 

undefined

, throw a 

TypeError

 exception.

13.  Else, 

ReturnIfAbrupt

(

result

).

14.  Return ? 

constructorEnv

.GetThisBinding().

The abstract operation OrdinaryFunctionCreate takes arguments 

functionPrototype

 (an Object), 

sourceText

 (a sequence

of Unicode code points), 

ParameterList

 (a 

Parse Node

), 

Body

 (a 

Parse Node

), 

thisMode

 (either 

lexical-this

 or 

non-lexical-

this

), and 

Scope

 (an 

Environment Record

). 

sourceText

 is the source text of the syntactic definition of the function to be

created. It performs the following steps when called:

1. 

Assert

Type

(

functionPrototype

) is Object.

2.  Let 

internalSlotsList

 be the internal slots listed in 

Table 29

.

3.  Let 

F

 be ! 

OrdinaryObjectCreate

(

functionPrototype

internalSlotsList

).

4.  Set 

F

.[[Call]] to the definition specified in 

10.2.1

.

5.  Set 

F

.[[SourceText]] to 

sourceText

.

10.2.1.4  OrdinaryCallEvaluateBody ( 

F

argumentsList

 )

10.2.2  [[Construct]] ( 

argumentsList

newTarget

 )

10.2.3  OrdinaryFunctionCreate ( 

functionPrototype

sourceText

ParameterList

Body

,

thisMode

Scope

 )

233

6.  Set 

F

.[[FormalParameters]] to 

ParameterList

.

7.  Set 

F

.[[ECMAScriptCode]] to 

Body

.

8.  If the source text matching 

Body

 is 

strict mode code

, let 

Strict

 be 

true

; else let 

Strict

 be 

false

.

9.  Set 

F

.[[Strict]] to 

Strict

.

10.  If 

thisMode

 is 

lexical-this

, set 

F

.[[ThisMode]] to 

lexical

.

11.  Else if 

Strict

 is 

true

, set 

F

.[[ThisMode]] to 

strict

.

12.  Else, set 

F

.[[ThisMode]] to 

global

.

13.  Set 

F

.[[IsClassConstructor]] to 

false

.

14.  Set 

F

.[[Environment]] to 

Scope

.

15.  Set 

F

.[[ScriptOrModule]] to 

GetActiveScriptOrModule

().

16.  Set 

F

.[[Realm]] to 

the current Realm Record

.

17.  Set 

F

.[[HomeObject]] to 

undefined

.

18.  Let 

len

 be the 

ExpectedArgumentCount

 of 

ParameterList

.

19.  Perform ! 

SetFunctionLength

(

F

len

).

20.  Return 

F

.

The abstract operation AddRestrictedFunctionProperties takes arguments 

F

 (a 

function object

) and 

realm

 (a 

Realm

Record

). It performs the following steps when called:

1. 

Assert

realm

.[[Intrinsics]].[[

%ThrowTypeError%

]] exists and has been initialized.

2.  Let 

thrower

 be 

realm

.[[Intrinsics]].[[

%ThrowTypeError%

]].

3.  Perform ! 

DefinePropertyOrThrow

(

F

"caller"

, PropertyDescriptor { [[Get]]: 

thrower

, [[Set]]: 

thrower

,

[[Enumerable]]: 

false

, [[Configurable]]: 

true

 }).

4.  Return ! 

DefinePropertyOrThrow

(

F

"arguments"

, PropertyDescriptor { [[Get]]: 

thrower

, [[Set]]: 

thrower

,

[[Enumerable]]: 

false

, [[Configurable]]: 

true

 }).

The 

%ThrowTypeError%

 intrinsic is an anonymous built-in 

function object

 that is defined once for each 

realm

. When

%ThrowTypeError% is called it performs the following steps:

1.  Throw a 

TypeError

 exception.

The value of the [[Extensible]] internal slot of a %ThrowTypeError% function is 

false

.

The 

"length"

 property of a %ThrowTypeError% function has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

,

[[Configurable]]: 

false

 }.

The 

"name"

 property of a %ThrowTypeError% function has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

,

[[Configurable]]: 

false

 }.

The abstract operation MakeConstructor takes argument 

F

 (a 

function object

) and optional arguments

writablePrototype

 (a Boolean) and 

prototype

 (an Object). It converts 

F

 into a 

constructor

. It performs the following steps

when called:

10.2.4  AddRestrictedFunctionProperties ( 

F

realm

 )

10.2.4.1  %ThrowTypeError% ( )

10.2.5  MakeConstructor ( 

F

 [ , 

writablePrototype

 [ , 

prototype

 ] ] )

234

1. 

Assert

F

 is an ECMAScript 

function object

 or a built-in 

function object

.

2.  If 

F

 is an ECMAScript 

function object

, then

a. 

Assert

IsConstructor

(

F

) is 

false

.

b. 

Assert

F

 is an extensible object that does not have a 

"prototype"

 own property.

c.  Set 

F

.[[Construct]] to the definition specified in 

10.2.2

.

3.  Set 

F

.[[ConstructorKind]] to 

base

.

4.  If 

writablePrototype

 is not present, set 

writablePrototype

 to 

true

.

5.  If 

prototype

 is not present, then

a.  Set 

prototype

 to ! 

OrdinaryObjectCreate

(

%Object.prototype%

).

b.  Perform ! 

DefinePropertyOrThrow

(

prototype

"constructor"

, PropertyDescriptor { [[Value]]: 

F

,

[[Writable]]: 

writablePrototype

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }).

6.  Perform ! 

DefinePropertyOrThrow

(

F

"prototype"

, PropertyDescriptor { [[Value]]: 

prototype

, [[Writable]]:

writablePrototype

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }).

7.  Return 

NormalCompletion

(

undefined

).

The abstract operation MakeClassConstructor takes argument 

F

. It performs the following steps when called:

1. 

Assert

F

 is an ECMAScript 

function object

.

2. 

Assert

F

.[[IsClassConstructor]] is 

false

.

3.  Set 

F

.[[IsClassConstructor]] to 

true

.

4.  Return 

NormalCompletion

(

undefined

).

The abstract operation MakeMethod takes arguments 

F

 and 

homeObject

. It configures 

F

 as a method. It performs the

following steps when called:

1. 

Assert

F

 is an ECMAScript 

function object

.

2. 

Assert

Type

(

homeObject

) is Object.

3.  Set 

F

.[[HomeObject]] to 

homeObject

.

4.  Return 

NormalCompletion

(

undefined

).

The abstract operation SetFunctionName takes arguments 

F

 (a 

function object

) and 

name

 (a property key) and optional

argument 

prefix

 (a String). It adds a 

"name"

 property to 

F

. It performs the following steps when called:

1. 

Assert

F

 is an extensible object that does not have a 

"name"

 own property.

2. 

Assert

Type

(

name

) is either Symbol or String.

3. 

Assert

: If 

prefix

 is present, then 

Type

(

prefix

) is String.

4.  If 

Type

(

name

) is Symbol, then

a.  Let 

description

 be 

name

's [[Description]] value.

b.  If 

description

 is 

undefined

, set 

name

 to the empty String.

c.  Else, set 

name

 to the 

string-concatenation

 of 

"["

description

, and 

"]"

.

5.  If 

F

 has an [[InitialName]] internal slot, then

a.  Set 

F

.[[InitialName]] to 

name

.

10.2.6  MakeClassConstructor ( 

F

 )

10.2.7  MakeMethod ( 

F

homeObject

 )

10.2.8  SetFunctionName ( 

F

name

 [ , 

prefix

 ] )

235

6.  If 

prefix

 is present, then

a.  Set 

name

 to the 

string-concatenation

 of 

prefix

, the code unit 0x0020 (SPACE), and 

name

.

b.  If 

F

 has an [[InitialName]] internal slot, then

i.  Optionally, set 

F

.[[InitialName]] to 

name

.

7.  Return ! 

DefinePropertyOrThrow

(

F

"name"

, PropertyDescriptor { [[Value]]: 

name

, [[Writable]]: 

false

,

[[Enumerable]]: 

false

, [[Configurable]]: 

true

 }).

The abstract operation SetFunctionLength takes arguments 

F

 (a 

function object

) and 

length

 (a non-negative 

integer

 or

+

). It adds a 

"length"

 property to 

F

. It performs the following steps when called:

1. 

Assert

F

 is an extensible object that does not have a 

"length"

 own property.

2.  Return ! 

DefinePropertyOrThrow

(

F

"length"

length

), [[Writable]]: 

false

,

[[Enumerable]]: 

false

, [[Configurable]]: 

true

 }).

NOTE 1

The abstract operation FunctionDeclarationInstantiation takes arguments 

func

 (a 

function object

) and 

argumentsList

.

func

 is the 

function object

 for which the 

execution context

 is being established. It performs the following steps when

called:

1.  Let 

calleeContext

 be the 

running execution context

.

2.  Let 

code

 be 

func

.[[ECMAScriptCode]].

3.  Let 

strict

 be 

func

.[[Strict]].

4.  Let 

formals

 be 

func

.[[FormalParameters]].

5.  Let 

parameterNames

 be the 

BoundNames

 of 

formals

.

6.  If 

parameterNames

 has any duplicate entries, let 

hasDuplicates

 be 

true

. Otherwise, let 

hasDuplicates

 be 

false

.

7.  Let 

simpleParameterList

 be 

IsSimpleParameterList

 of 

formals

.

8.  Let 

hasParameterExpressions

 be 

ContainsExpression

 of 

formals

.

9.  Let 

varNames

 be the 

VarDeclaredNames

 of 

code

.

10.  Let 

varDeclarations

 be the 

VarScopedDeclarations

 of 

code

.

11.  Let 

lexicalNames

 be the 

LexicallyDeclaredNames

 of 

code

.

12.  Let 

functionNames

 be a new empty 

List

.

13.  Let 

functionsToInitialize

 be a new empty 

List

.

14.  For each element 

d

 of 

varDeclarations

, in reverse 

List

 order, do

a.  If 

d

 is neither a 

VariableDeclaration

 nor a 

ForBinding

 nor a 

BindingIdentifier

, then

i. 

Assert

d

 is either a 

FunctionDeclaration

, a 

GeneratorDeclaration

, an 

AsyncFunctionDeclaration

, or an 

When an 

execution context

 is established for evaluating an ECMAScript function a new 

function

Environment Record

 is created and bindings for each formal parameter are instantiated in that

Environment Record

. Each declaration in the function body is also instantiated. If the function's

formal parameters do not include any default value initializers then the body declarations are
instantiated in the same 

Environment Record

 as the parameters. If default value parameter

initializers exist, a second 

Environment Record

 is created for the body declarations. Formal

parameters and functions are initialized as part of FunctionDeclarationInstantiation. All other
bindings are initialized during evaluation of the function body.

10.2.9  SetFunctionLength ( 

F

length

 )

10.2.10  FunctionDeclarationInstantiation ( 

func

argumentsList

 )

236

AsyncGeneratorDeclaration

.

ii.  Let 

fn

 be the sole element of the 

BoundNames

 of 

d

.

iii.  If 

fn

 is not an element of 

functionNames

, then

1.  Insert 

fn

 as the first element of 

functionNames

.

2.  NOTE: If there are multiple function declarations for the same name, the last declaration is

used.

3.  Insert 

d

 as the first element of 

functionsToInitialize

.

15.  Let 

argumentsObjectNeeded

 be 

true

.

16.  If 

func

.[[ThisMode]] is 

lexical

, then

a.  NOTE: Arrow functions never have an arguments objects.

b.  Set 

argumentsObjectNeeded

 to 

false

.

17.  Else if 

"arguments"

 is an element of 

parameterNames

, then

a.  Set 

argumentsObjectNeeded

 to 

false

.

18.  Else if 

hasParameterExpressions

 is 

false

, then

a.  If 

"arguments"

 is an element of 

functionNames

 or if 

"arguments"

 is an element of 

lexicalNames

, then

i.  Set 

argumentsObjectNeeded

 to 

false

.

19.  If 

strict

 is 

true

 or if 

hasParameterExpressions

 is 

false

, then

a.  NOTE: Only a single 

Environment Record

 is needed for the parameters and top-level vars.

b.  Let 

env

 be the LexicalEnvironment of 

calleeContext

.

20.  Else,

a.  NOTE: A separate 

Environment Record

 is needed to ensure that bindings created by 

direct eval

 calls in

the formal parameter list are outside the environment where parameters are declared.

b.  Let 

calleeEnv

 be the LexicalEnvironment of 

calleeContext

.

c.  Let 

env

 be 

NewDeclarativeEnvironment

(

calleeEnv

).

d. 

Assert

: The VariableEnvironment of 

calleeContext

 is 

calleeEnv

.

e.  Set the LexicalEnvironment of 

calleeContext

 to 

env

.

21.  For each String 

paramName

 of 

parameterNames

, do

a.  Let 

alreadyDeclared

 be 

env

.HasBinding(

paramName

).

b.  NOTE: Early errors ensure that duplicate parameter names can only occur in non-strict functions that do

not have parameter default values or rest parameters.

c.  If 

alreadyDeclared

 is 

false

, then

i.  Perform ! 

env

.CreateMutableBinding(

paramName

false

).

ii.  If 

hasDuplicates

 is 

true

, then

1.  Perform ! 

env

.InitializeBinding(

paramName

undefined

).

22.  If 

argumentsObjectNeeded

 is 

true

, then

a.  If 

strict

 is 

true

 or if 

simpleParameterList

 is 

false

, then

i.  Let 

ao

 be 

CreateUnmappedArgumentsObject

(

argumentsList

).

b.  Else,

i.  NOTE: A mapped argument object is only provided for non-strict functions that don't have a rest

parameter, any parameter default value initializers, or any destructured parameters.

ii.  Let 

ao

 be 

CreateMappedArgumentsObject

(

func

formals

argumentsList

env

).

c.  If 

strict

 is 

true

, then

i.  Perform ! 

env

.CreateImmutableBinding(

"arguments"

false

).

d.  Else,

i.  Perform ! 

env

.CreateMutableBinding(

"arguments"

false

).

e.  Call 

env

.InitializeBinding(

"arguments"

ao

).

f.  Let 

parameterBindings

 be a 

List

 whose elements are the elements of 

parameterNames

, followed by

"arguments"

.

237

23.  Else,

a.  Let 

parameterBindings

 be 

parameterNames

.

24.  Let 

iteratorRecord

 be 

CreateListIteratorRecord

(

argumentsList

).

25.  If 

hasDuplicates

 is 

true

, then

a.  Perform ? 

IteratorBindingInitialization

 for 

formals

 with 

iteratorRecord

 and 

undefined

 as arguments.

26.  Else,

a.  Perform ? 

IteratorBindingInitialization

 for 

formals

 with 

iteratorRecord

 and 

env

 as arguments.

27.  If 

hasParameterExpressions

 is 

false

, then

a.  NOTE: Only a single 

Environment Record

 is needed for the parameters and top-level vars.

b.  Let 

instantiatedVarNames

 be a copy of the 

List

 

parameterBindings

.

c.  For each element 

n

 of 

varNames

, do

i.  If 

n

 is not an element of 

instantiatedVarNames

, then

1.  Append 

n

 to 

instantiatedVarNames

.

2.  Perform ! 

env

.CreateMutableBinding(

n

false

).

3.  Call 

env

.InitializeBinding(

n

undefined

).

d.  Let 

varEnv

 be 

env

.

28.  Else,

a.  NOTE: A separate 

Environment Record

 is needed to ensure that closures created by expressions in the

formal parameter list do not have visibility of declarations in the function body.

b.  Let 

varEnv

 be 

NewDeclarativeEnvironment

(

env

).

c.  Set the VariableEnvironment of 

calleeContext

 to 

varEnv

.

d.  Let 

instantiatedVarNames

 be a new empty 

List

.

e.  For each element 

n

 of 

varNames

, do

i.  If 

n

 is not an element of 

instantiatedVarNames

, then

1.  Append 

n

 to 

instantiatedVarNames

.

2.  Perform ! 

varEnv

.CreateMutableBinding(

n

false

).

3.  If 

n

 is not an element of 

parameterBindings

 or if 

n

 is an element of 

functionNames

, let

initialValue

 be 

undefined

.

4.  Else,

a.  Let 

initialValue

 be ! 

env

.GetBindingValue(

n

false

).

5.  Call 

varEnv

.InitializeBinding(

n

initialValue

).

6.  NOTE: A var with the same name as a formal parameter initially has the same value as the

corresponding initialized parameter.

29.  NOTE: Annex 

B.3.3.1

 adds additional steps at this point.

30.  If 

strict

 is 

false

, then

a.  Let 

lexEnv

 be 

NewDeclarativeEnvironment

(

varEnv

).

b.  NOTE: Non-strict functions use a separate 

Environment Record

 for top-level lexical declarations so that

direct eval

 can determine whether any var scoped declarations introduced by the eval code conflict

with pre-existing top-level lexically scoped declarations. This is not needed for strict functions because a
strict 

direct eval

 always places all declarations into a new 

Environment Record

.

31.  Else, let 

lexEnv

 be 

varEnv

.

32.  Set the LexicalEnvironment of 

calleeContext

 to 

lexEnv

.

33.  Let 

lexDeclarations

 be the 

LexicallyScopedDeclarations

 of 

code

.

34.  For each element 

d

 of 

lexDeclarations

, do

a.  NOTE: A lexically declared name cannot be the same as a function/generator declaration, formal

parameter, or a var name. Lexically declared names are only instantiated here but not initialized.

b.  For each element 

dn

 of the 

BoundNames

 of 

d

, do

i.  If 

IsConstantDeclaration

 of 

d

 is 

true

, then

238

1.  Perform ! 

lexEnv

.CreateImmutableBinding(

dn

true

).

ii.  Else,

1.  Perform ! 

lexEnv

.CreateMutableBinding(

dn

false

).

35.  For each 

Parse Node

 

f

 of 

functionsToInitialize

, do

a.  Let 

fn

 be the sole element of the 

BoundNames

 of 

f

.

b.  Let 

fo

 be 

InstantiateFunctionObject

 of 

f

 with argument 

lexEnv

.

c.  Perform ! 

varEnv

.SetMutableBinding(

fn

fo

false

).

36.  Return 

NormalCompletion

(

empty

).

NOTE 2

NOTE 3

The built-in function objects defined in this specification may be implemented as either ECMAScript function objects
(

10.2

) whose behaviour is provided using ECMAScript code or as implementation provided function exotic objects

whose behaviour is provided in some other manner. In either case, the effect of calling such functions must conform to
their specifications. An implementation may also provide additional built-in function objects that are not defined in
this specification.

If a built-in 

function object

 is implemented as an 

exotic object

 it must have the 

ordinary object

 behaviour specified in

10.1

. All such function exotic objects also have [[Prototype]], [[Extensible]], and [[Realm]] internal slots.

Unless otherwise specified every built-in 

function object

 has the 

%Function.prototype%

 object as the initial value of its

[[Prototype]] internal slot.

The behaviour specified for each built-in function via algorithm steps or other means is the specification of the
function body behaviour for both [[Call]] and [[Construct]] invocations of the function. However, [[Construct]]
invocation is not supported by all built-in functions. For each built-in function, when invoked with [[Call]], the [[Call]]

thisArgument

 provides the 

this

 value, the [[Call]] 

argumentsList

 provides the named parameters, and the NewTarget

value is 

undefined

. When invoked with [[Construct]], the 

this

 value is uninitialized, the [[Construct]] 

argumentsList

provides the named parameters, and the [[Construct]] 

newTarget

 parameter provides the NewTarget value. If the built-

in function is implemented as an ECMAScript 

function object

 then this specified behaviour must be implemented by

the ECMAScript code that is the body of the function. Built-in functions that are ECMAScript function objects must be
strict functions. If a built-in 

constructor

 has any [[Call]] behaviour other than throwing a 

TypeError

 exception, an

ECMAScript implementation of the function must be done in a manner that does not cause the function's
[[IsClassConstructor]] internal slot to have the value 

true

.

Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method
unless otherwise specified in the description of a particular function. When a built-in 

constructor

 is called as part of a

new

new

 expression the 

argumentsList

 parameter of the invoked [[Construct]] internal method provides the values for the

built-in 

constructor

's named parameters.

B.3.3

 provides an extension to the above algorithm that is necessary for backwards compatibility

with web browser implementations of ECMAScript that predate ECMAScript 2015.

Parameter 

Initializer

s may contain 

direct eval

 expressions. Any top level declarations of such

evals are only visible to the eval code (

11.2

). The creation of the environment for such

declarations is described in 

8.5.3

.

10.3  Built-in Function Objects

239

Built-in functions that are not constructors do not have a 

"prototype"

 property unless otherwise specified in the

description of a particular function.

Built-in functions have an [[InitialName]] internal slot.

If a built-in 

function object

 is not implemented as an ECMAScript function it must provide [[Call]] and [[Construct]]

internal methods that conform to the following definitions:

The [[Call]] internal method of a built-in 

function object

 

F

 takes arguments 

thisArgument

 (an 

ECMAScript language

value

) and 

argumentsList

 (a 

List

 of ECMAScript language values). It performs the following steps when called:

1.  Let 

callerContext

 be the 

running execution context

.

2.  If 

callerContext

 is not already suspended, suspend 

callerContext

.

3.  Let 

calleeContext

 be a new 

execution context

.

4.  Set the Function of 

calleeContext

 to 

F

.

5.  Let 

calleeRealm

 be 

F

.[[Realm]].

6.  Set the 

Realm

 of 

calleeContext

 to 

calleeRealm

.

7.  Set the ScriptOrModule of 

calleeContext

 to 

null

.

8.  Perform any necessary 

implementation-defined

 initialization of 

calleeContext

.

9.  Push 

calleeContext

 onto the 

execution context stack

calleeContext

 is now the 

running execution context

.

10.  Let 

result

 be the 

Completion Record

 that is the result of evaluating 

F

 in a manner that conforms to the

specification of 

F

thisArgument

 is the 

this

 value, 

argumentsList

 provides the named parameters, and the

NewTarget value is 

undefined

.

11.  Remove 

calleeContext

 from the 

execution context stack

 and restore 

callerContext

 as the 

running execution

context

.

12.  Return 

result

.

NOTE

The [[Construct]] internal method of a built-in 

function object

 

F

 takes arguments 

argumentsList

 (a 

List

 of ECMAScript

language values) and 

newTarget

 (a 

constructor

). The steps performed are the same as [[Call]] (see 

10.3.1

) except that

step 

10

 is replaced by:

10.  Let 

result

 be the 

Completion Record

 that is the result of evaluating 

F

 in a manner that conforms to the

specification of 

F

. The 

this

 value is uninitialized, 

argumentsList

 provides the named parameters, and 

newTarget

provides the NewTarget value.

The abstract operation CreateBuiltinFunction takes arguments 

steps

length

name

, and 

internalSlotsList

 (a 

List

 of names

of internal slots) and optional arguments 

realm

prototype

, and 

prefix

internalSlotsList

 contains the names of additional

internal slots that must be defined as part of the object. This operation creates a built-in 

function object

. It performs the

When 

calleeContext

 is removed from the 

execution context stack

 it must not be destroyed if it has

been suspended and retained by an accessible generator object for later resumption.

10.3.1  [[Call]] ( 

thisArgument

argumentsList

 )

10.3.2  [[Construct]] ( 

argumentsList

newTarget

 )

10.3.3  CreateBuiltinFunction ( 

steps

length

name

internalSlotsList

 [ , 

realm

 [ , 

prototype

 [ ,

prefix

 ] ] ] )

240

following steps when called:

1. 

Assert

steps

 is either a set of algorithm steps or other definition of a function's behaviour provided in this

specification.

2.  If 

realm

 is not present or 

realm

 is 

empty

, set 

realm

 to 

the current Realm Record

.

3. 

Assert

realm

 is a 

Realm Record

.

4.  If 

prototype

 is not present, set 

prototype

 to 

realm

.[[Intrinsics]].[[

%Function.prototype%

]].

5.  Let 

func

 be a new built-in 

function object

 that when called performs the action described by 

steps

. The new

function object

 has internal slots whose names are the elements of 

internalSlotsList

, and an [[InitialName]]

internal slot.

6.  Set 

func

.[[Realm]] to 

realm

.

7.  Set 

func

.[[Prototype]] to 

prototype

.

8.  Set 

func

.[[Extensible]] to 

true

.

9.  Set 

func

.[[InitialName]] to 

null

.

10.  Perform ! 

SetFunctionLength

(

func

length

).

11.  If 

prefix

 is not present, then

a.  Perform ! 

SetFunctionName

(

func

name

).

12.  Else,

a.  Perform ! 

SetFunctionName

(

func

name

prefix

).

13.  Return 

func

.

Each built-in function defined in this specification is created by calling the CreateBuiltinFunction abstract operation.

This specification defines several kinds of built-in exotic objects. These objects generally behave similar to ordinary
objects except for a few specific situations. The following exotic objects use the 

ordinary object

 internal methods

except where it is explicitly specified otherwise below:

bound function exotic object

 is an 

exotic object

 that wraps another 

function object

. A 

bound function exotic object

 is

callable (it has a [[Call]] internal method and may have a [[Construct]] internal method). Calling a 

bound function

exotic object

 generally results in a call of its wrapped function.

An object is a 

bound function exotic object

 if its [[Call]] and (if applicable) [[Construct]] internal methods use the

following implementations, and its other essential internal methods use the definitions found in 

10.1

. These methods

are installed in 

BoundFunctionCreate

.

Bound function exotic objects do not have the internal slots of ECMAScript function objects listed in 

Table 29

. Instead

they have the internal slots listed in 

Table 30

, in addition to [[Prototype]] and [[Extensible]].

10.4  Built-in Exotic Object Internal Methods and Slots

10.4.1  Bound Function Exotic Objects

241

Table 30: Internal Slots of Bound Function Exotic Objects

Internal Slot

Type

Description

[[BoundTargetFunction]] Callable

Object

The wrapped 

function object

.

[[BoundThis]]

Any

The value that is always passed as the 

this

 value when calling the wrapped

function.

[[BoundArguments]]

List

 of Any A list of values whose elements are used as the first arguments to any call to

the wrapped function.

The [[Call]] internal method of a 

bound function exotic object

 

F

 takes arguments 

thisArgument

 (an 

ECMAScript

language value

) and 

argumentsList

 (a 

List

 of ECMAScript language values). It performs the following steps when

called:

1.  Let 

target

 be 

F

.[[BoundTargetFunction]].

2.  Let 

boundThis

 be 

F

.[[BoundThis]].

3.  Let 

boundArgs

 be 

F

.[[BoundArguments]].

4.  Let 

args

 be a 

List

 whose elements are the elements of 

boundArgs

, followed by the elements of 

argumentsList

.

5.  Return ? 

Call

(

target

boundThis

args

).

The [[Construct]] internal method of a 

bound function exotic object

 

F

 takes arguments 

argumentsList

 (a 

List

 of

ECMAScript language values) and 

newTarget

 (a 

constructor

). It performs the following steps when called:

1.  Let 

target

 be 

F

.[[BoundTargetFunction]].

2. 

Assert

IsConstructor

(

target

) is 

true

.

3.  Let 

boundArgs

 be 

F

.[[BoundArguments]].

4.  Let 

args

 be a 

List

 whose elements are the elements of 

boundArgs

, followed by the elements of 

argumentsList

.

5.  If 

SameValue

(

F

newTarget

) is 

true

, set 

newTarget

 to 

target

.

6.  Return ? 

Construct

(

target

args

newTarget

).

The abstract operation BoundFunctionCreate takes arguments 

targetFunction

boundThis

, and 

boundArgs

. It is used to

specify the creation of new bound function exotic objects. It performs the following steps when called:

1. 

Assert

Type

(

targetFunction

) is Object.

2.  Let 

proto

 be ? 

targetFunction

.[[GetPrototypeOf]]().

3.  Let 

internalSlotsList

 be the internal slots listed in 

Table 30

, plus [[Prototype]] and [[Extensible]].

4.  Let 

obj

 be ! 

MakeBasicObject

(

internalSlotsList

).

5.  Set 

obj

.[[Prototype]] to 

proto

.

6.  Set 

obj

.[[Call]] as described in 

10.4.1.1

.

7.  If 

IsConstructor

(

targetFunction

) is 

true

, then

a.  Set 

obj

.[[Construct]] as described in 

10.4.1.2

.

10.4.1.1  [[Call]] ( 

thisArgument

argumentsList

 )

10.4.1.2  [[Construct]] ( 

argumentsList

newTarget

 )

10.4.1.3  BoundFunctionCreate ( 

targetFunction

boundThis

boundArgs

 )

242

 

 

 

 

 

 

 

Content      ..     19      20      21      22     ..