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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     45      46      47      48     ..

 

 

 

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

 

 

1.  Return 0.

FormalParameters

 

:

 

FormalParameterList

 

,

 

FunctionRestParameter

1.  Return 

ExpectedArgumentCount

 of 

FormalParameterList

.

NOTE

FormalParameterList

 

:

 

FormalParameter

1.  If 

HasInitializer

 of 

FormalParameter

 is 

true

, return 0.

2.  Return 1.

FormalParameterList

 

:

 

FormalParameterList

 

,

 

FormalParameter

1.  Let 

count

 be 

ExpectedArgumentCount

 of 

FormalParameterList

.

2.  If 

HasInitializer

 of 

FormalParameterList

 is 

true

 or 

HasInitializer

 of 

FormalParameter

 is 

true

, return 

count

.

3.  Return 

count

 + 1.

ArrowParameters

 

:

 

BindingIdentifier

1.  Return 1.

ArrowParameters

 

:

 

CoverParenthesizedExpressionAndArrowParameterList

1.  Let 

formals

 be 

CoveredFormalsList

 of 

CoverParenthesizedExpressionAndArrowParameterList

.

2.  Return 

ExpectedArgumentCount

 of 

formals

.

PropertySetParameterList

 

:

 

FormalParameter

1.  If 

HasInitializer

 of 

FormalParameter

 is 

true

, return 0.

2.  Return 1.

AsyncArrowBindingIdentifier

 

:

 

BindingIdentifier

1.  Return 1.

FunctionDeclaration

[Yield, Await, Default]

 

:

function

 

BindingIdentifier

[?Yield, ?Await]

 

(

 

FormalParameters

[~Yield, ~Await]

 

)

 

{

FunctionBody

[~Yield, ~Await]

 

}

[+Default]

 

function

 

(

 

FormalParameters

[~Yield, ~Await]

 

)

 

{

 

FunctionBody

[~Yield, ~Await]

 

}

FunctionExpression

 

:

The ExpectedArgumentCount of a 

FormalParameterList

 is the number of 

FormalParameters

 to the

left of either the rest parameter or the first 

FormalParameter

 with an Initializer. A 

FormalParameter

without an initializer is allowed after the first parameter with an initializer but such parameters
are considered to be optional with 

undefined

 as their default value.

15.2  Function Definitions

Syntax

394

function

 

BindingIdentifier

[~Yield, ~Await]

opt

 

(

 

FormalParameters

[~Yield, ~Await]

 

)

 

{

FunctionBody

[~Yield, ~Await]

 

}

FunctionBody

[Yield, Await]

 

:

FunctionStatementList

[?Yield, ?Await]

FunctionStatementList

[Yield, Await]

 

:

StatementList

[?Yield, ?Await, +Return]

opt

FunctionDeclaration

 

:

function

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

function

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

FunctionExpression

 

:

function

 

BindingIdentifier

opt

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

If the source code matching 

FormalParameters

 is 

strict mode code

, the Early Error rules for

UniqueFormalParameters

 

:

 

FormalParameters

 are applied.

If 

BindingIdentifier

 is present and the source code matching 

BindingIdentifier

 is 

strict mode code

, it is a Syntax

Error if the 

StringValue

 of 

BindingIdentifier

 is 

"eval"

 or 

"arguments"

.

It is a Syntax Error if 

FunctionBodyContainsUseStrict

 of 

FunctionBody

 is 

true

 and 

IsSimpleParameterList

 of 

FormalParameters

 is 

false

.

It is a Syntax Error if any element of the 

BoundNames

 of 

FormalParameters

 also occurs in the

LexicallyDeclaredNames

 of 

FunctionBody

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

SuperProperty

 is 

true

.

It is a Syntax Error if 

FunctionBody

 

Contains

 

SuperProperty

 is 

true

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

SuperCall

 is 

true

.

It is a Syntax Error if 

FunctionBody

 

Contains

 

SuperCall

 is 

true

.

NOTE

FunctionBody

 

:

 

FunctionStatementList

It is a Syntax Error if the 

LexicallyDeclaredNames

 of 

FunctionStatementList

 contains any duplicate entries.

It is a Syntax Error if any element of the 

LexicallyDeclaredNames

 of 

FunctionStatementList

 also occurs in the

VarDeclaredNames

 of 

FunctionStatementList

.

It is a Syntax Error if 

ContainsDuplicateLabels

 of 

FunctionStatementList

 with argument « » is 

true

.

It is a Syntax Error if 

ContainsUndefinedBreakTarget

 of 

FunctionStatementList

 with argument « » is 

true

.

It is a Syntax Error if 

ContainsUndefinedContinueTarget

 of 

FunctionStatementList

 with arguments « » and « » is

true

.

FunctionBody

 

:

 

FunctionStatementList

1.  If the 

Directive Prologue

 of 

FunctionBody

 contains a 

Use Strict Directive

, return 

true

; otherwise, return 

false

.

The 

LexicallyDeclaredNames

 of a 

FunctionBody

 does not include identifiers bound using var or

function declarations.

15.2.1  Static Semantics: Early Errors

15.2.2  Static Semantics: FunctionBodyContainsUseStrict

395

With parameters 

functionObject

 and 

argumentsList

 (a 

List

).

FunctionBody

 

:

 

FunctionStatementList

1.  Perform ? 

FunctionDeclarationInstantiation

(

functionObject

argumentsList

).

2.  Return the result of evaluating 

FunctionStatementList

.

With parameter 

scope

.

FunctionDeclaration

 

:

 

function

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

1.  Let 

name

 be 

StringValue

 of 

BindingIdentifier

.

2.  Let 

sourceText

 be the source text matched by 

FunctionDeclaration

.

3.  Let 

F

 be 

OrdinaryFunctionCreate

(

%Function.prototype%

sourceText

FormalParameters

FunctionBody

non-

lexical-this

scope

).

4.  Perform 

SetFunctionName

(

F

name

).

5.  Perform 

MakeConstructor

(

F

).

6.  Return 

F

.

FunctionDeclaration

 

:

 

function

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

1.  Let 

sourceText

 be the source text matched by 

FunctionDeclaration

.

2.  Let 

F

 be 

OrdinaryFunctionCreate

(

%Function.prototype%

sourceText

FormalParameters

FunctionBody

non-

lexical-this

scope

).

3.  Perform 

SetFunctionName

(

F

"default"

).

4.  Perform 

MakeConstructor

(

F

).

5.  Return 

F

.

NOTE

With optional parameter 

name

.

FunctionExpression

 

:

 

function

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

1.  If 

name

 is not present, set 

name

 to 

""

.

2.  Let 

scope

 be the LexicalEnvironment of the 

running execution context

.

3.  Let 

sourceText

 be the source text matched by 

FunctionExpression

.

4.  Let 

closure

 be 

OrdinaryFunctionCreate

(

%Function.prototype%

sourceText

FormalParameters

FunctionBody

non-

lexical-this

scope

).

5.  Perform 

SetFunctionName

(

closure

name

).

6.  Perform 

MakeConstructor

(

closure

).

7.  Return 

closure

.

An anonymous 

FunctionDeclaration

 can only occur as part of an 

export default

export default

declaration, and its function code is therefore always 

strict mode code

.

15.2.3  Runtime Semantics: EvaluateFunctionBody

15.2.4  Runtime Semantics: InstantiateOrdinaryFunctionObject

15.2.5  Runtime Semantics: InstantiateOrdinaryFunctionExpression

396

FunctionExpression

 

:

 

function

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

1. 

Assert

name

 is not present.

2.  Set 

name

 to 

StringValue

 of 

BindingIdentifier

.

3.  Let 

scope

 be the 

running execution context

's LexicalEnvironment.

4.  Let 

funcEnv

 be 

NewDeclarativeEnvironment

(

scope

).

5.  Perform 

funcEnv

.CreateImmutableBinding(

name

false

).

6.  Let 

sourceText

 be the source text matched by 

FunctionExpression

.

7.  Let 

closure

 be 

OrdinaryFunctionCreate

(

%Function.prototype%

sourceText

FormalParameters

FunctionBody

non-

lexical-this

funcEnv

).

8.  Perform 

SetFunctionName

(

closure

name

).

9.  Perform 

MakeConstructor

(

closure

).

10.  Perform 

funcEnv

.InitializeBinding(

name

closure

).

11.  Return 

closure

.

NOTE

FunctionDeclaration

 

:

 

function

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

1.  Return 

NormalCompletion

(

empty

).

NOTE 1

FunctionDeclaration

 

:

 

function

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

1.  Return 

NormalCompletion

(

empty

).

FunctionExpression

 

:

 

function

 

BindingIdentifier

opt

 

(

 

FormalParameters

 

)

 

{

 

FunctionBody

 

}

1.  Return 

InstantiateOrdinaryFunctionExpression

 of 

FunctionExpression

.

NOTE 2

FunctionStatementList

 

:

  [empty]

1.  Return 

NormalCompletion

(

undefined

).

The 

BindingIdentifier

 in a 

FunctionExpression

 can be referenced from inside the 

FunctionExpression

's

FunctionBody

 to allow the function to call itself recursively. However, unlike in a 

FunctionDeclaration

, the 

BindingIdentifier

 in a 

FunctionExpression

 cannot be referenced from and

does not affect the scope enclosing the 

FunctionExpression

.

An alternative semantics is provided in 

B.3.3

.

"prototype"

 property is automatically created for every function defined using a 

FunctionDeclaration

 or 

FunctionExpression

, to allow for the possibility that the function will be

used as a 

constructor

.

15.2.6  Runtime Semantics: Evaluation

15.3  Arrow Function Definitions

Syntax

397

ArrowFunction

[In, Yield, Await]

 

:

ArrowParameters

[?Yield, ?Await]

 [no 

LineTerminator

 here]  

=>

 

ConciseBody

[?In]

ArrowParameters

[Yield, Await]

 

:

BindingIdentifier

[?Yield, ?Await]

CoverParenthesizedExpressionAndArrowParameterList

[?Yield, ?Await]

ConciseBody

[In]

 

:

[lookahead 

 

{

 

ExpressionBody

[?In, ~Await]

{

 

FunctionBody

[~Yield, ~Await]

 

}

ExpressionBody

[In, Await]

 

:

AssignmentExpression

[?In, ~Yield, ?Await]

When processing an instance of the production 

ArrowParameters

[Yield, Await]

 

:

 

CoverParenthesizedExpressionAndArrowParameterList

[?Yield, ?Await]

 

the interpretation of 

CoverParenthesizedExpressionAndArrowParameterList

 is refined using the following grammar:

ArrowFormalParameters

[Yield, Await]

 

:

(

 

UniqueFormalParameters

[?Yield, ?Await]

 

)

ArrowFunction

 

:

 

ArrowParameters

 

=>

 

ConciseBody

It is a Syntax Error if 

ArrowParameters

 

Contains

 

YieldExpression

 is 

true

.

It is a Syntax Error if 

ArrowParameters

 

Contains

 

AwaitExpression

 is 

true

.

It is a Syntax Error if 

ConciseBodyContainsUseStrict

 of 

ConciseBody

 is 

true

 and 

IsSimpleParameterList

 of 

ArrowParameters

 is 

false

.

It is a Syntax Error if any element of the 

BoundNames

 of 

ArrowParameters

 also occurs in the

LexicallyDeclaredNames

 of 

ConciseBody

.

ArrowParameters

 

:

 

CoverParenthesizedExpressionAndArrowParameterList

It is a Syntax Error if 

CoverParenthesizedExpressionAndArrowParameterList

 is not 

covering

 an 

ArrowFormalParameters

.

All 

early error

 rules for 

ArrowFormalParameters

 and its derived productions also apply to 

CoveredFormalsList

of 

CoverParenthesizedExpressionAndArrowParameterList

.

ConciseBody

 

:

 

ExpressionBody

1.  Return 

false

.

ConciseBody

 

:

 

{

 

FunctionBody

 

}

1.  Return 

FunctionBodyContainsUseStrict

 of 

FunctionBody

.

Supplemental Syntax

15.3.1  Static Semantics: Early Errors

15.3.2  Static Semantics: ConciseBodyContainsUseStrict

398

ArrowParameters

 

:

 

BindingIdentifier

1.  Return this 

ArrowParameters

.

CoverParenthesizedExpressionAndArrowParameterList

 

:

(

 

Expression

 

)

(

 

Expression

 

,

 

)

(

 

)

(

 

...

 

BindingIdentifier

 

)

(

 

...

 

BindingPattern

 

)

(

 

Expression

 

,

 

...

 

BindingIdentifier

 

)

(

 

Expression

 

,

 

...

 

BindingPattern

 

)

1.  Return the 

ArrowFormalParameters

 that is 

covered

 by 

CoverParenthesizedExpressionAndArrowParameterList

.

With parameters 

functionObject

 and 

argumentsList

 (a 

List

).

ConciseBody

 

:

 

ExpressionBody

1.  Perform ? 

FunctionDeclarationInstantiation

(

functionObject

argumentsList

).

2.  Return the result of evaluating 

ExpressionBody

.

With optional parameter 

name

.

ArrowFunction

 

:

 

ArrowParameters

 

=>

 

ConciseBody

1.  If 

name

 is not present, set 

name

 to 

""

.

2.  Let 

scope

 be the LexicalEnvironment of the 

running execution context

.

3.  Let 

sourceText

 be the source text matched by 

ArrowFunction

.

4.  Let 

parameters

 be 

CoveredFormalsList

 of 

ArrowParameters

.

5.  Let 

closure

 be 

OrdinaryFunctionCreate

(

%Function.prototype%

sourceText

parameters

ConciseBody

lexical-this

,

scope

).

6.  Perform 

SetFunctionName

(

closure

name

).

7.  Return 

closure

.

NOTE

An 

ArrowFunction

 does not define local bindings for 

arguments

arguments

super

super

this

this

, or

new.target

new.target

. Any reference to 

arguments

arguments

super

super

this

this

, or 

new.target

new.target

 within an 

ArrowFunction

 must resolve to a binding in a lexically enclosing environment. Typically this will

be the Function Environment of an immediately enclosing function. Even though an 

ArrowFunction

 may contain references to 

super

super

, the 

function object

 created in step 

5

 is not made

into a method by performing 

MakeMethod

. An 

ArrowFunction

 that references 

super

super

 is always

contained within a non-

ArrowFunction

 and the necessary state to implement 

super

super

 is accessible

via the 

scope

 that is captured by the 

function object

 of the 

ArrowFunction

.

15.3.3  Static Semantics: CoveredFormalsList

15.3.4  Runtime Semantics: EvaluateConciseBody

15.3.5  Runtime Semantics: InstantiateArrowFunctionExpression

399

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.replace

Symbol.replace

 is the well-known symbol 

@@replace

 (

Table 1

).

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.search

Symbol.search

 is the well-known symbol 

@@search

 (

Table 1

).

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.species

Symbol.species

 is the well-known symbol 

@@species

 (

Table 1

).

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.split

Symbol.split

 is the well-known symbol 

@@split

 (

Table 1

).

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.toPrimitive

Symbol.toPrimitive

 is the well-known symbol 

@@toPrimitive

 (

Table 1

).

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.toStringTag

Symbol.toStringTag

 is the well-known symbol 

@@toStringTag

 (

Table 1

).

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.unscopables

Symbol.unscopables

 is the well-known symbol 

@@unscopables

 (

Table 1

).

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The 

Symbol prototype object

:

is 

%Symbol.prototype%

.

is an 

ordinary object

.

20.4.2.10  Symbol.replace

20.4.2.11  Symbol.search

20.4.2.12  Symbol.species

20.4.2.13  Symbol.split

20.4.2.14  Symbol.toPrimitive

20.4.2.15  Symbol.toStringTag

20.4.2.16  Symbol.unscopables

20.4.3  Properties of the Symbol Prototype Object

499

is not a Symbol instance and does not have a [[SymbolData]] internal slot.
has a [[Prototype]] internal slot whose value is 

%Object.prototype%

.

The abstract operation 

thisSymbolValue

 takes argument 

value

. It performs the following steps when called:

1.  If 

Type

(

value

) is Symbol, return 

value

.

2.  If 

Type

(

value

) is Object and 

value

 has a [[SymbolData]] internal slot, then

a.  Let 

s

 be 

value

.[[SymbolData]].

b. 

Assert

Type

(

s

) is Symbol.

c.  Return 

s

.

3.  Throw a 

TypeError

 exception.

The initial value of 

Symbol.prototype.constructor

Symbol.prototype.constructor

 is 

%Symbol%

.

Symbol.prototype.description

Symbol.prototype.description

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get

accessor function performs the following steps:

1.  Let 

s

 be the 

this

 value.

2.  Let 

sym

 be ? 

thisSymbolValue

(

s

).

3.  Return 

sym

.[[Description]].

The following steps are taken:

1.  Let 

sym

 be ? 

thisSymbolValue

(

this

 value).

2.  Return 

SymbolDescriptiveString

(

sym

).

The abstract operation SymbolDescriptiveString takes argument 

sym

. It performs the following steps when called:

1. 

Assert

Type

(

sym

) is Symbol.

2.  Let 

desc

 be 

sym

's [[Description]] value.

3.  If 

desc

 is 

undefined

, set 

desc

 to the empty String.

4. 

Assert

Type

(

desc

) is String.

5.  Return the 

string-concatenation

 of 

"Symbol("

desc

, and 

")"

.

The following steps are taken:

1.  Return ? 

thisSymbolValue

(

this

 value).

20.4.3.1  Symbol.prototype.constructor

20.4.3.2  get Symbol.prototype.description

20.4.3.3  Symbol.prototype.toString ( )

20.4.3.3.1  SymbolDescriptiveString ( 

sym

 )

20.4.3.4  Symbol.prototype.valueOf ( )

20.4.3.5  Symbol.prototype [ @@toPrimitive ] ( 

hint

 )

500

This function is called by ECMAScript language operators to convert a Symbol object to a primitive value.

When the 

@@toPrimitive

@@toPrimitive

 method is called with argument 

hint

, the following steps are taken:

1.  Return ? 

thisSymbolValue

(

this

 value).

The value of the 

"name"

 property of this function is 

"[Symbol.toPrimitive]"

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

NOTE

The initial value of the 

@@toStringTag

 property is the String value 

"Symbol"

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

Symbol instances are ordinary objects that inherit properties from the 

Symbol prototype object

. Symbol instances have

a [[SymbolData]] internal slot. The [[SymbolData]] internal slot is the Symbol value represented by this Symbol object.

Instances of Error objects are thrown as exceptions when runtime errors occur. The Error objects may also serve as
base objects for user-defined exception classes.

When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the 

NativeError

objects defined in 

20.5.5

 or a new instance of AggregateError object defined in 

20.5.7

. Each of these objects has the

structure described below, differing only in the name used as the 

constructor

 name instead of 

NativeError

, in the 

name

name

property of the prototype object, in the 

implementation-defined

 

message

message

 property of the prototype object, and in

the presence of the 

%AggregateError%

-specific 

errors

errors

 property.

The Error 

constructor

:

is 

%Error%

.

is the initial value of the 

"Error"

 property of the 

global object

.

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

constructor

. Thus the

function call 

Error(…)

Error(…)

 is equivalent to the object creation expression 

new Error(…)

new Error(…)

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

super

super

 call to the Error

constructor

 to create and initialize subclass instances with an [[ErrorData]] internal slot.

The argument is ignored.

20.4.3.6  Symbol.prototype [ @@toStringTag ]

20.4.4  Properties of Symbol Instances

20.5  Error Objects

20.5.1  The Error Constructor

20.5.1.1  Error ( 

message

 )

501

When the 

Error

Error

 function is called with argument 

message

, the following steps are taken:

1.  If NewTarget is 

undefined

, let 

newTarget

 be the 

active function object

; else let 

newTarget

 be NewTarget.

2.  Let 

O

 be ? 

OrdinaryCreateFromConstructor

(

newTarget

"%Error.prototype%"

, « [[ErrorData]] »).

3.  If 

message

 is not 

undefined

, then

a.  Let 

msg

 be ? 

ToString

(

message

).

b.  Let 

msgDesc

 be the PropertyDescriptor { [[Value]]: 

msg

, [[Writable]]: 

true

, [[Enumerable]]: 

false

,

[[Configurable]]: 

true

 }.

c.  Perform ! 

DefinePropertyOrThrow

(

O

"message"

msgDesc

).

4.  Return 

O

.

The Error 

constructor

:

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

%Function.prototype%

.

has the following properties:

The initial value of 

Error.prototype

Error.prototype

 is the 

Error prototype object

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The 

Error prototype object

:

is 

%Error.prototype%

.

is an 

ordinary object

.

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

%Object.prototype%

.

The initial value of 

Error.prototype.constructor

Error.prototype.constructor

 is 

%Error%

.

The initial value of 

Error.prototype.message

Error.prototype.message

 is the empty String.

The initial value of 

Error.prototype.name

Error.prototype.name

 is 

"Error"

.

The following steps are taken:

20.5.2  Properties of the Error Constructor

20.5.2.1  Error.prototype

20.5.3  Properties of the Error Prototype Object

20.5.3.1  Error.prototype.constructor

20.5.3.2  Error.prototype.message

20.5.3.3  Error.prototype.name

20.5.3.4  Error.prototype.toString ( )

502

1.  Let 

O

 be the 

this

 value.

2.  If 

Type

(

O

) is not Object, throw a 

TypeError

 exception.

3.  Let 

name

 be ? 

Get

(

O

"name"

).

4.  If 

name

 is 

undefined

, set 

name

 to 

"Error"

; otherwise set 

name

 to ? 

ToString

(

name

).

5.  Let 

msg

 be ? 

Get

(

O

"message"

).

6.  If 

msg

 is 

undefined

, set 

msg

 to the empty String; otherwise set 

msg

 to ? 

ToString

(

msg

).

7.  If 

name

 is the empty String, return 

msg

.

8.  If 

msg

 is the empty String, return 

name

.

9.  Return the 

string-concatenation

 of 

name

, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE), and

msg

.

Error instances are ordinary objects that inherit properties from the 

Error prototype object

 and have an [[ErrorData]]

internal slot whose value is 

undefined

. The only specified uses of [[ErrorData]] is to identify Error, AggregateError,

and 

NativeError

 instances as Error objects within 

Object.prototype.toString

Object.prototype.toString

.

A new instance of one of the 

NativeError

 objects below or of the AggregateError object is thrown when a runtime error

is detected. All 

NativeError

 objects share the same structure, as described in 

20.5.6

.

The EvalError 

constructor

 is 

%EvalError%

.

This exception is not currently used within this specification. This object remains for compatibility with previous
editions of this specification.

The RangeError 

constructor

 is 

%RangeError%

.

Indicates a value that is not in the set or range of allowable values.

The ReferenceError 

constructor

 is 

%ReferenceError%

.

Indicate that an invalid reference has been detected.

The SyntaxError 

constructor

 is 

%SyntaxError%

.

Indicates that a parsing error has occurred.

20.5.4  Properties of Error Instances

20.5.5  Native Error Types Used in This Standard

20.5.5.1  EvalError

20.5.5.2  RangeError

20.5.5.3  ReferenceError

20.5.5.4  SyntaxError

20.5.5.5  TypeError

503

The TypeError 

constructor

 is 

%TypeError%

.

TypeError is used to indicate an unsuccessful operation when none of the other 

NativeError

 objects are an appropriate

indication of the failure cause.

The URIError 

constructor

 is 

%URIError%

.

Indicates that one of the global URI handling functions was used in a way that is incompatible with its definition.

When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the 

NativeError

objects defined in 

20.5.5

. Each of these objects has the structure described below, differing only in the name used as the

constructor

 name instead of 

NativeError

, in the 

"name"

 property of the prototype object, and in the 

implementation-

defined

 

"message"

 property of the prototype object.

For each error object, references to 

NativeError

 in the definition should be replaced with the appropriate error object

name from 

20.5.5

.

Each 

NativeError

 

constructor

:

creates and initializes a new 

NativeError

 object when called as a function rather than as a 

constructor

. A call of

the object as a function is equivalent to calling it as a 

constructor

 with the same arguments. Thus the function

call 

NativeError

NativeError

(…)

(…)

 is equivalent to the object creation expression 

new 

new 

NativeError

NativeError

(…)

(…)

 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 

NativeError

 behaviour must include a 

super

super

 call to the

NativeError

 

constructor

 to create and initialize subclass instances with an [[ErrorData]] internal slot.

When a 

NativeError

 function is called with argument 

message

, the following steps are taken:

1.  If NewTarget is 

undefined

, let 

newTarget

 be the 

active function object

; else let 

newTarget

 be NewTarget.

2.  Let 

O

 be ? 

OrdinaryCreateFromConstructor

(

newTarget

"%

"%

NativeError

NativeError

.prototype%"

.prototype%"

, « [[ErrorData]]

»).

3.  If 

message

 is not 

undefined

, then

a.  Let 

msg

 be ? 

ToString

(

message

).

b.  Let 

msgDesc

 be the PropertyDescriptor { [[Value]]: 

msg

, [[Writable]]: 

true

, [[Enumerable]]: 

false

,

[[Configurable]]: 

true

 }.

c.  Perform ! 

DefinePropertyOrThrow

(

O

"message"

msgDesc

).

4.  Return 

O

.

The actual value of the string passed in step 

2

 is either 

"%EvalError.prototype%"

"%RangeError.prototype%"

,

"%ReferenceError.prototype%"

"%SyntaxError.prototype%"

"%TypeError.prototype%"

, or

"%URIError.prototype%"

 corresponding to which 

NativeError

 

constructor

 is being defined.

20.5.5.6  URIError

20.5.6  

NativeError

 Object Structure

20.5.6.1  The 

NativeError

 Constructors

20.5.6.1.1  

NativeError

 ( 

message

 )

504

Each 

NativeError

 

constructor

:

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

%Error%

.

has a 

"name"

 property whose value is the String value 

"

NativeError

"

.

has the following properties:

The initial value of 

NativeError

NativeError

.prototype

.prototype

 is a 

NativeError

 prototype object (

20.5.6.3

). Each 

NativeError

constructor

 has a distinct prototype object.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

Each 

NativeError

 prototype object

:

is an 

ordinary object

.

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

%Error.prototype%

.

The initial value of the 

"constructor"

 property of the prototype for a given 

NativeError

 

constructor

 is the

corresponding intrinsic object %

NativeError

% (

20.5.6.1

).

The initial value of the 

"message"

 property of the prototype for a given 

NativeError

 

constructor

 is the empty String.

The initial value of the 

"name"

 property of the prototype for a given 

NativeError

 

constructor

 is the String value

consisting of the name of the 

constructor

 (the name used instead of 

NativeError

).

NativeError

 instances are ordinary objects that inherit properties from their 

NativeError

 prototype object and have an

[[ErrorData]] internal slot whose value is 

undefined

. The only specified use of [[ErrorData]] is by

Object.prototype.toString

Object.prototype.toString

 (

20.1.3.6

) to identify Error, AggregateError, or 

NativeError

 instances.

The AggregateError 

constructor

:

is 

%AggregateError%

.

is the initial value of the 

"AggregateError"

 property of the 

global object

.

20.5.6.2  Properties of the 

NativeError

 Constructors

20.5.6.2.1  

NativeError

.prototype

20.5.6.3  Properties of the 

NativeError

 Prototype Objects

20.5.6.3.1  

NativeError

.prototype.constructor

20.5.6.3.2  

NativeError

.prototype.message

20.5.6.3.3  

NativeError

.prototype.name

20.5.6.4  Properties of 

NativeError

 Instances

20.5.7  AggregateError Objects

20.5.7.1  The AggregateError Constructor

505

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

constructor

. Thus

the function call 

AggregateError(…)

AggregateError(…)

 is equivalent to the object creation expression

new AggregateError(…)

new AggregateError(…)

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

super

super

 call to the

AggregateError 

constructor

 to create and initialize subclass instances with an [[ErrorData]] internal slot.

When the 

AggregateError

 function is called with arguments 

errors

 and 

message

, the following steps are taken:

1.  If NewTarget is 

undefined

, let 

newTarget

 be the 

active function object

; else let 

newTarget

 be NewTarget.

2.  Let 

O

 be ? 

OrdinaryCreateFromConstructor

(

newTarget

"%AggregateError.prototype%"

, « [[ErrorData]] »).

3.  If 

message

 is not 

undefined

, then

a.  Let 

msg

 be ? 

ToString

(

message

).

b.  Let 

msgDesc

 be the PropertyDescriptor { [[Value]]: 

msg

, [[Writable]]: 

true

, [[Enumerable]]: 

false

,

[[Configurable]]: 

true

 }.

c.  Perform ! 

DefinePropertyOrThrow

(

O

"message"

msgDesc

).

4.  Let 

errorsList

 be ? 

IterableToList

(

errors

).

5.  Perform ! 

DefinePropertyOrThrow

(

O

"errors"

, PropertyDescriptor { [[Configurable]]: 

true

, [[Enumerable]]:

false

, [[Writable]]: 

true

, [[Value]]: ! 

CreateArrayFromList

(

errorsList

) }).

6.  Return 

O

.

The AggregateError 

constructor

:

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

%Error%

.

has the following properties:

The initial value of 

AggregateError.prototype

AggregateError.prototype

 is 

%AggregateError.prototype%

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The 

AggregateError prototype object

:

is 

%AggregateError.prototype%

.

is an 

ordinary object

.

is not an Error instance or an AggregateError instance and does not have an [[ErrorData]] internal slot.
has a [[Prototype]] internal slot whose value is 

%Error.prototype%

.

The initial value of 

AggregateError.prototype.constructor

AggregateError.prototype.constructor

 is 

%AggregateError%

.

20.5.7.1.1  AggregateError ( 

errors

message

 )

20.5.7.2  Properties of the AggregateError Constructor

20.5.7.2.1  AggregateError.prototype

20.5.7.3  Properties of the AggregateError Prototype Object

20.5.7.3.1  AggregateError.prototype.constructor

20.5.7.3.2  AggregateError.prototype.message

506

The initial value of 

AggregateError.prototype.message

AggregateError.prototype.message

 is the empty String.

The initial value of 

AggregateError.prototype.name

AggregateError.prototype.name

 is 

"AggregateError"

.

AggregateError instances are ordinary objects that inherit properties from their 

AggregateError prototype object

 and

have an [[ErrorData]] internal slot whose value is 

undefined

. The only specified use of [[ErrorData]] is by

Object.prototype.toString

Object.prototype.toString

 (

20.1.3.6

) to identify Error, AggregateError, or 

NativeError

 instances.

The Number 

constructor

:

is 

%Number%

.

is the initial value of the 

"Number"

 property of the 

global object

.

creates and initializes a new Number 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 Number behaviour must include a 

super

super

 call to the Number

constructor

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

When 

Number

Number

 is called with argument 

value

, the following steps are taken:

1.  If 

value

 is present, then

a.  Let 

prim

 be ? 

ToNumeric

(

value

).

b.  If 

Type

(

prim

) is BigInt, let 

n

(

prim

)).

c.  Otherwise, let 

n

 be 

prim

.

2.  Else,

a.  Let 

n

 be 

+0

𝔽

.

3.  If NewTarget is 

undefined

, return 

n

.

4.  Let 

O

 be ? 

OrdinaryCreateFromConstructor

(NewTarget, 

"%Number.prototype%"

, « [[NumberData]] »).

5.  Set 

O

.[[NumberData]] to 

n

.

6.  Return 

O

.

20.5.7.3.3  AggregateError.prototype.name

20.5.7.4  Properties of AggregateError Instances

21  Numbers and Dates

21.1  Number Objects

21.1.1  The Number Constructor

21.1.1.1  Number ( 

value

 )

21.1.2  Properties of the Number Constructor

507

The Number 

constructor

:

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

%Function.prototype%

.

has the following properties:

The value of 

Number.EPSILON

Number.EPSILON

 is the 

Number value

 for the magnitude of the difference between 1 and the

smallest value greater than 1 that is representable as a 

Number value

, which is approximately

2.2204460492503130808472633361816 

×

 10

-16

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

When 

Number.isFinite

Number.isFinite

 is called with one argument 

number

, the following steps are taken:

1.  If 

Type

(

number

) is not Number, return 

false

.

2.  If 

number

 is 

NaN

+

𝔽

, or 

-

𝔽

, return 

false

.

3.  Otherwise, return 

true

.

When 

Number.isInteger

Number.isInteger

 is called with one argument 

number

, the following steps are taken:

1.  Return ! 

IsIntegralNumber

(

number

).

When 

Number.isNaN

Number.isNaN

 is called with one argument 

number

, the following steps are taken:

1.  If 

Type

(

number

) is not Number, return 

false

.

2.  If 

number

 is 

NaN

, return 

true

.

3.  Otherwise, return 

false

.

NOTE

When 

Number.isSafeInteger

Number.isSafeInteger

 is called with one argument 

number

, the following steps are taken:

1.  If ! 

IsIntegralNumber

(

number

) is 

true

, then

a.  If 

abs

(

number

)) 

 2

53

 - 1, return 

true

.

2.  Return 

false

.

This function differs from the global isNaN function (

19.2.3

) in that it does not convert its

argument to a Number before determining whether it is 

NaN

.

21.1.2.1  Number.EPSILON

21.1.2.2  Number.isFinite ( 

number

 )

21.1.2.3  Number.isInteger ( 

number

 )

21.1.2.4  Number.isNaN ( 

number

 )

21.1.2.5  Number.isSafeInteger ( 

number

 )

21.1.2.6  Number.MAX_SAFE_INTEGER

508

 

 

 

 

 

 

 

Content      ..     45      46      47      48     ..