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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     39      40      41      42     ..

 

 

 

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

 

 

Rue du Rhone 114

CH-1204 Geneva

Tel: +41 22 849 6000

Fax: +41 22 849 6001

Web: 

https://ecma-international.org/

This document may be copied, published and distributed to others, and certain derivative works of it may be
prepared, copied, published, and distributed, in whole or in part, provided that the above copyright notice and this
Copyright License and Disclaimer are included on all such copies and derivative works. The only derivative works
that are permissible under this Copyright License and Disclaimer are:

(i) works which incorporate all or portion of this document for the purpose of providing commentary or explanation
(such as an annotated version of the document),

(ii) works which incorporate all or portion of this document for the purpose of incorporating features that provide
accessibility,

(iii) translations of this document into languages other than English and into different formats and

(iv) works by making use of this specification in standard conformant products by implementing (e.g. by copy and
paste wholly or partly) the functionality therein.

However, the content of this document itself may not be modified in any way, including by removing the copyright
notice or references to Ecma International, except as required to translate it into languages other than English or into a
different format.

The official version of an Ecma International document is the English language version on the Ecma International
website. In the event of discrepancies between a translated version and the official version, the official version shall
govern.

The limited permissions granted above are perpetual and will not be revoked by Ecma International or its successors
or assigns.

This document and the information contained herein is provided on an "AS IS" basis and ECMA INTERNATIONAL
DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY
THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY OWNERSHIP RIGHTS OR ANY
IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

All Software contained in this document ("Software") is protected by copyright and is being made available under the
"BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma
International), including patent rights, and no licenses under such third party rights are granted under this license

Copyright Notice

Software License

874

even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN
PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR
INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT
ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following

disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the

following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived

from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA
INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

875

is not a valid sentence in the ECMAScript grammar, even with the automatic semicolon insertion rules. In contrast, the
source

is also not a valid ECMAScript sentence, but is transformed by automatic semicolon insertion into the following:

which is a valid ECMAScript sentence.

The source

is not a valid ECMAScript sentence and is not altered by automatic semicolon insertion because the semicolon is
needed for the header of a 

for

for

 statement. Automatic semicolon insertion never inserts one of the two semicolons in

the header of a 

for

for

 statement.

The source

is transformed by automatic semicolon insertion into the following:

NOTE 1

The source

is transformed by automatic semicolon insertion into the following:

NOTE 2

The source

1

 

2

 } 

3

1

2

 } 

3

1

;

2

 ;} 

3

;

for

 (a; b

)

return

a + b

return

;

a + b;

The expression 

a + b

a + b

 is not treated as a value to be returned by the 

return

return

 statement,

because a 

LineTerminator

 separates it from the token 

return

return

.

a = b
++c

a = b;
++c;

The token 

++

++

 is not treated as a postfix operator applying to the variable 

bb

, because a 

LineTerminator

 occurs between 

bb

 and 

++

++

.

300

is not a valid ECMAScript sentence and is not altered by automatic semicolon insertion before the 

else

else

 token, even

though no production of the grammar applies at that point, because an automatically inserted semicolon would then
be parsed as an empty statement.

The source

is 

not

 transformed by automatic semicolon insertion, because the parenthesized expression that begins the second line

can be interpreted as an argument list for a function call:

In the circumstance that an assignment statement must begin with a left parenthesis, it is a good idea for the
programmer to provide an explicit semicolon at the end of the preceding statement rather than to rely on automatic
semicolon insertion.

This section is non-normative.

ECMAScript programs can be written in a style with very few semicolons by relying on automatic semicolon
insertion. As described above, semicolons are not inserted at every newline, and automatic semicolon insertion can
depend on multiple tokens across line terminators.

As new syntactic features are added to ECMAScript, additional grammar productions could be added that cause lines
relying on automatic semicolon insertion preceding them to change grammar productions when parsed.

For the purposes of this section, a case of automatic semicolon insertion is considered interesting if it is a place where
a semicolon may or may not be inserted, depending on the source text which precedes it. The rest of this section
describes a number of interesting cases of automatic semicolon insertion in this version of ECMAScript.

In a 

StatementList

, many 

StatementListItem

s end in semicolons, which may be omitted using automatic semicolon

insertion. As a consequence of the rules above, at the end of a line ending an expression, a semicolon is required if the
following line begins with any of the following:

An opening parenthesis (

((

)

. Without a semicolon, the two lines together are treated as a 

CallExpression

.

An opening square bracket (

[[

)

. Without a semicolon, the two lines together are treated as property access,

rather than an 

ArrayLiteral

 or 

ArrayAssignmentPattern

.

A template literal (

``

)

. Without a semicolon, the two lines together are interpreted as a tagged Template

(

13.3.11

), with the previous expression as the 

MemberExpression

.

Unary 

++

 or 

--

. Without a semicolon, the two lines together are interpreted as a usage of the corresponding

binary operator.

A RegExp literal

. Without a semicolon, the two lines together may be parsed instead as the 

//

 

MultiplicativeOperator

, for example if the RegExp has flags.

if

 (a > b)

else

 c = d

a = b + c
(d + e).print()

a = b + c(d + e).print()

12.9.3  Interesting Cases of Automatic Semicolon Insertion

12.9.3.1  Interesting Cases of Automatic Semicolon Insertion in Statement Lists

301

This section is non-normative.

ECMAScript contains grammar productions which include “[no 

LineTerminator

 here]”. These productions are

sometimes a means to have optional operands in the grammar. Introducing a 

LineTerminator

 in these locations would

change the grammar production of a source text by using the grammar production without the optional operand.

The rest of this section describes a number of productions using “[no 

LineTerminator

 here]” in this version of

ECMAScript.

UpdateExpression

.

ContinueStatement

.

BreakStatement

.

ReturnStatement

.

YieldExpression

.

Async Function Definitions (

15.8

) with relation to Function Definitions (

15.2

)

IdentifierReference

[Yield, Await]

 

:

Identifier

[~Yield]

yield

[~Await]

await

BindingIdentifier

[Yield, Await]

 

:

Identifier

yield

await

LabelIdentifier

[Yield, Await]

 

:

Identifier

[~Yield]

yield

[~Await]

await

Identifier

 

:

IdentifierName

 but not 

ReservedWord

12.9.3.2  Cases of Automatic Semicolon Insertion and “[no 

LineTerminator

 here]”

12.9.3.2.1  List of Grammar Productions with Optional Operands and “[no 

LineTerminator

 here]”

13  ECMAScript Language: Expressions

13.1  Identifiers

Syntax

302

NOTE

BindingIdentifier

 

:

 

Identifier

It is a Syntax Error if the code matched by this production is contained in 

strict mode code

 and the 

StringValue

of 

Identifier

 is 

"arguments"

 or 

"eval"

.

IdentifierReference

 

:

 

yield

BindingIdentifier

 

:

 

yield

LabelIdentifier

 

:

 

yield

It is a Syntax Error if the code matched by this production is contained in 

strict mode code

.

IdentifierReference

 

:

 

await

BindingIdentifier

 

:

 

await

LabelIdentifier

 

:

 

await

It is a Syntax Error if the 

goal symbol

 of the syntactic grammar is 

Module

.

BindingIdentifier

[Yield, Await]

 

:

 

yield

It is a Syntax Error if this production has a 

[Yield]

 parameter.

BindingIdentifier

[Yield, Await]

 

:

 

await

It is a Syntax Error if this production has an 

[Await]

 parameter.

IdentifierReference

[Yield, Await]

 

:

 

Identifier

BindingIdentifier

[Yield, Await]

 

:

 

Identifier

LabelIdentifier

[Yield, Await]

 

:

 

Identifier

It is a Syntax Error if this production has a 

[Yield]

 parameter and 

StringValue

 of 

Identifier

 is 

"yield"

.

It is a Syntax Error if this production has an 

[Await]

 parameter and 

StringValue

 of 

Identifier

 is 

"await"

.

Identifier

 

:

 

IdentifierName

 but not 

ReservedWord

It is a Syntax Error if this phrase is contained in 

strict mode code

 and the 

StringValue

 of 

IdentifierName

 is:

"implements"

"interface"

"let"

"package"

"private"

"protected"

"public"

"static"

, or 

"yield"

.

It is a Syntax Error if the 

goal symbol

 of the syntactic grammar is 

Module

 and the 

StringValue

 of 

IdentifierName

is 

"await"

.

It is a Syntax Error if 

StringValue

 of 

IdentifierName

 is the same String value as the 

StringValue

 of any 

ReservedWord

 except for 

yield

yield

 or 

await

await

.

yield

yield

 and 

await

await

 are permitted as 

BindingIdentifier

 in the grammar, and prohibited with 

static

semantics

 below, to prohibit automatic semicolon insertion in cases such as

let
await

 

0

;

13.1.1  Static Semantics: Early Errors

303

NOTE

IdentifierName

 

::

IdentifierStart
IdentifierName

 

IdentifierPart

1.  Let 

idText

 be the source text matched by 

IdentifierName

.

2.  Let 

idTextUnescaped

 be the result of replacing any occurrences of 

\\

 

UnicodeEscapeSequence

 in 

idText

 with the

code point represented by the 

UnicodeEscapeSequence

.

3.  Return ! 

CodePointsToString

(

idTextUnescaped

).

IdentifierReference

 

:

 

yield

BindingIdentifier

 

:

 

yield

LabelIdentifier

 

:

 

yield

1.  Return 

"yield"

.

IdentifierReference

 

:

 

await

BindingIdentifier

 

:

 

await

LabelIdentifier

 

:

 

await

1.  Return 

"await"

.

Identifier

 

:

 

IdentifierName

 but not 

ReservedWord

1.  Return the 

StringValue

 of 

IdentifierName

.

IdentifierReference

 

:

 

Identifier

1.  Return ? 

ResolveBinding

(

StringValue

 of 

Identifier

).

IdentifierReference

 

:

 

yield

1.  Return ? 

ResolveBinding

(

"yield"

).

IdentifierReference

 

:

 

await

1.  Return ? 

ResolveBinding

(

"await"

).

NOTE 1

NOTE 2

StringValue

 of 

IdentifierName

 normalizes any Unicode escape sequences in 

IdentifierName

 hence

such escapes cannot be used to write an 

Identifier

 whose code point sequence is the same as a 

ReservedWord

.

The result of evaluating an 

IdentifierReference

 is always a value of type Reference.

In 

non-strict code

, the 

keyword

 

yield

yield

 may be used as an identifier. Evaluating the 

IdentifierReference

 resolves the binding of 

yield

yield

 as if it was an 

Identifier

. Early Error restriction

ensures that such an evaluation only can occur for 

non-strict code

.

13.1.2  Static Semantics: StringValue

13.1.3  Runtime Semantics: Evaluation

304

PrimaryExpression

[Yield, Await]

 

:

this

IdentifierReference

[?Yield, ?Await]

Literal
ArrayLiteral

[?Yield, ?Await]

ObjectLiteral

[?Yield, ?Await]

FunctionExpression
ClassExpression

[?Yield, ?Await]

GeneratorExpression
AsyncFunctionExpression
AsyncGeneratorExpression
RegularExpressionLiteral
TemplateLiteral

[?Yield, ?Await, ~Tagged]

CoverParenthesizedExpressionAndArrowParameterList

[?Yield, ?Await]

CoverParenthesizedExpressionAndArrowParameterList

[Yield, Await]

 

:

(

 

Expression

[+In, ?Yield, ?Await]

 

)

(

 

Expression

[+In, ?Yield, ?Await]

 

,

 

)

(

 

)

(

 

...

 

BindingIdentifier

[?Yield, ?Await]

 

)

(

 

...

 

BindingPattern

[?Yield, ?Await]

 

)

(

 

Expression

[+In, ?Yield, ?Await]

 

,

 

...

 

BindingIdentifier

[?Yield, ?Await]

 

)

(

 

Expression

[+In, ?Yield, ?Await]

 

,

 

...

 

BindingPattern

[?Yield, ?Await]

 

)

When processing an instance of the production 

PrimaryExpression

[Yield, Await]

 

:

 

CoverParenthesizedExpressionAndArrowParameterList

[?Yield, ?Await]

 

the interpretation of 

CoverParenthesizedExpressionAndArrowParameterList

 is refined using the following grammar:

ParenthesizedExpression

[Yield, Await]

 

:

(

 

Expression

[+In, ?Yield, ?Await]

 

)

CoverParenthesizedExpressionAndArrowParameterList

 

:

 

(

 

Expression

 

)

1.  Return the 

ParenthesizedExpression

 that is 

covered

 by 

CoverParenthesizedExpressionAndArrowParameterList

.

13.2  Primary Expression

Syntax

Supplemental Syntax

13.2.1  Semantics

13.2.1.1  Static Semantics: CoveredParenthesizedExpression

305

PrimaryExpression

 

:

 

this

1.  Return ? 

ResolveThisBinding

().

See 

13.1

 for 

IdentifierReference

.

Literal

 

:

NullLiteral
BooleanLiteral
NumericLiteral
StringLiteral

Literal

 

:

 

NullLiteral

1.  Return 

null

.

Literal

 

:

 

BooleanLiteral

1.  If 

BooleanLiteral

 is the token 

false

false

, return 

false

.

2.  If 

BooleanLiteral

 is the token 

true

true

, return 

true

.

Literal

 

:

 

NumericLiteral

1.  Return the 

NumericValue

 of 

NumericLiteral

 as defined in 

12.8.3

.

Literal

 

:

 

StringLiteral

1.  Return the 

SV

 of 

StringLiteral

 as defined in 

12.8.4.1

.

NOTE

Array elements may be elided at the beginning, middle or end of the element list. Whenever a comma in the element
list is not preceded by an 

AssignmentExpression

 (i.e., a comma at the beginning or after another comma), the missing

array element contributes to the length of the Array and increases the index of subsequent elements. Elided array

An 

ArrayLiteral

 is an expression describing the initialization of an Array object, using a list, of

zero or more expressions each of which represents an array element, enclosed in square brackets.
The elements need not be literals; they are evaluated each time the array initializer is evaluated.

13.2.2  The 

this

this

 Keyword

13.2.2.1  Runtime Semantics: Evaluation

13.2.3  Identifier Reference

13.2.4  Literals

Syntax

13.2.4.1  Runtime Semantics: Evaluation

13.2.5  Array Initializer

306

elements are not defined. If an element is elided at the end of an array, that element does not contribute to the length
of the Array.

ArrayLiteral

[Yield, Await]

 

:

[

 

Elision

opt

 

]

[

 

ElementList

[?Yield, ?Await]

 

]

[

 

ElementList

[?Yield, ?Await]

 

,

 

Elision

opt

 

]

ElementList

[Yield, Await]

 

:

Elision

opt

 

AssignmentExpression

[+In, ?Yield, ?Await]

Elision

opt

 

SpreadElement

[?Yield, ?Await]

ElementList

[?Yield, ?Await]

 

,

 

Elision

opt

 

AssignmentExpression

[+In, ?Yield, ?Await]

ElementList

[?Yield, ?Await]

 

,

 

Elision

opt

 

SpreadElement

[?Yield, ?Await]

Elision

 

:

,

Elision

 

,

SpreadElement

[Yield, Await]

 

:

...

 

AssignmentExpression

[+In, ?Yield, ?Await]

With parameters 

array

 and 

nextIndex

.

Elision

 

:

 

,

1.  Let 

len

 be 

nextIndex

 + 1.

2.  Perform ? 

Set

(

array

"length"

len

), 

true

).

3.  NOTE: The above Set throws if 

len

 exceeds 2

32

-1.

4.  Return 

len

.

Elision

 

:

 

Elision

 

,

1.  Return the result of performing 

ArrayAccumulation

 for 

Elision

 with arguments 

array

 and 

nextIndex

 + 1.

ElementList

 

:

 

Elision

opt

 

AssignmentExpression

1.  If 

Elision

 is present, then

a.  Set 

nextIndex

 to the result of performing 

ArrayAccumulation

 for 

Elision

 with arguments 

array

 and

nextIndex

.

b. 

ReturnIfAbrupt

(

nextIndex

).

2.  Let 

initResult

 be the result of evaluating 

AssignmentExpression

.

3.  Let 

initValue

 be ? 

GetValue

(

initResult

).

4.  Let 

created

 be ! 

CreateDataPropertyOrThrow

(

array

, ! 

ToString

(

nextIndex

)), 

initValue

).

5.  Return 

nextIndex

 + 1.

Syntax

13.2.5.1  Runtime Semantics: ArrayAccumulation

307

ElementList

 

:

 

Elision

opt

 

SpreadElement

1.  If 

Elision

 is present, then

a.  Set 

nextIndex

 to the result of performing 

ArrayAccumulation

 for 

Elision

 with arguments 

array

 and

nextIndex

.

b. 

ReturnIfAbrupt

(

nextIndex

).

2.  Return the result of performing 

ArrayAccumulation

 for 

SpreadElement

 with arguments 

array

 and 

nextIndex

.

ElementList

 

:

 

ElementList

 

,

 

Elision

opt

 

AssignmentExpression

1.  Set 

nextIndex

 to the result of performing 

ArrayAccumulation

 for 

ElementList

 with arguments 

array

 and

nextIndex

.

2. 

ReturnIfAbrupt

(

nextIndex

).

3.  If 

Elision

 is present, then

a.  Set 

nextIndex

 to the result of performing 

ArrayAccumulation

 for 

Elision

 with arguments 

array

 and

nextIndex

.

b. 

ReturnIfAbrupt

(

nextIndex

).

4.  Let 

initResult

 be the result of evaluating 

AssignmentExpression

.

5.  Let 

initValue

 be ? 

GetValue

(

initResult

).

6.  Let 

created

 be ! 

CreateDataPropertyOrThrow

(

array

, ! 

ToString

(

nextIndex

)), 

initValue

).

7.  Return 

nextIndex

 + 1.

ElementList

 

:

 

ElementList

 

,

 

Elision

opt

 

SpreadElement

1.  Set 

nextIndex

 to the result of performing 

ArrayAccumulation

 for 

ElementList

 with arguments 

array

 and

nextIndex

.

2. 

ReturnIfAbrupt

(

nextIndex

).

3.  If 

Elision

 is present, then

a.  Set 

nextIndex

 to the result of performing 

ArrayAccumulation

 for 

Elision

 with arguments 

array

 and

nextIndex

.

b. 

ReturnIfAbrupt

(

nextIndex

).

4.  Return the result of performing 

ArrayAccumulation

 for 

SpreadElement

 with arguments 

array

 and 

nextIndex

.

SpreadElement

 

:

 

...

 

AssignmentExpression

1.  Let 

spreadRef

 be the result of evaluating 

AssignmentExpression

.

2.  Let 

spreadObj

 be ? 

GetValue

(

spreadRef

).

3.  Let 

iteratorRecord

 be ? 

GetIterator

(

spreadObj

).

4.  Repeat,

a.  Let 

next

 be ? 

IteratorStep

(

iteratorRecord

).

b.  If 

next

 is 

false

, return 

nextIndex

.

c.  Let 

nextValue

 be ? 

IteratorValue

(

next

).

d.  Perform ! 

CreateDataPropertyOrThrow

(

array

, ! 

ToString

(

(

nextIndex

)), 

nextValue

).

e.  Set 

nextIndex

 to 

nextIndex

 + 1.

NOTE

CreateDataPropertyOrThrow

 is used to ensure that own properties are defined for the array even

if the standard built-in 

Array prototype object

 has been modified in a manner that would

preclude the creation of new own properties using [[Set]].

308

ArrayLiteral

 

:

 

[

 

Elision

opt

 

]

1.  Let 

array

 be ! 

ArrayCreate

(0).

2.  If 

Elision

 is present, then

a.  Let 

len

 be the result of performing 

ArrayAccumulation

 for 

Elision

 with arguments 

array

 and 0.

b. 

ReturnIfAbrupt

(

len

).

3.  Return 

array

.

ArrayLiteral

 

:

 

[

 

ElementList

 

]

1.  Let 

array

 be ! 

ArrayCreate

(0).

2.  Let 

len

 be the result of performing 

ArrayAccumulation

 for 

ElementList

 with arguments 

array

 and 0.

3. 

ReturnIfAbrupt

(

len

).

4.  Return 

array

.

ArrayLiteral

 

:

 

[

 

ElementList

 

,

 

Elision

opt

 

]

1.  Let 

array

 be ! 

ArrayCreate

(0).

2.  Let 

nextIndex

 be the result of performing 

ArrayAccumulation

 for 

ElementList

 with arguments 

array

 and 0.

3. 

ReturnIfAbrupt

(

nextIndex

).

4.  If 

Elision

 is present, then

a.  Let 

len

 be the result of performing 

ArrayAccumulation

 for 

Elision

 with arguments 

array

 and 

nextIndex

.

b. 

ReturnIfAbrupt

(

len

).

5.  Return 

array

.

NOTE 1

ObjectLiteral

[Yield, Await]

 

:

{

 

}

{

 

PropertyDefinitionList

[?Yield, ?Await]

 

}

{

 

PropertyDefinitionList

[?Yield, ?Await]

 

,

 

}

PropertyDefinitionList

[Yield, Await]

 

:

PropertyDefinition

[?Yield, ?Await]

PropertyDefinitionList

[?Yield, ?Await]

 

,

 

PropertyDefinition

[?Yield, ?Await]

PropertyDefinition

[Yield, Await]

 

:

IdentifierReference

[?Yield, ?Await]

CoverInitializedName

[?Yield, ?Await]

PropertyName

[?Yield, ?Await]

 

:

 

AssignmentExpression

[+In, ?Yield, ?Await]

An object initializer is an expression describing the initialization of an Object, written in a form
resembling a literal. It is a list of zero or more pairs of property keys and associated values,
enclosed in curly brackets. The values need not be literals; they are evaluated each time the object
initializer is evaluated.

13.2.5.2  Runtime Semantics: Evaluation

13.2.6  Object Initializer

Syntax

309

MethodDefinition

[?Yield, ?Await]

...

 

AssignmentExpression

[+In, ?Yield, ?Await]

PropertyName

[Yield, Await]

 

:

LiteralPropertyName
ComputedPropertyName

[?Yield, ?Await]

LiteralPropertyName

 

:

IdentifierName
StringLiteral
NumericLiteral

ComputedPropertyName

[Yield, Await]

 

:

[

 

AssignmentExpression

[+In, ?Yield, ?Await]

 

]

CoverInitializedName

[Yield, Await]

 

:

IdentifierReference

[?Yield, ?Await]

 

Initializer

[+In, ?Yield, ?Await]

Initializer

[In, Yield, Await]

 

:

=

 

AssignmentExpression

[?In, ?Yield, ?Await]

NOTE 2

NOTE 3

PropertyDefinition

 

:

 

MethodDefinition

It is a Syntax Error if 

HasDirectSuper

 of 

MethodDefinition

 is 

true

.

In addition to describing an actual object initializer the 

ObjectLiteral

 productions are also used as a cover grammar for 

ObjectAssignmentPattern

 and may be recognized as part of a 

CoverParenthesizedExpressionAndArrowParameterList

. When

ObjectLiteral

 appears in a context wher

ObjectAssignmentPattern

 is required the following Early Error rules are 

not

applied. In addition, they are not applied when initially parsing a 

CoverParenthesizedExpressionAndArrowParameterList

or 

CoverCallExpressionAndAsyncArrowHead

.

PropertyDefinition

 

:

 

CoverInitializedName

Always throw a Syntax Error if code matches this production.

NOTE

MethodDefinition

 is defined in 

15.4

.

In certain contexts, 

ObjectLiteral

 is used as a cover grammar for a more restricted secondary

grammar. The 

CoverInitializedName

 production is necessary to fully cover these secondary

grammars. However, use of this production results in an early Syntax Error in normal contexts
where an actual 

ObjectLiteral

 is expected.

This production exists so that 

ObjectLiteral

 can serve as a cover grammar for 

ObjectAssignmentPattern

. It cannot occur in an actual object initializer.

13.2.6.1  Static Semantics: Early Errors

310

PropertyName

 

:

 

LiteralPropertyName

1.  Return 

false

.

PropertyName

 

:

 

ComputedPropertyName

1.  Return 

true

.

PropertyDefinitionList

 

:

 

PropertyDefinition

1.  If 

PropName

 of 

PropertyDefinition

 is 

empty

, return a new empty 

List

.

2.  Return a 

List

 whose sole element is 

PropName

 of 

PropertyDefinition

.

PropertyDefinitionList

 

:

 

PropertyDefinitionList

 

,

 

PropertyDefinition

1.  Let 

list

 be 

PropertyNameList

 of 

PropertyDefinitionList

.

2.  If 

PropName

 of 

PropertyDefinition

 is 

empty

, return 

list

.

3.  Append 

PropName

 of 

PropertyDefinition

 to the end of 

list

.

4.  Return 

list

.

ObjectLiteral

 

:

 

{

 

}

1.  Return ! 

OrdinaryObjectCreate

(

%Object.prototype%

).

ObjectLiteral

 

:

{

 

PropertyDefinitionList

 

}

{

 

PropertyDefinitionList

 

,

 

}

1.  Let 

obj

 be ! 

OrdinaryObjectCreate

(

%Object.prototype%

).

2.  Perform ? 

PropertyDefinitionEvaluation

 of 

PropertyDefinitionList

 with arguments 

obj

 and 

true

.

3.  Return 

obj

.

LiteralPropertyName

 

:

 

IdentifierName

1.  Return 

StringValue

 of 

IdentifierName

.

LiteralPropertyName

 

:

 

StringLiteral

1.  Return the 

SV

 of 

StringLiteral

.

LiteralPropertyName

 

:

 

NumericLiteral

1.  Let 

nbr

 be the 

NumericValue

 of 

NumericLiteral

.

2.  Return ! 

ToString

(

nbr

).

ComputedPropertyName

 

:

 

[

 

AssignmentExpression

 

]

1.  Let 

exprValue

 be the result of evaluating 

AssignmentExpression

.

2.  Let 

propName

 be ? 

GetValue

(

exprValue

).

3.  Return ? 

ToPropertyKey

(

propName

).

13.2.6.2  Static Semantics: IsComputedPropertyKey

13.2.6.3  Static Semantics: PropertyNameList

13.2.6.4  Runtime Semantics: Evaluation

311

With parameters 

object

 and 

enumerable

.

PropertyDefinitionList

 

:

 

PropertyDefinitionList

 

,

 

PropertyDefinition

1.  Perform ? 

PropertyDefinitionEvaluation

 of 

PropertyDefinitionList

 with arguments 

object

 and 

enumerable

.

2.  Return the result of performing 

PropertyDefinitionEvaluation

 of 

PropertyDefinition

 with arguments 

object

 and

enumerable

.

PropertyDefinition

 

:

 

...

 

AssignmentExpression

1.  Let 

exprValue

 be the result of evaluating 

AssignmentExpression

.

2.  Let 

fromValue

 be ? 

GetValue

(

exprValue

).

3.  Let 

excludedNames

 be a new empty 

List

.

4.  Return ? 

CopyDataProperties

(

object

fromValue

excludedNames

).

PropertyDefinition

 

:

 

IdentifierReference

1.  Let 

propName

 be 

StringValue

 of 

IdentifierReference

.

2.  Let 

exprValue

 be the result of evaluating 

IdentifierReference

.

3.  Let 

propValue

 be ? 

GetValue

(

exprValue

).

4. 

Assert

enumerable

 is 

true

.

5. 

Assert

object

 is an ordinary, extensible object with no non-configurable properties.

6.  Return ! 

CreateDataPropertyOrThrow

(

object

propName

propValue

).

PropertyDefinition

 

:

 

PropertyName

 

:

 

AssignmentExpression

1.  Let 

propKey

 be the result of evaluating 

PropertyName

.

2. 

ReturnIfAbrupt

(

propKey

).

3.  If 

IsAnonymousFunctionDefinition

(

AssignmentExpression

) is 

true

, then

a.  Let 

propValue

 be ? 

NamedEvaluation

 of 

AssignmentExpression

 with argument 

propKey

.

4.  Else,

a.  Let 

exprValueRef

 be the result of evaluating 

AssignmentExpression

.

b.  Let 

propValue

 be ? 

GetValue

(

exprValueRef

).

5. 

Assert

enumerable

 is 

true

.

6. 

Assert

object

 is an ordinary, extensible object with no non-configurable properties.

7.  Return ! 

CreateDataPropertyOrThrow

(

object

propKey

propValue

).

NOTE

MethodDefinition

 

:

PropertyName

 

(

 

UniqueFormalParameters

 

)

 

{

 

FunctionBody

 

}

get

 

PropertyName

 

(

 

)

 

{

 

FunctionBody

 

}

set

 

PropertyName

 

(

 

PropertySetParameterList

 

)

 

{

 

FunctionBody

 

}

1.  Return ? 

MethodDefinitionEvaluation

 of 

MethodDefinition

 with arguments 

object

 and 

enumerable

.

GeneratorMethod

 

:

 

*

 

PropertyName

 

(

 

UniqueFormalParameters

 

)

 

{

 

GeneratorBody

 

}

1.  Return ? 

MethodDefinitionEvaluation

 of 

GeneratorMethod

 with arguments 

object

 and 

enumerable

.

An alternative semantics for this production is given in 

B.3.1

.

13.2.6.5  Runtime Semantics: PropertyDefinitionEvaluation

312

AsyncGeneratorMethod

 

:

 

async

 

*

 

PropertyName

 

(

 

UniqueFormalParameters

 

)

 

{

 

AsyncGeneratorBody

 

}

1.  Return ? 

MethodDefinitionEvaluation

 of 

AsyncGeneratorMethod

 with arguments 

object

 and 

enumerable

.

AsyncMethod

 

:

 

async

 

PropertyName

 

(

 

UniqueFormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

1.  Return ? 

MethodDefinitionEvaluation

 of 

AsyncMethod

 with arguments 

object

 and 

enumerable

.

See 

15.2

 for 

PrimaryExpression

 

:

 

FunctionExpression

 .

See 

15.5

 for 

PrimaryExpression

 

:

 

GeneratorExpression

 .

See 

15.7

 for 

PrimaryExpression

 

:

 

ClassExpression

 .

See 

15.8

 for 

PrimaryExpression

 

:

 

AsyncFunctionExpression

 .

See 

15.6

 for 

PrimaryExpression

 

:

 

AsyncGeneratorExpression

 .

See 

12.8.5

.

PrimaryExpression

 

:

 

RegularExpressionLiteral

It is a Syntax Error if 

IsValidRegularExpressionLiteral

(

RegularExpressionLiteral

) is 

false

.

The abstract operation IsValidRegularExpressionLiteral takes argument 

literal

. It determines if its argument is a valid

regular expression literal. It performs the following steps when called:

1. 

Assert

literal

 is a 

RegularExpressionLiteral

.

2.  If 

FlagText

 of 

literal

 contains any code points other than 

gg

ii

mm

ss

uu

, or 

yy

, or if it contains the same code point

more than once, return 

false

.

3.  Let 

patternText

 be 

BodyText

 of 

literal

.

4.  If 

FlagText

 of 

literal

 contains 

uu

, let 

u

 be 

true

; else let 

u

 be 

false

.

5.  If 

u

 is 

false

, then

a.  Let 

stringValue

 be 

CodePointsToString

(

patternText

).

b.  Set 

patternText

 to the sequence of code points resulting from interpreting each of the 16-bit elements of

stringValue

 as a Unicode BMP code point. UTF-16 decoding is not applied to the elements.

6.  Let 

parseResult

 be 

ParsePattern

(

patternText

u

).

7.  If 

parseResult

 is a 

Parse Node

, return 

true

; else return 

false

.

PrimaryExpression

 

:

 

RegularExpressionLiteral

13.2.7  Function Defining Expressions

13.2.8  Regular Expression Literals

Syntax

13.2.8.1  Static Semantics: Early Errors

13.2.8.2  Static Semantics: IsValidRegularExpressionLiteral ( 

literal

 )

13.2.8.3  Runtime Semantics: Evaluation

313

 

 

 

 

 

 

 

Content      ..     39      40      41      42     ..