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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     8      9      10      11     ..

 

 

 

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

 

 

Table 79: 

Agent Events Record

 Fields

Field Name

Value

Meaning

[[AgentSignifier]]

A value that admits equality
testing

The 

agent

 whose evaluation resulted in this ordering.

[[EventList]]

List

 of events

Events are appended to the list during evaluation.

[[AgentSynchronizesWith]] A 

List

 of pairs of 

Synchronize

events

Synchronize

 relationships introduced by the

operational semantics.

Chosen Value Record

 is a 

Record

 with the following fields.

Table 80: 

Chosen Value Record

 Fields

Field Name

Value

Meaning

[[Event]]

Shared Data

Block event

The 

ReadSharedMemory

 or 

ReadModifyWriteSharedMemory

 event that was

introduced for this chosen value.

[[ChosenValue]] A 

List

 of byte

values

The bytes that were nondeterministically chosen during evaluation.

candidate execution

 of the evaluation of an 

agent cluster

 is a 

Record

 with the following fields.

29.3  Chosen Value Records

29.4  Candidate Executions

802

Table 81: Candidate Execution 

Record

 Fields

Field Name

Value

Meaning

[[EventsRecords]]

List

 of 

Agent

Events Records.

Maps an 

agent

 to Lists of events appended during the

evaluation.

[[ChosenValues]]

List

 of Chosen

Value Records.

Maps 

ReadSharedMemory

 or 

ReadModifyWriteSharedMemory

events to the 

List

 of byte values chosen during the evaluation.

[[AgentOrder]]

An 

agent-order

Relation

.

Defined below.

[[ReadsBytesFrom]]

reads-bytes-from

mathematical
function.

Defined below.

[[ReadsFrom]]

reads-from

Relation

.

Defined below.

[[HostSynchronizesWith]] 

host-synchronizes-

with

 

Relation

.

Defined below.

[[SynchronizesWith]]

synchronizes-with

Relation

.

Defined below.

[[HappensBefore]]

happens-before

Relation

.

Defined below.

An 

empty candidate execution

 is a candidate execution 

Record

 whose fields are empty Lists and Relations.

The abstract operation EventSet takes argument 

execution

 (a 

candidate execution

). It performs the following steps

when called:

1.  Let 

events

 be an empty Set.

2.  For each 

Agent Events Record

 

aer

 of 

execution

.[[EventsRecords]], do

a.  For each event 

E

 of 

aer

.[[EventList]], do

i.  Add 

E

 to 

events

.

3.  Return 

events

.

The abstract operation SharedDataBlockEventSet takes argument 

execution

 (a 

candidate execution

). It performs the

following steps when called:

1.  Let 

events

 be an empty Set.

29.5  Abstract Operations for the Memory Model

29.5.1  EventSet ( 

execution

 )

29.5.2  SharedDataBlockEventSet ( 

execution

 )

803

of the Atomics object.

context-free grammar

 consists of a number of 

productions

. Each production has an abstract symbol called a 

nonterminal

as its 

left-hand side

, and a sequence of zero or more nonterminal and 

terminal

 symbols as its 

right-hand side

. For each

grammar, the terminal symbols are drawn from a specified alphabet.

chain production

 is a production that has exactly one nonterminal symbol on its right-hand side along with zero or

more terminal symbols.

Starting from a sentence consisting of a single distinguished nonterminal, called the 

goal symbol

, a given context-free

grammar specifies a 

language

, namely, the (perhaps infinite) set of possible sequences of terminal symbols that can

result from repeatedly replacing any nonterminal in the sequence with a right-hand side of a production for which the
nonterminal is the left-hand side.

lexical grammar

 for ECMAScript is given in clause 

12

. This grammar has as its terminal symbols Unicode code points

that conform to the rules for 

SourceCharacter

 defined in 

11.1

. It defines a set of productions, starting from the 

goal

symbol

 

InputElementDiv

InputElementTemplateTail

, or 

InputElementRegExp

, or 

InputElementRegExpOrTemplateTail

, that

describe how sequences of such code points are translated into a sequence of input elements.

Input elements other than white space and comments form the terminal symbols for the syntactic grammar for
ECMAScript and are called ECMAScript 

tokens

. These tokens are the reserved words, identifiers, literals, and

punctuators of the ECMAScript language. Moreover, line terminators, although not considered to be tokens, also
become part of the stream of input elements and guide the process of automatic semicolon insertion (

12.9

). Simple

white space and single-line comments are discarded and do not appear in the stream of input elements for the
syntactic grammar. A 

MultiLineComment

 (that is, a comment of the form 

/*

/*

*/

*/

 regardless of whether it spans more

than one line) is likewise simply discarded if it contains no line terminator; but if a 

MultiLineComment

 contains one or

more line terminators, then it is replaced by a single line terminator, which becomes part of the stream of input
elements for the syntactic grammar.

RegExp grammar

 for ECMAScript is given in 

22.2.1

. This grammar also has as its terminal symbols the code points as

defined by 

SourceCharacter

. It defines a set of productions, starting from the 

goal symbol

 

Pattern

, that describe how

sequences of code points are translated into regular expression patterns.

Productions of the lexical and RegExp grammars are distinguished by having two colons “

::

” as separating

punctuation. The lexical and RegExp grammars share some productions.

5  Notational Conventions

5.1  Syntactic and Lexical Grammars

5.1.1  Context-Free Grammars

5.1.2  The Lexical and RegExp Grammars

5.1.3  The Numeric String Grammar

58

Another grammar is used for translating Strings into numeric values. This grammar is similar to the part of the lexical
grammar having to do with numeric literals and has as its terminal symbols 

SourceCharacter

. This grammar appears in

7.1.4.1

.

Productions of the numeric string grammar are distinguished by having three colons “

:::

” as punctuation.

The 

syntactic grammar

 for ECMAScript is given in clauses 

13

 through 

16

. This grammar has ECMAScript tokens

defined by the lexical grammar as its terminal symbols (

5.1.2

). It defines a set of productions, starting from two

alternative goal symbols 

Script

 and 

Module

, that describe how sequences of tokens form syntactically correct

independent components of ECMAScript programs.

When a stream of code points is to be parsed as an ECMAScript 

Script

 or 

Module

, it is first converted to a stream of

input elements by repeated application of the lexical grammar; this stream of input elements is then parsed by a single
application of the syntactic grammar. The input stream is syntactically in error if the tokens in the stream of input
elements cannot be parsed as a single instance of the goal nonterminal (

Script

 or 

Module

), with no tokens left over.

When a parse is successful, it constructs a 

parse tree

, a rooted tree structure in which each node is a 

Parse Node

. Each

Parse Node is an 

instance

 of a symbol in the grammar; it represents a span of the source text that can be derived from

that symbol. The root node of the parse tree, representing the whole of the source text, is an instance of the parse's

goal symbol

. When a Parse Node is an instance of a nonterminal, it is also an instance of some production that has

that nonterminal as its left-hand side. Moreover, it has zero or more 

children

, one for each symbol on the production's

right-hand side: each child is a Parse Node that is an instance of the corresponding symbol.

New Parse Nodes are instantiated for each invocation of the parser and never reused between parses even of identical
source text. Parse Nodes are considered 

the same Parse Node

 if and only if they represent the same span of source text,

are instances of the same grammar symbol, and resulted from the same parser invocation.

NOTE 1

NOTE 2

Productions of the syntactic grammar are distinguished by having just one colon “

:

” as punctuation.

The syntactic grammar as presented in clauses 

13

 through 

16

 is not a complete account of which token sequences are

accepted as a correct ECMAScript 

Script

 or 

Module

. Certain additional token sequences are also accepted, namely,

those that would be described by the grammar if only semicolons were added to the sequence in certain places (such
as before line terminator characters). Furthermore, certain token sequences that are described by the grammar are not
considered acceptable if a line terminator character appears in certain “awkward” places.

Parsing the same String multiple times will lead to different Parse Nodes. For example, consider:

Each call to 

eval

eval

 converts the value of 

str

str

 into an ECMAScript source text and performs an

independent parse that creates its own separate tree of Parse Nodes. The trees are distinct even
though each parse operates upon a source text that was derived from the same String value.

let

 str = 

"1 + 1;"

;

eval

(str);

eval

(str);

Parse Nodes are specification artefacts, and implementations are not required to use an
analogous data structure.

5.1.4  The Syntactic Grammar

59

In certain cases, in order to avoid ambiguities, the syntactic grammar uses generalized productions that permit token
sequences that do not form a valid ECMAScript 

Script

 or 

Module

. For example, this technique is used for object literals

and object destructuring patterns. In such cases a more restrictive 

supplemental grammar

 is provided that further

restricts the acceptable token sequences. Typically, an 

early error

 rule will then define an error condition if "

P

 is not

covering

 an 

N

", where 

P

 is a Parse Node (an instance of the generalized production) and 

N

 is a nonterminal from the

supplemental grammar. Here, the sequence of tokens originally matched by 

P

 is parsed again using 

N

 as the 

goal

symbol

. (If 

N

 takes grammatical parameters, then they are set to the same values used when 

P

 was originally parsed.)

An error occurs if the sequence of tokens cannot be parsed as a single instance of 

N

, with no tokens left over.

Subsequently, algorithms access the result of the parse using a phrase of the form "the 

N

 that is 

covered

 by 

P

". This will

always be a Parse Node (an instance of 

N

, unique for a given 

P

), since any parsing failure would have been detected

by an 

early error

 rule.

Terminal symbols are shown in 

fixed width

fixed width

 font, both in the productions of the grammars and throughout this

specification whenever the text directly refers to such a terminal symbol. These are to appear in a script exactly as
written. All terminal symbol code points specified in this way are to be understood as the appropriate Unicode code
points from the Basic Latin range, as opposed to any similar-looking code points from other Unicode ranges. A code
point in a terminal symbol cannot be expressed by a 

\\

 

UnicodeEscapeSequence

.

Nonterminal symbols are shown in 

italic

 type. The definition of a nonterminal (also called a “production”) is

introduced by the name of the nonterminal being defined followed by one or more colons. (The number of colons
indicates to which grammar the production belongs.) One or more alternative right-hand sides for the nonterminal
then follow on succeeding lines. For example, the syntactic definition:

WhileStatement

 

:

while

 

(

 

Expression

 

)

 

Statement

states that the nonterminal 

WhileStatement

 represents the token 

while

while

, followed by a left parenthesis token, followed

by an 

Expression

, followed by a right parenthesis token, followed by a 

Statement

. The occurrences of 

Expression

 and 

Statement

 are themselves nonterminals. As another example, the syntactic definition:

ArgumentList

 

:

AssignmentExpression
ArgumentList

 

,

 

AssignmentExpression

states that an 

ArgumentList

 may represent either a single 

AssignmentExpression

 or an 

ArgumentList

, followed by a

comma, followed by an 

AssignmentExpression

. This definition of 

ArgumentList

 is recursive, that is, it is defined in terms

of itself. The result is that an 

ArgumentList

 may contain any positive number of arguments, separated by commas,

where each argument expression is an 

AssignmentExpression

. Such recursive definitions of nonterminals are common.

The subscripted suffix “

opt

”, which may appear after a terminal or nonterminal, indicates an optional symbol. The

alternative containing the optional symbol actually specifies two right-hand sides, one that omits the optional element
and one that includes it. This means that:

VariableDeclaration

 

:

BindingIdentifier

 

Initializer

opt

is a convenient abbreviation for:

5.1.5  Grammar Notation

60

VariableDeclaration

 

:

BindingIdentifier
BindingIdentifier

 

Initializer

and that:

ForStatement

 

:

for

 

(

 

LexicalDeclaration

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

is a convenient abbreviation for:

ForStatement

 

:

for

 

(

 

LexicalDeclaration

 

;

 

Expression

opt

 

)

 

Statement

for

 

(

 

LexicalDeclaration

 

Expression

 

;

 

Expression

opt

 

)

 

Statement

which in turn is an abbreviation for:

ForStatement

 

:

for

 

(

 

LexicalDeclaration

 

;

 

)

 

Statement

for

 

(

 

LexicalDeclaration

 

;

 

Expression

 

)

 

Statement

for

 

(

 

LexicalDeclaration

 

Expression

 

;

 

)

 

Statement

for

 

(

 

LexicalDeclaration

 

Expression

 

;

 

Expression

 

)

 

Statement

so, in this example, the nonterminal 

ForStatement

 actually has four alternative right-hand sides.

A production may be parameterized by a subscripted annotation of the form “

[parameters]

”, which may appear as a

suffix to the nonterminal symbol defined by the production. “

parameters

” may be either a single name or a comma

separated list of names. A parameterized production is shorthand for a set of productions defining all combinations of
the parameter names, preceded by an underscore, appended to the parameterized nonterminal symbol. This means
that:

StatementList

[Return]

 

:

ReturnStatement
ExpressionStatement

is a convenient abbreviation for:

StatementList

 

:

ReturnStatement
ExpressionStatement

StatementList_Return

 

:

ReturnStatement
ExpressionStatement

and that:

StatementList

[Return, In]

 

:

ReturnStatement
ExpressionStatement

61

ReadSharedMemory

 or 

ReadModifyWriteSharedMemory

 event). It performs the following steps when called:

1. 

Assert

R

 is a 

ReadSharedMemory

 or 

ReadModifyWriteSharedMemory

 event.

2.  Let 

Ws

 be 

execution

.[[ReadsBytesFrom]](

R

).

3. 

Assert

Ws

 is a 

List

 of 

WriteSharedMemory

 or 

ReadModifyWriteSharedMemory

 events with length equal to 

R

.

[[ElementSize]].

4.  Return 

ComposeWriteEventBytes

(

execution

R

.[[ByteIndex]], 

Ws

).

For a 

candidate execution

 

execution

execution

.[[AgentOrder]] is a 

Relation

 on events that satisfies the following.

For each pair (

E

D

) in 

EventSet

(

execution

), (

E

D

) is in 

execution

.[[AgentOrder]] if there is some 

Agent Events

Record

 

aer

 in 

execution

.[[EventsRecords]] such that 

E

 and 

D

 are in 

aer

.[[EventList]] and 

E

 is before 

D

 in 

List

order of 

aer

.[[EventList]].

NOTE

For a 

candidate execution

 

execution

execution

.[[ReadsBytesFrom]] is a mathematical function mapping events in

SharedDataBlockEventSet

(

execution

) to Lists of events in 

SharedDataBlockEventSet

(

execution

) that satisfies the

following conditions.

For each 

ReadSharedMemory

 or 

ReadModifyWriteSharedMemory

 event 

R

 in

SharedDataBlockEventSet

(

execution

), 

execution

.[[ReadsBytesFrom]](

R

) is a 

List

 of length 

R

.[[ElementSize]]

whose elements ar

WriteSharedMemory

 or 

ReadModifyWriteSharedMemory

 events 

Ws

 such that all of the

following are true.

Each event 

W

 with index 

i

 in 

Ws

 has 

R

.[[ByteIndex]] + 

i

 in its range.

R

 is not in 

Ws

.

For a 

candidate execution

 

execution

execution

.[[ReadsFrom]] is the least 

Relation

 on events that satisfies the following.

For each pair (

R

W

) in 

SharedDataBlockEventSet

(

execution

), (

R

W

) is in 

execution

.[[ReadsFrom]] if 

W

 is in

execution

.[[ReadsBytesFrom]](

R

).

For a 

candidate execution

 

execution

execution

.[[HostSynchronizesWith]] is a 

host

-provided 

strict partial order

 on 

host

-

specific events that satisfies at least the following.

Each 

agent

 introduces events in a per-

agent

 

strict total order

 during the evaluation. This is the

union of those strict total orders.

29.6  Relations of Candidate Executions

29.6.1  agent-order

29.6.2  reads-bytes-from

29.6.3  reads-from

29.6.4  host-synchronizes-with

805

 

 

 

 

 

 

 

Content      ..     8      9      10      11     ..