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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     28      29      30      31     ..

 

 

 

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

 

 

The Object 

constructor

:

is 

%Object%

.

is the initial value of the 

"Object"

 property of the 

global object

.

creates a new 

ordinary object

 when called as a 

constructor

.

performs a type conversion when called as a function rather than as a 

constructor

.

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

extends

extends

 clause of a class definition.

When the 

Object

Object

 function is called with optional argument 

value

, the following steps are taken:

1.  If NewTarget is neither 

undefined

 nor the active function, then

a.  Return ? 

OrdinaryCreateFromConstructor

(NewTarget, 

"%Object.prototype%"

).

2.  If 

value

 is 

undefined

 or 

null

, return ! 

OrdinaryObjectCreate

(

%Object.prototype%

).

3.  Return ! 

ToObject

(

value

).

The 

"length"

 property of the 

Object

Object

 function is 

1

𝔽

.

The Object 

constructor

:

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

%Function.prototype%

.

has a 

"length"

 property.

has the following additional properties:

The 

assign

assign

 function is used to copy the values of all of the enumerable own properties from one or more source

objects to a 

target

 object. When the 

assign

assign

 function is called, the following steps are taken:

1.  Let 

to

 be ? 

ToObject

(

target

).

2.  If only one argument was passed, return 

to

.

3.  For each element 

nextSource

 of 

sources

, do

a.  If 

nextSource

 is neither 

undefined

 nor 

null

, then

i.  Let 

from

 be ! 

ToObject

(

nextSource

).

ii.  Let 

keys

 be ? 

from

.[[OwnPropertyKeys]]().

iii.  For each element 

nextKey

 of 

keys

, do

1.  Let 

desc

 be ? 

from

.[[GetOwnProperty]](

nextKey

).

2.  If 

desc

 is not 

undefined

 and 

desc

.[[Enumerable]] is 

true

, then

a.  Let 

propValue

 be ? 

Get

(

from

nextKey

).

b.  Perform ? 

Set

(

to

nextKey

propValue

true

).

4.  Return 

to

.

20.1  Object Objects

20.1.1  The Object Constructor

20.1.1.1  Object ( [ 

value

 ] )

20.1.2  Properties of the Object Constructor

20.1.2.1  Object.assign ( 

target

, ...

sources

 )

480

The 

"length"

 property of the 

assign

assign

 function is 

2

𝔽

.

The 

create

create

 function creates a new object with a specified prototype. When the 

create

create

 function is called, the

following steps are taken:

1.  If 

Type

(

O

) is neither Object nor Null, throw a 

TypeError

 exception.

2.  Let 

obj

 be ! 

OrdinaryObjectCreate

(

O

).

3.  If 

Properties

 is not 

undefined

, then

a.  Return ? 

ObjectDefineProperties

(

obj

Properties

).

4.  Return 

obj

.

The 

defineProperties

defineProperties

 function is used to add own properties and/or update the attributes of existing own

properties of an object. When the 

defineProperties

defineProperties

 function is called, the following steps are taken:

1.  If 

Type

(

O

) is not Object, throw a 

TypeError

 exception.

2.  Return ? 

ObjectDefineProperties

(

O

Properties

).

The abstract operation ObjectDefineProperties takes arguments 

O

 and 

Properties

. It performs the following steps when

called:

1. 

Assert

Type

(

O

) is Object.

2.  Let 

props

 be ? 

ToObject

(

Properties

).

3.  Let 

keys

 be ? 

props

.[[OwnPropertyKeys]]().

4.  Let 

descriptors

 be a new empty 

List

.

5.  For each element 

nextKey

 of 

keys

, do

a.  Let 

propDesc

 be ? 

props

.[[GetOwnProperty]](

nextKey

).

b.  If 

propDesc

 is not 

undefined

 and 

propDesc

.[[Enumerable]] is 

true

, then

i.  Let 

descObj

 be ? 

Get

(

props

nextKey

).

ii.  Let 

desc

 be ? 

ToPropertyDescriptor

(

descObj

).

iii.  Append the pair (a two element 

List

) consisting of 

nextKey

 and 

desc

 to the end of 

descriptors

.

6.  For each element 

pair

 of 

descriptors

, do

a.  Let 

P

 be the first element of 

pair

.

b.  Let 

desc

 be the second element of 

pair

.

c.  Perform ? 

DefinePropertyOrThrow

(

O

P

desc

).

7.  Return 

O

.

The 

defineProperty

defineProperty

 function is used to add an own property and/or update the attributes of an existing own

property of an object. When the 

defineProperty

defineProperty

 function is called, the following steps are taken:

1.  If 

Type

(

O

) is not Object, throw a 

TypeError

 exception.

2.  Let 

key

 be ? 

ToPropertyKey

(

P

).

20.1.2.2  Object.create ( 

O

Properties

 )

20.1.2.3  Object.defineProperties ( 

O

Properties

 )

20.1.2.3.1  ObjectDefineProperties ( 

O

Properties

 )

20.1.2.4  Object.defineProperty ( 

O

P

Attributes

 )

481

3.  Let 

desc

 be ? 

ToPropertyDescriptor

(

Attributes

).

4.  Perform ? 

DefinePropertyOrThrow

(

O

key

desc

).

5.  Return 

O

.

When the 

entries

entries

 function is called with argument 

O

, the following steps are taken:

1.  Let 

obj

 be ? 

ToObject

(

O

).

2.  Let 

nameList

 be ? 

EnumerableOwnPropertyNames

(

obj

key+value

).

3.  Return 

CreateArrayFromList

(

nameList

).

When the 

freeze

freeze

 function is called, the following steps are taken:

1.  If 

Type

(

O

) is not Object, return 

O

.

2.  Let 

status

 be ? 

SetIntegrityLevel

(

O

frozen

).

3.  If 

status

 is 

false

, throw a 

TypeError

 exception.

4.  Return 

O

.

When the 

fromEntries

fromEntries

 method is called with argument 

iterable

, the following steps are taken:

1.  Perform ? 

RequireObjectCoercible

(

iterable

).

2.  Let 

obj

 be ! 

OrdinaryObjectCreate

(

%Object.prototype%

).

3. 

Assert

obj

 is an extensible 

ordinary object

 with no own properties.

4.  Let 

stepsDefine

 be the algorithm steps defined in 

CreateDataPropertyOnObject Functions

.

5.  Let 

lengthDefine

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

CreateDataPropertyOnObject Functions

.

6.  Let 

adder

 be ! 

CreateBuiltinFunction

(

stepsDefine

lengthDefine

""

, « »).

7.  Return ? 

AddEntriesFromIterable

(

obj

iterable

adder

).

NOTE

A CreateDataPropertyOnObject function is an anonymous built-in function. When a CreateDataPropertyOnObject
function is called with arguments 

key

 and 

value

, the following steps are taken:

1.  Let 

O

 be the 

this

 value.

2. 

Assert

Type

(

O

) is Object.

3. 

Assert

O

 is an extensible 

ordinary object

.

4.  Let 

propertyKey

 be ? 

ToPropertyKey

(

key

).

5.  Perform ! 

CreateDataPropertyOrThrow

(

O

propertyKey

value

).

6.  Return 

undefined

.

The function created for 

adder

 is never directly accessible to ECMAScript code.

20.1.2.5  Object.entries ( 

O

 )

20.1.2.6  Object.freeze ( 

O

 )

20.1.2.7  Object.fromEntries ( 

iterable

 )

20.1.2.7.1  CreateDataPropertyOnObject Functions

482

When the 

getOwnPropertyDescriptor

getOwnPropertyDescriptor

 function is called, the following steps are taken:

1.  Let 

obj

 be ? 

ToObject

(

O

).

2.  Let 

key

 be ? 

ToPropertyKey

(

P

).

3.  Let 

desc

 be ? 

obj

.[[GetOwnProperty]](

key

).

4.  Return 

FromPropertyDescriptor

(

desc

).

When the 

getOwnPropertyDescriptors

getOwnPropertyDescriptors

 function is called, the following steps are taken:

1.  Let 

obj

 be ? 

ToObject

(

O

).

2.  Let 

ownKeys

 be ? 

obj

.[[OwnPropertyKeys]]().

3.  Let 

descriptors

 be ! 

OrdinaryObjectCreate

(

%Object.prototype%

).

4.  For each element 

key

 of 

ownKeys

, do

a.  Let 

desc

 be ? 

obj

.[[GetOwnProperty]](

key

).

b.  Let 

descriptor

 be ! 

FromPropertyDescriptor

(

desc

).

c.  If 

descriptor

 is not 

undefined

, perform ! 

CreateDataPropertyOrThrow

(

descriptors

key

descriptor

).

5.  Return 

descriptors

.

When the 

getOwnPropertyNames

getOwnPropertyNames

 function is called, the following steps are taken:

1.  Return ? 

GetOwnPropertyKeys

(

O

string

).

When the 

getOwnPropertySymbols

getOwnPropertySymbols

 function is called with argument 

O

, the following steps are taken:

1.  Return ? 

GetOwnPropertyKeys

(

O

symbol

).

The abstract operation GetOwnPropertyKeys takes arguments 

O

 and 

type

 (either 

string

 or 

symbol

). It performs the

following steps when called:

1.  Let 

obj

 be ? 

ToObject

(

O

).

2.  Let 

keys

 be ? 

obj

.[[OwnPropertyKeys]]().

3.  Let 

nameList

 be a new empty 

List

.

4.  For each element 

nextKey

 of 

keys

, do

a.  If 

Type

(

nextKey

) is Symbol and 

type

 is 

symbol

 or 

Type

(

nextKey

) is String and 

type

 is 

string

, then

i.  Append 

nextKey

 as the last element of 

nameList

.

5.  Return 

CreateArrayFromList

(

nameList

).

When the 

getPrototypeOf

getPrototypeOf

 function is called with argument 

O

, the following steps are taken:

20.1.2.8  Object.getOwnPropertyDescriptor ( 

O

P

 )

20.1.2.9  Object.getOwnPropertyDescriptors ( 

O

 )

20.1.2.10  Object.getOwnPropertyNames ( 

O

 )

20.1.2.11  Object.getOwnPropertySymbols ( 

O

 )

20.1.2.11.1  GetOwnPropertyKeys ( 

O

type

 )

20.1.2.12  Object.getPrototypeOf ( 

O

 )

483

1.  Let 

obj

 be ? 

ToObject

(

O

).

2.  Return ? 

obj

.[[GetPrototypeOf]]().

When the 

is

is

 function is called with arguments 

value1

 and 

value2

, the following steps are taken:

1.  Return 

SameValue

(

value1

value2

).

When the 

isExtensible

isExtensible

 function is called with argument 

O

, the following steps are taken:

1.  If 

Type

(

O

) is not Object, return 

false

.

2.  Return ? 

IsExtensible

(

O

).

When the 

isFrozen

isFrozen

 function is called with argument 

O

, the following steps are taken:

1.  If 

Type

(

O

) is not Object, return 

true

.

2.  Return ? 

TestIntegrityLevel

(

O

frozen

).

When the 

isSealed

isSealed

 function is called with argument 

O

, the following steps are taken:

1.  If 

Type

(

O

) is not Object, return 

true

.

2.  Return ? 

TestIntegrityLevel

(

O

sealed

).

When the 

keys

keys

 function is called with argument 

O

, the following steps are taken:

1.  Let 

obj

 be ? 

ToObject

(

O

).

2.  Let 

nameList

 be ? 

EnumerableOwnPropertyNames

(

obj

key

).

3.  Return 

CreateArrayFromList

(

nameList

).

When the 

preventExtensions

preventExtensions

 function is called, the following steps are taken:

1.  If 

Type

(

O

) is not Object, return 

O

.

2.  Let 

status

 be ? 

O

.[[PreventExtensions]]().

3.  If 

status

 is 

false

, throw a 

TypeError

 exception.

4.  Return 

O

.

The initial value of 

Object.prototype

Object.prototype

 is the 

Object prototype object

.

20.1.2.13  Object.is ( 

value1

value2

 )

20.1.2.14  Object.isExtensible ( 

O

 )

20.1.2.15  Object.isFrozen ( 

O

 )

20.1.2.16  Object.isSealed ( 

O

 )

20.1.2.17  Object.keys ( 

O

 )

20.1.2.18  Object.preventExtensions ( 

O

 )

20.1.2.19  Object.prototype

484

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

When the 

seal

seal

 function is called, the following steps are taken:

1.  If 

Type

(

O

) is not Object, return 

O

.

2.  Let 

status

 be ? 

SetIntegrityLevel

(

O

sealed

).

3.  If 

status

 is 

false

, throw a 

TypeError

 exception.

4.  Return 

O

.

When the 

setPrototypeOf

setPrototypeOf

 function is called with arguments 

O

 and 

proto

, the following steps are taken:

1.  Set 

O

 to ? 

RequireObjectCoercible

(

O

).

2.  If 

Type

(

proto

) is neither Object nor Null, throw a 

TypeError

 exception.

3.  If 

Type

(

O

) is not Object, return 

O

.

4.  Let 

status

 be ? 

O

.[[SetPrototypeOf]](

proto

).

5.  If 

status

 is 

false

, throw a 

TypeError

 exception.

6.  Return 

O

.

When the 

values

values

 function is called with argument 

O

, the following steps are taken:

1.  Let 

obj

 be ? 

ToObject

(

O

).

2.  Let 

nameList

 be ? 

EnumerableOwnPropertyNames

(

obj

value

).

3.  Return 

CreateArrayFromList

(

nameList

).

The 

Object prototype object

:

is 

%Object.prototype%

.

has an [[Extensible]] internal slot whose value is 

true

.

has the internal methods defined for ordinary objects, except for the [[SetPrototypeOf]] method, which is as
defined in 

10.4.7.1

. (Thus, it is an 

immutable prototype exotic object

.)

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

null

.

The initial value of 

Object.prototype.constructor

Object.prototype.constructor

 is 

%Object%

.

When the 

hasOwnProperty

hasOwnProperty

 method is called with argument 

V

, the following steps are taken:

1.  Let 

P

 be ? 

ToPropertyKey

(

V

).

20.1.2.20  Object.seal ( 

O

 )

20.1.2.21  Object.setPrototypeOf ( 

O

proto

 )

20.1.2.22  Object.values ( 

O

 )

20.1.3  Properties of the Object Prototype Object

20.1.3.1  Object.prototype.constructor

20.1.3.2  Object.prototype.hasOwnProperty ( 

V

 )

485

2.  Let 

O

 be ? 

ToObject

(

this

 value).

3.  Return ? 

HasOwnProperty

(

O

P

).

NOTE

When the 

isPrototypeOf

isPrototypeOf

 method is called with argument 

V

, the following steps are taken:

1.  If 

Type

(

V

) is not Object, return 

false

.

2.  Let 

O

 be ? 

ToObject

(

this

 value).

3.  Repeat,

a.  Set 

V

 to ? 

V

.[[GetPrototypeOf]]().

b.  If 

V

 is 

null

, return 

false

.

c.  If 

SameValue

(

O

V

) is 

true

, return 

true

.

NOTE

When the 

propertyIsEnumerable

propertyIsEnumerable

 method is called with argument 

V

, the following steps are taken:

1.  Let 

P

 be ? 

ToPropertyKey

(

V

).

2.  Let 

O

 be ? 

ToObject

(

this

 value).

3.  Let 

desc

 be ? 

O

.[[GetOwnProperty]](

P

).

4.  If 

desc

 is 

undefined

, return 

false

.

5.  Return 

desc

.[[Enumerable]].

NOTE 1

NOTE 2

When the 

toLocaleString

toLocaleString

 method is called, the following steps are taken:

1.  Let 

O

 be the 

this

 value.

2.  Return ? 

Invoke

(

O

"toString"

).

The optional parameters to this function are not used but are intended to correspond to the parameter pattern used by
ECMA-402 

toLocaleString

toLocaleString

 functions. Implementations that do not include ECMA-402 support must not use

The ordering of steps 

1

 and 

2

 is chosen to ensure that any exception that would have been

thrown by step 

1

 in previous editions of this specification will continue to be thrown even if the

this

 value is 

undefined

 or 

null

.

The ordering of steps 

1

 and 

2

 preserves the behaviour specified by previous editions of this

specification for the case where 

V

 is not an object and the 

this

 value is 

undefined

 or 

null

.

This method does not consider objects in the prototype chain.

The ordering of steps 

1

 and 

2

 is chosen to ensure that any exception that would have been

thrown by step 

1

 in previous editions of this specification will continue to be thrown even if the

this

 value is 

undefined

 or 

null

.

20.1.3.3  Object.prototype.isPrototypeOf ( 

V

 )

20.1.3.4  Object.prototype.propertyIsEnumerable ( 

V

 )

20.1.3.5  Object.prototype.toLocaleString ( [ 

reserved1

 [ , 

reserved2

 ] ] )

486

those parameter positions for other purposes.

NOTE 1

NOTE 2

When the 

toString

toString

 method is called, the following steps are taken:

1.  If the 

this

 value is 

undefined

, return 

"[object Undefined]"

.

2.  If the 

this

 value is 

null

, return 

"[object Null]"

.

3.  Let 

O

 be ! 

ToObject

(

this

 value).

4.  Let 

isArray

 be ? 

IsArray

(

O

).

5.  If 

isArray

 is 

true

, let 

builtinTag

 be 

"Array"

.

6.  Else if 

O

 has a [[ParameterMap]] internal slot, let 

builtinTag

 be 

"Arguments"

.

7.  Else if 

O

 has a [[Call]] internal method, let 

builtinTag

 be 

"Function"

.

8.  Else if 

O

 has an [[ErrorData]] internal slot, let 

builtinTag

 be 

"Error"

.

9.  Else if 

O

 has a [[BooleanData]] internal slot, let 

builtinTag

 be 

"Boolean"

.

10.  Else if 

O

 has a [[NumberData]] internal slot, let 

builtinTag

 be 

"Number"

.

11.  Else if 

O

 has a [[StringData]] internal slot, let 

builtinTag

 be 

"String"

.

12.  Else if 

O

 has a [[DateValue]] internal slot, let 

builtinTag

 be 

"Date"

.

13.  Else if 

O

 has a [[RegExpMatcher]] internal slot, let 

builtinTag

 be 

"RegExp"

.

14.  Else, let 

builtinTag

 be 

"Object"

.

15.  Let 

tag

 be ? 

Get

(

O

@@toStringTag

).

16.  If 

Type

(

tag

) is not String, set 

tag

 to 

builtinTag

.

17.  Return the 

string-concatenation

 of 

"[object "

tag

, and 

"]"

.

NOTE

When the 

valueOf

valueOf

 method is called, the following steps are taken:

1.  Return ? 

ToObject

(

this

 value).

This function provides a generic 

toLocaleString

toLocaleString

 implementation for objects that have no

locale-specific 

toString

toString

 behaviour. 

Array

Array

Number

Number

Date

Date

, and 

%TypedArray%

 provide

their own locale-sensitive 

toLocaleString

toLocaleString

 methods.

ECMA-402 intentionally does not provide an alternative to this default implementation.

Historically, this function was occasionally used to access the String value of the [[Class]] internal
slot that was used in previous editions of this specification as a nominal type tag for various
built-in objects. The above definition of 

toString

toString

 preserves compatibility for legacy code that

uses 

toString

toString

 as a test for those specific kinds of built-in objects. It does not provide a reliable

type testing mechanism for other kinds of built-in or program defined objects. In addition,
programs can use 

@@toStringTag

 in ways that will invalidate the reliability of such legacy type

tests.

20.1.3.6  Object.prototype.toString ( )

20.1.3.7  Object.prototype.valueOf ( )

20.1.4  Properties of Object Instances

487

Object instances have no special properties beyond those inherited from the 

Object prototype object

.

The Function 

constructor

:

is 

%Function%

.

is the initial value of the 

"Function"

 property of the 

global object

.

creates and initializes a new 

function object

 when called as a function rather than as a 

constructor

. Thus the

function call 

Function(…)

Function(…)

 is equivalent to the object creation expression 

new Function(…)

new Function(…)

 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 Function behaviour must include a 

super

super

 call to the Function

constructor

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

behaviour. All ECMAScript syntactic forms for defining function objects create instances of Function. There is
no syntactic means to create instances of Function subclasses except for the built-in GeneratorFunction,
AsyncFunction, and AsyncGeneratorFunction subclasses.

The last argument specifies the body (executable code) of a function; any preceding arguments specify formal
parameters.

When the 

Function

Function

 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, 

normal

args

).

NOTE

The abstract operation CreateDynamicFunction takes arguments 

constructor

 (a 

constructor

), 

newTarget

 (a 

constructor

),

kind

 (either 

normal

generator

async

, or 

asyncGenerator

), and 

args

 (a 

List

 of ECMAScript language values). 

constructor

is the 

constructor

 function that is performing this action. 

newTarget

 is the 

constructor

 that 

new

new

 was initially applied to.

args

 is the argument values that were passed to 

constructor

. It performs the following steps when called:

1. 

Assert

: The 

execution context stack

 has at least two elements.

It is permissible but not necessary to have one argument for each formal parameter to be
specified. For example, all three of the following expressions produce the same result:

new

 

Function

(

"a"

"b"

"c"

"return a+b+c"

)

new

 

Function

(

"a, b, c"

"return a+b+c"

)

new

 

Function

(

"a,b"

"c"

"return a+b+c"

)

20.2  Function Objects

20.2.1  The Function Constructor

20.2.1.1  Function ( 

p1

p2

, … , 

pn

body

 )

20.2.1.1.1  CreateDynamicFunction ( 

constructor

newTarget

kind

args

 )

488

2.  Let 

callerContext

 be the second to top element of the 

execution context stack

.

3.  Let 

callerRealm

 be 

callerContext

's 

Realm

.

4.  Let 

calleeRealm

 be 

the current Realm Record

.

5.  Perform ? 

HostEnsureCanCompileStrings

(

callerRealm

calleeRealm

).

6.  If 

newTarget

 is 

undefined

, set 

newTarget

 to 

constructor

.

7.  If 

kind

 is 

normal

, then

a.  Let 

goal

 be the grammar symbol 

FunctionBody

[~Yield, ~Await]

.

b.  Let 

parameterGoal

 be the grammar symbol 

FormalParameters

[~Yield, ~Await]

.

c.  Let 

fallbackProto

 be 

"%Function.prototype%"

.

8.  Else if 

kind

 is 

generator

, then

a.  Let 

goal

 be the grammar symbol 

GeneratorBody

.

b.  Let 

parameterGoal

 be the grammar symbol 

FormalParameters

[+Yield, ~Await]

.

c.  Let 

fallbackProto

 be 

"%GeneratorFunction.prototype%"

.

9.  Else if 

kind

 is 

async

, then

a.  Let 

goal

 be the grammar symbol 

AsyncFunctionBody

.

b.  Let 

parameterGoal

 be the grammar symbol 

FormalParameters

[~Yield, +Await]

.

c.  Let 

fallbackProto

 be 

"%AsyncFunction.prototype%"

.

10.  Else,

a. 

Assert

kind

 is 

asyncGenerator

.

b.  Let 

goal

 be the grammar symbol 

AsyncGeneratorBody

.

c.  Let 

parameterGoal

 be the grammar symbol 

FormalParameters

[+Yield, +Await]

.

d.  Let 

fallbackProto

 be 

"%AsyncGeneratorFunction.prototype%"

.

11.  Let 

argCount

 be the number of elements in 

args

.

12.  Let 

P

 be the empty String.

13.  If 

argCount

 = 0, let 

bodyArg

 be the empty String.

14.  Else if 

argCount

 = 1, let 

bodyArg

 be 

args

[0].

15.  Else,

a. 

Assert

argCount

 > 1.

b.  Let 

firstArg

 be 

args

[0].

c.  Set 

P

 to ? 

ToString

(

firstArg

).

d.  Let 

k

 be 1.

e.  Repeat, while 

k

 < 

argCount

 - 1,

i.  Let 

nextArg

 be 

args

[

k

].

ii.  Let 

nextArgString

 be ? 

ToString

(

nextArg

).

iii.  Set 

P

 to the 

string-concatenation

 of 

P

","

 (a comma), and 

nextArgString

.

iv.  Set 

k

 to 

k

 + 1.

f.  Let 

bodyArg

 be 

args

[

k

].

16.  Let 

bodyString

 be the 

string-concatenation

 of 0x000A (LINE FEED), ? 

ToString

(

bodyArg

), and 0x000A (LINE

FEED).

17.  Let 

prefix

 be the prefix associated with 

kind

 in 

Table 50

.

18.  Let 

sourceString

 be the 

string-concatenation

 of 

prefix

" anonymous("

P

, 0x000A (LINE FEED), 

") {"

bodyString

,

and 

"}"

.

19.  Let 

sourceText

 be ! 

StringToCodePoints

(

sourceString

).

20.  Perform the following substeps in an 

implementation-defined

 order, possibly interleaving parsing and error

detection:

a.  Let 

parameters

 be 

ParseText

(! 

StringToCodePoints

(

P

), 

parameterGoal

).

b.  If 

parameters

 is a 

List

 of errors, throw a 

SyntaxError

 exception.

489

c.  Let 

body

 be 

ParseText

(! 

StringToCodePoints

(

bodyString

), 

goal

).

d.  If 

body

 is a 

List

 of errors, throw a 

SyntaxError

 exception.

e.  Let 

strict

 be 

FunctionBodyContainsUseStrict

 of 

body

.

f.  If 

strict

 is 

true

, apply the 

early error

 rules for 

UniqueFormalParameters

 

:

 

FormalParameters

 to 

parameters

.

g.  If 

strict

 is 

true

 and 

IsSimpleParameterList

 of 

parameters

 is 

false

, throw a 

SyntaxError

 exception.

h.  If any element of the 

BoundNames

 of 

parameters

 also occurs in the 

LexicallyDeclaredNames

 of 

body

,

throw a 

SyntaxError

 exception.

i.  If 

body

 

Contains

 

SuperCall

 is 

true

, throw a 

SyntaxError

 exception.

j.  If 

parameters

 

Contains

 

SuperCall

 is 

true

, throw a 

SyntaxError

 exception.

k.  If 

body

 

Contains

 

SuperProperty

 is 

true

, throw a 

SyntaxError

 exception.

l.  If 

parameters

 

Contains

 

SuperProperty

 is 

true

, throw a 

SyntaxError

 exception.

m.  If 

kind

 is 

generator

 or 

asyncGenerator

, then

i.  If 

parameters

 

Contains

 

YieldExpression

 is 

true

, throw a 

SyntaxError

 exception.

n.  If 

kind

 is 

async

 or 

asyncGenerator

, then

i.  If 

parameters

 

Contains

 

AwaitExpression

 is 

true

, throw a 

SyntaxError

 exception.

o.  If 

strict

 is 

true

, then

i.  If 

BoundNames

 of 

parameters

 contains any duplicate elements, throw a 

SyntaxError

 exception.

21.  Let 

proto

 be ? 

GetPrototypeFromConstructor

(

newTarget

fallbackProto

).

22.  Let 

realmF

 be 

the current Realm Record

.

23.  Let 

scope

 be 

realmF

.[[GlobalEnv]].

24.  Let 

F

 be ! 

OrdinaryFunctionCreate

(

proto

sourceText

parameters

body

non-lexical-this

scope

).

25.  Perform 

SetFunctionName

(

F

"anonymous"

).

26.  If 

kind

 is 

generator

, then

a.  Let 

prototype

 be ! 

OrdinaryObjectCreate

(

%GeneratorFunction.prototype.prototype%

).

b.  Perform 

DefinePropertyOrThrow

(

F

"prototype"

, PropertyDescriptor { [[Value]]: 

prototype

, [[Writable]]:

true

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }).

27.  Else if 

kind

 is 

asyncGenerator

, then

a.  Let 

prototype

 be ! 

OrdinaryObjectCreate

(

%AsyncGeneratorFunction.prototype.prototype%

).

b.  Perform 

DefinePropertyOrThrow

(

F

"prototype"

, PropertyDescriptor { [[Value]]: 

prototype

, [[Writable]]:

true

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }).

28.  Else if 

kind

 is 

normal

, perform 

MakeConstructor

(

F

).

29.  NOTE: Functions whose 

kind

 is 

async

 are not constructible and do not have a [[Construct]] internal method or

"prototype"

 property.

30.  Return 

F

.

NOTE

Table 50: Dynamic Function SourceText Prefixes

Kind

Prefix

normal

"function"

generator

"function*"

async

"async function"

asyncGenerator

"async function*"

CreateDynamicFunction defines a 

"prototype"

 property on any function it creates whose 

kind

 is

not 

async

 to provide for the possibility that the function will be used as a 

constructor

.

490

The Function 

constructor

:

is itself a built-in 

function object

.

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

%Function.prototype%

.

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 value of 

Function.prototype

Function.prototype

 is the 

Function prototype object

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The 

Function prototype object

:

is 

%Function.prototype%

.

is itself a built-in 

function object

.

accepts any arguments and returns 

undefined

 when invoked.

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

constructor

 with the 

new

new

 operator.

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

%Object.prototype%

.

does not have a 

"prototype"

 property.

has a 

"length"

 property whose value is 

+0

𝔽

.

has a 

"name"

 property whose value is the empty String.

NOTE

When the 

apply

apply

 method is called with arguments 

thisArg

 and 

argArray

, the following steps are taken:

1.  Let 

func

 be the 

this

 value.

2.  If 

IsCallable

(

func

) is 

false

, throw a 

TypeError

 exception.

3.  If 

argArray

 is 

undefined

 or 

null

, then

a.  Perform 

PrepareForTailCall

().

b.  Return ? 

Call

(

func

thisArg

).

4.  Let 

argList

 be ? 

CreateListFromArrayLike

(

argArray

).

5.  Perform 

PrepareForTailCall

().

6.  Return ? 

Call

(

func

thisArg

argList

).

The Function prototype object is specified to be a 

function object

 to ensure compatibility with

ECMAScript code that was created prior to the ECMAScript 2015 specification.

20.2.2  Properties of the Function Constructor

20.2.2.1  Function.length

20.2.2.2  Function.prototype

20.2.3  Properties of the Function Prototype Object

20.2.3.1  Function.prototype.apply ( 

thisArg

argArray

 )

491

NOTE 1

NOTE 2

When the 

bind

bind

 method is called with argument 

thisArg

 and zero or more 

args

, it performs the following steps:

1.  Let 

Target

 be the 

this

 value.

2.  If 

IsCallable

(

Target

) is 

false

, throw a 

TypeError

 exception.

3.  Let 

F

 be ? 

BoundFunctionCreate

(

Target

thisArg

args

).

4.  Let 

L

 be 0.

5.  Let 

targetHasLength

 be ? 

HasOwnProperty

(

Target

"length"

).

6.  If 

targetHasLength

 is 

true

, then

a.  Let 

targetLen

 be ? 

Get

(

Target

"length"

).

b.  If 

Type

(

targetLen

) is Number, then

i.  If 

targetLen

 is 

+

𝔽

, set 

L

 to +

.

ii.  Else if 

targetLen

 is 

-

𝔽

, set 

L

 to 0.

iii.  Else,

1.  Let 

targetLenAsInt

 be ! 

ToIntegerOrInfinity

(

targetLen

).

2. 

Assert

targetLenAsInt

 is finite.

3.  Let 

argCount

 be the number of elements in 

args

.

4.  Set 

L

 to 

max

(

targetLenAsInt

 - 

argCount

, 0).

7.  Perform ! 

SetFunctionLength

(

F

L

).

8.  Let 

targetName

 be ? 

Get

(

Target

"name"

).

9.  If 

Type

(

targetName

) is not String, set 

targetName

 to the empty String.

10.  Perform 

SetFunctionName

(

F

targetName

"bound"

).

11.  Return 

F

.

NOTE 1

NOTE 2

When the 

call

call

 method is called with argument 

thisArg

 and zero or more 

args

, the following steps are taken:

1.  Let 

func

 be the 

this

 value.

The 

thisArg

 value is passed without modification as the 

this

 value. This is a change from Edition

3, where an 

undefined

 or 

null

 

thisArg

 is replaced with the 

global object

 and 

ToObject

 is applied

to all other values and that result is passed as the 

this

 value. Even though the 

thisArg

 is passed

without modification, non-strict functions still perform these transformations upon entry to the
function.

If 

func

 is an arrow function or a 

bound function exotic object

 then the 

thisArg

 will be ignored by

the function [[Call]] in step 

6

.

Function objects created using 

Function.prototype.bind

Function.prototype.bind

 are exotic objects. They also do

not have a 

"prototype"

 property.

If 

Target

 is an arrow function or a 

bound function exotic object

 then the 

thisArg

 passed to this

method will not be used by subsequent calls to 

F

.

20.2.3.2  Function.prototype.bind ( 

thisArg

, ...

args

 )

20.2.3.3  Function.prototype.call ( 

thisArg

, ...

args

 )

492

2.  If 

IsCallable

(

func

) is 

false

, throw a 

TypeError

 exception.

3.  Perform 

PrepareForTailCall

().

4.  Return ? 

Call

(

func

thisArg

args

).

NOTE 1

NOTE 2

The initial value of 

Function.prototype.constructor

Function.prototype.constructor

 is 

%Function%

.

When the 

toString

toString

 method is called, the following steps are taken:

1.  Let 

func

 be the 

this

 value.

2.  If 

Type

(

func

) is Object and 

func

 has a [[SourceText]] internal slot and 

func

.[[SourceText]] is a sequence of

Unicode code points and ! 

HostHasSourceTextAvailable

(

func

) is 

true

, then

a.  Return ! 

CodePointsToString

(

func

.[[SourceText]]).

3.  If 

func

 is a 

built-in function object

, return an 

implementation-defined

 String source code representation of 

func

.

The representation must have the syntax of a 

NativeFunction

. Additionally, if 

func

 has an [[InitialName]]

internal slot and 

func

.[[InitialName]] is a String, the portion of the returned String that would be matched by 

NativeFunctionAccessor

opt

 

PropertyName

 must be the value of 

func

.[[InitialName]].

4.  If 

Type

(

func

) is Object and 

IsCallable

(

func

) is 

true

, return an 

implementation-defined

 String source code

representation of 

func

. The representation must have the syntax of a 

NativeFunction

.

5.  Throw a 

TypeError

 exception.

NativeFunction

 

:

function

 

NativeFunctionAccessor

opt

 

PropertyName

[~Yield, ~Await]

opt

 

(

FormalParameters

[~Yield, ~Await]

 

)

 

{

 

[

 

native

 

code

 

]

 

}

NativeFunctionAccessor

 

:

get

set

When the 

@@hasInstance

@@hasInstance

 method of an object 

F

 is called with value 

V

, the following steps are taken:

1.  Let 

F

 be the 

this

 value.

2.  Return ? 

OrdinaryHasInstance

(

F

V

).

The 

thisArg

 value is passed without modification as the 

this

 value. This is a change from Edition

3, where an 

undefined

 or 

null

 

thisArg

 is replaced with the 

global object

 and 

ToObject

 is applied

to all other values and that result is passed as the 

this

 value. Even though the 

thisArg

 is passed

without modification, non-strict functions still perform these transformations upon entry to the
function.

If 

func

 is an arrow function or a 

bound function exotic object

 then the 

thisArg

 will be ignored by

the function [[Call]] in step 

4

.

20.2.3.4  Function.prototype.constructor

20.2.3.5  Function.prototype.toString ( )

20.2.3.6  Function.prototype [ @@hasInstance ] ( 

V

 )

493

The value of the 

"name"

 property of this function is 

"[Symbol.hasInstance]"

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

NOTE

This property is non-writable and non-configurable to prevent tampering that could be used to globally expose the
target function of a bound function.

Every Function instance is an ECMAScript 

function object

 and has the internal slots listed in 

Table 29

. Function objects

created using the 

Function.prototype.bind

Function.prototype.bind

 method (

20.2.3.2

) have the internal slots listed in 

Table 30

.

Function instances have the following properties:

The value of the 

"length"

 property is an 

integral Number

 that indicates the typical number of arguments expected by

the function. However, the language permits the function to be invoked with some other number of arguments. The
behaviour of a function when invoked on a number of arguments other than the number specified by its 

"length"

property depends on the function. This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

,

[[Configurable]]: 

true

 }.

The value of the 

"name"

 property is a String that is descriptive of the function. The name has no semantic significance

but is typically a variable or 

property name

 that is used to refer to the function at its point of definition in ECMAScript

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

Anonymous functions objects that do not have a contextual name associated with them by this specification use the
empty String as the value of the 

"name"

 property.

Function instances that can be used as a 

constructor

 have a 

"prototype"

 property. Whenever such a Function instance

is created another 

ordinary object

 is also created and is the initial value of the function's 

"prototype"

 property. Unless

otherwise specified, the value of the 

"prototype"

 property is used to initialize the [[Prototype]] internal slot of the

object created when that function is invoked as a 

constructor

.

This is the default implementation of 

@@hasInstance

@@hasInstance

 that most functions inherit.

@@hasInstance

@@hasInstance

 is called by the 

instanceof

instanceof

 operator to determine whether a value is an

instance of a specific 

constructor

. An expression such as

evaluates as

constructor

 function can control which objects are recognized as its instances by

instanceof

instanceof

 by exposing a different 

@@hasInstance

@@hasInstance

 method on the function.

instanceof

 F

F[@@hasInstance](v)

20.2.4  Function Instances

20.2.4.1  length

20.2.4.2  name

20.2.4.3  prototype

494

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

true

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

NOTE

The 

host-defined

 abstract operation HostHasSourceTextAvailable takes argument 

func

 (a 

function object

). It allows

host

 environments to prevent the source text from being provided for 

func

.

An implementation of HostHasSourceTextAvailable must complete normally in all cases. This operation must be
deterministic with respect to its parameters. Each time it is called with a specific 

func

 as its argument, it must return

the same completion record. The default implementation of HostHasSourceTextAvailable is to unconditionally return
a normal completion with a value of 

true

.

The Boolean 

constructor

:

is 

%Boolean%

.

is the initial value of the 

"Boolean"

 property of the 

global object

.

creates and initializes a new Boolean object when called as a 

constructor

.

performs a type conversion when called as a function rather than as a 

constructor

.

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 Boolean behaviour must include a 

super

super

 call to the Boolean

constructor

 to create and initialize the subclass instance with a [[BooleanData]] internal slot.

When 

Boolean

Boolean

 is called with argument 

value

, the following steps are taken:

1.  Let 

b

 be ! 

ToBoolean

(

value

).

2.  If NewTarget is 

undefined

, return 

b

.

3.  Let 

O

 be ? 

OrdinaryCreateFromConstructor

(NewTarget, 

"%Boolean.prototype%"

, « [[BooleanData]] »).

4.  Set 

O

.[[BooleanData]] to 

b

.

5.  Return 

O

.

The Boolean 

constructor

:

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

%Function.prototype%

.

has the following properties:

Function objects created using 

Function.prototype.bind

Function.prototype.bind

, or by evaluating a 

MethodDefinition

 (that is not a 

GeneratorMethod

 or 

AsyncGeneratorMethod

) or an 

ArrowFunction

 do

not have a 

"prototype"

 property.

20.2.5  HostHasSourceTextAvailable ( 

func

 )

20.3  Boolean Objects

20.3.1  The Boolean Constructor

20.3.1.1  Boolean ( 

value

 )

20.3.2  Properties of the Boolean Constructor

495

 

 

 

 

 

 

 

Content      ..     28      29      30      31     ..