13.2 Primary Expression
Syntax
Supplemental Syntax
When processing an instance of the production
the interpretation of
13.2.1 Semantics
13.2.1.1 Static Semantics: CoveredParenthesizedExpression
- Return the
ParenthesizedExpression that iscovered byCoverParenthesizedExpressionAndArrowParameterList .
13.2.2 The this
Keyword
13.2.2.1 Runtime Semantics: Evaluation
- Return ?
ResolveThisBinding ().
13.2.3 Identifier Reference
See
13.2.4 Literals
Syntax
13.2.4.1 Runtime Semantics: Evaluation
- Return
null .
- If
BooleanLiteral is the tokenfalse
, returnfalse . - If
BooleanLiteral is the tokentrue
, returntrue .
- Return the
NumericValue ofNumericLiteral as defined in12.8.3 .
- Return the
SV ofStringLiteral as defined in12.8.4.1 .
13.2.5 Array Initializer
An
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
Syntax
13.2.5.1 Runtime Semantics: ArrayAccumulation
With parameters array and nextIndex.
- Return the result of performing
ArrayAccumulation forElision with arguments array and nextIndex + 1.
- If
Elision is present, then- Set nextIndex to the result of performing
ArrayAccumulation forElision with arguments array and nextIndex. ReturnIfAbrupt (nextIndex).
- Set nextIndex to the result of performing
- Let initResult be the result of evaluating
AssignmentExpression . - Let initValue be ?
GetValue (initResult). - Let created be !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (nextIndex)), initValue). - Return nextIndex + 1.
- If
Elision is present, then- Set nextIndex to the result of performing
ArrayAccumulation forElision with arguments array and nextIndex. ReturnIfAbrupt (nextIndex).
- Set nextIndex to the result of performing
- Return the result of performing
ArrayAccumulation forSpreadElement with arguments array and nextIndex.
- Set nextIndex to the result of performing
ArrayAccumulation forElementList with arguments array and nextIndex. ReturnIfAbrupt (nextIndex).- If
Elision is present, then- Set nextIndex to the result of performing
ArrayAccumulation forElision with arguments array and nextIndex. ReturnIfAbrupt (nextIndex).
- Set nextIndex to the result of performing
- Let initResult be the result of evaluating
AssignmentExpression . - Let initValue be ?
GetValue (initResult). - Let created be !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (nextIndex)), initValue). - Return nextIndex + 1.
- Set nextIndex to the result of performing
ArrayAccumulation forElementList with arguments array and nextIndex. ReturnIfAbrupt (nextIndex).- If
Elision is present, then- Set nextIndex to the result of performing
ArrayAccumulation forElision with arguments array and nextIndex. ReturnIfAbrupt (nextIndex).
- Set nextIndex to the result of performing
- Return the result of performing
ArrayAccumulation forSpreadElement with arguments array and nextIndex.
- Let spreadRef be the result of evaluating
AssignmentExpression . - Let spreadObj be ?
GetValue (spreadRef). - Let iteratorRecord be ?
GetIterator (spreadObj). - Repeat,
- Let next be ?
IteratorStep (iteratorRecord). - If next is
false , return nextIndex. - Let nextValue be ?
IteratorValue (next). - Perform !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (nextIndex)), nextValue). - Set nextIndex to nextIndex + 1.
- Let next be ?
13.2.5.2 Runtime Semantics: Evaluation
- Let array be !
ArrayCreate (0). - If
Elision is present, then- Let len be the result of performing
ArrayAccumulation forElision with arguments array and 0. ReturnIfAbrupt (len).
- Let len be the result of performing
- Return array.
- Let array be !
ArrayCreate (0). - Let len be the result of performing
ArrayAccumulation forElementList with arguments array and 0. ReturnIfAbrupt (len).- Return array.
- Let array be !
ArrayCreate (0). - Let nextIndex be the result of performing
ArrayAccumulation forElementList with arguments array and 0. ReturnIfAbrupt (nextIndex).- If
Elision is present, then- Let len be the result of performing
ArrayAccumulation forElision with arguments array and nextIndex. ReturnIfAbrupt (len).
- Let len be the result of performing
- Return array.
13.2.6 Object Initializer
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.
Syntax
In certain contexts,
13.2.6.1 Static Semantics: Early Errors
-
It is a Syntax Error if
HasDirectSuper ofMethodDefinition istrue .
In addition to describing an actual object initializer the
- Always throw a Syntax Error if code matches this production.
This production exists so that
13.2.6.2 Static Semantics: IsComputedPropertyKey
- Return
false .
- Return
true .
13.2.6.3 Static Semantics: PropertyNameList
- If
PropName ofPropertyDefinition isempty , return a new emptyList . - Return a
List whose sole element isPropName ofPropertyDefinition .
- Let list be
PropertyNameList ofPropertyDefinitionList . - If
PropName ofPropertyDefinition isempty , return list. - Append
PropName ofPropertyDefinition to the end of list. - Return list.
13.2.6.4 Runtime Semantics: Evaluation
- Return !
OrdinaryObjectCreate (%Object.prototype% ).
- Let obj be !
OrdinaryObjectCreate (%Object.prototype% ). - Perform ?
PropertyDefinitionEvaluation ofPropertyDefinitionList with arguments obj andtrue . - Return obj.
- Return
StringValue ofIdentifierName .
- Return the
SV ofStringLiteral .
- Let nbr be the
NumericValue ofNumericLiteral . - Return !
ToString (nbr).
- Let exprValue be the result of evaluating
AssignmentExpression . - Let propName be ?
GetValue (exprValue). - Return ?
ToPropertyKey (propName).
13.2.6.5 Runtime Semantics: PropertyDefinitionEvaluation
With parameters object and enumerable.
- Perform ?
PropertyDefinitionEvaluation ofPropertyDefinitionList with arguments object and enumerable. - Return the result of performing
PropertyDefinitionEvaluation ofPropertyDefinition with arguments object and enumerable.
- Let exprValue be the result of evaluating
AssignmentExpression . - Let fromValue be ?
GetValue (exprValue). - Let excludedNames be a new empty
List . - Return ?
CopyDataProperties (object, fromValue, excludedNames).
- Let propName be
StringValue ofIdentifierReference . - Let exprValue be the result of evaluating
IdentifierReference . - Let propValue be ?
GetValue (exprValue). Assert : enumerable istrue .Assert : object is an ordinary, extensible object with no non-configurable properties.- Return !
CreateDataPropertyOrThrow (object, propName, propValue).
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue , then- Let propValue be ?
NamedEvaluation ofAssignmentExpression with argument propKey.
- Let propValue be ?
- Else,
- Let exprValueRef be the result of evaluating
AssignmentExpression . - Let propValue be ?
GetValue (exprValueRef).
- Let exprValueRef be the result of evaluating
Assert : enumerable istrue .Assert : object is an ordinary, extensible object with no non-configurable properties.- Return !
CreateDataPropertyOrThrow (object, propKey, propValue).
An alternative semantics for this production is given in
- Return ?
MethodDefinitionEvaluation ofMethodDefinition with arguments object and enumerable.
- Return ?
MethodDefinitionEvaluation ofGeneratorMethod with arguments object and enumerable.
- Return ?
MethodDefinitionEvaluation ofAsyncGeneratorMethod with arguments object and enumerable.
- Return ?
MethodDefinitionEvaluation ofAsyncMethod with arguments object and enumerable.
13.2.7 Function Defining Expressions
See
See
See
See
See
13.2.8 Regular Expression Literals
Syntax
See
13.2.8.1 Static Semantics: Early Errors
-
It is a Syntax Error if
IsValidRegularExpressionLiteral (RegularExpressionLiteral ) isfalse .
13.2.8.2 Static Semantics: IsValidRegularExpressionLiteral ( literal )
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:
Assert : literal is aRegularExpressionLiteral .- If
FlagText of literal contains any code points other thang
,i
,m
,s
,u
, ory
, or if it contains the same code point more than once, returnfalse . - Let patternText be
BodyText of literal. - If
FlagText of literal containsu
, let u betrue ; else let u befalse . - If u is
false , then- Let stringValue be
CodePointsToString (patternText). - 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.
- Let stringValue be
- Let parseResult be
ParsePattern (patternText, u). - If parseResult is a
Parse Node , returntrue ; else returnfalse .
13.2.8.3 Runtime Semantics: Evaluation
- Let pattern be !
CodePointsToString (BodyText ofRegularExpressionLiteral ). - Let flags be !
CodePointsToString (FlagText ofRegularExpressionLiteral ). - Return
RegExpCreate (pattern, flags).
13.2.9 Template Literals
Syntax
13.2.9.1 Static Semantics: Early Errors
-
It is a Syntax Error if the [Tagged] parameter was not set and
NoSubstitutionTemplate Contains NotEscapeSequence .
-
It is a Syntax Error if the number of elements in the result of
TemplateStrings ofTemplateLiteral with argumentfalse is greater than 232 - 1.
-
It is a Syntax Error if the [Tagged] parameter was not set and
TemplateHead Contains NotEscapeSequence .
-
It is a Syntax Error if the [Tagged] parameter was not set and
TemplateTail Contains NotEscapeSequence .
-
It is a Syntax Error if the [Tagged] parameter was not set and
TemplateMiddle Contains NotEscapeSequence .
13.2.9.2 Static Semantics: TemplateStrings
With parameter raw.
- If raw is
false , then- Let string be the TV of
NoSubstitutionTemplate .
- Let string be the TV of
- Else,
- Let string be the TRV of
NoSubstitutionTemplate .
- Let string be the TRV of
- Return a
List whose sole element is string.
- If raw is
false , then- Let head be the TV of
TemplateHead .
- Let head be the TV of
- Else,
- Let head be the TRV of
TemplateHead .
- Let head be the TRV of
- Let tail be
TemplateStrings ofTemplateSpans with argument raw. - Return a
List whose elements are head followed by the elements of tail.
- If raw is
false , then- Let tail be the TV of
TemplateTail .
- Let tail be the TV of
- Else,
- Let tail be the TRV of
TemplateTail .
- Let tail be the TRV of
- Return a
List whose sole element is tail.
- Let middle be
TemplateStrings ofTemplateMiddleList with argument raw. - If raw is
false , then- Let tail be the TV of
TemplateTail .
- Let tail be the TV of
- Else,
- Let tail be the TRV of
TemplateTail .
- Let tail be the TRV of
- Return a
List whose elements are the elements of middle followed by tail.
- If raw is
false , then- Let string be the TV of
TemplateMiddle .
- Let string be the TV of
- Else,
- Let string be the TRV of
TemplateMiddle .
- Let string be the TRV of
- Return a
List whose sole element is string.
- Let front be
TemplateStrings ofTemplateMiddleList with argument raw. - If raw is
false , then- Let last be the TV of
TemplateMiddle .
- Let last be the TV of
- Else,
- Let last be the TRV of
TemplateMiddle .
- Let last be the TRV of
- Append last as the last element of the
List front. - Return front.
13.2.9.3 GetTemplateObject ( templateLiteral )
The abstract operation GetTemplateObject takes argument templateLiteral (a
- Let realm be
the current Realm Record . - Let templateRegistry be realm.[[TemplateMap]].
- For each element e of templateRegistry, do
- If e.[[Site]] is
the same Parse Node as templateLiteral, then- Return e.[[Array]].
- If e.[[Site]] is
- Let rawStrings be
TemplateStrings of templateLiteral with argumenttrue . - Let cookedStrings be
TemplateStrings of templateLiteral with argumentfalse . - Let count be the number of elements in the
List cookedStrings. Assert : count ≤ 232 - 1.- Let template be !
ArrayCreate (count). - Let rawObj be !
ArrayCreate (count). - Let index be 0.
- Repeat, while index < count,
- Let prop be !
ToString (𝔽 (index)). - Let cookedValue be cookedStrings[index].
- Perform !
DefinePropertyOrThrow (template, prop, PropertyDescriptor { [[Value]]: cookedValue, [[Writable]]:false , [[Enumerable]]:true , [[Configurable]]:false }). - Let rawValue be the String value rawStrings[index].
- Perform !
DefinePropertyOrThrow (rawObj, prop, PropertyDescriptor { [[Value]]: rawValue, [[Writable]]:false , [[Enumerable]]:true , [[Configurable]]:false }). - Set index to index + 1.
- Let prop be !
- Perform !
SetIntegrityLevel (rawObj,frozen ). - Perform !
DefinePropertyOrThrow (template,"raw" , PropertyDescriptor { [[Value]]: rawObj, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:false }). - Perform !
SetIntegrityLevel (template,frozen ). - Append the
Record { [[Site]]: templateLiteral, [[Array]]: template } to templateRegistry. - Return template.
The creation of a template object cannot result in an
Each
Future editions of this specification may define additional non-enumerable properties of template objects.
13.2.9.4 Runtime Semantics: SubstitutionEvaluation
- Return a new empty
List .
- Return the result of
SubstitutionEvaluation ofTemplateMiddleList .
- Let subRef be the result of evaluating
Expression . - Let sub be ?
GetValue (subRef). - Return a
List whose sole element is sub.
- Let preceding be ?
SubstitutionEvaluation ofTemplateMiddleList . - Let nextRef be the result of evaluating
Expression . - Let next be ?
GetValue (nextRef). - Append next as the last element of the
List preceding. - Return preceding.
13.2.9.5 Runtime Semantics: Evaluation
- Return the TV of
NoSubstitutionTemplate as defined in12.8.6 .
- Let head be the TV of
TemplateHead as defined in12.8.6 . - Let subRef be the result of evaluating
Expression . - Let sub be ?
GetValue (subRef). - Let middle be ?
ToString (sub). - Let tail be the result of evaluating
TemplateSpans . ReturnIfAbrupt (tail).- Return the
string-concatenation of head, middle, and tail.
The string conversion semantics applied to the String.prototype.concat
rather than the +
operator.
- Return the TV of
TemplateTail as defined in12.8.6 .
- Let head be the result of evaluating
TemplateMiddleList . ReturnIfAbrupt (head).- Let tail be the TV of
TemplateTail as defined in12.8.6 . - Return the
string-concatenation of head and tail.
- Let head be the TV of
TemplateMiddle as defined in12.8.6 . - Let subRef be the result of evaluating
Expression . - Let sub be ?
GetValue (subRef). - Let middle be ?
ToString (sub). - Return the
string-concatenation of head and middle.
The string conversion semantics applied to the String.prototype.concat
rather than the +
operator.
- Let rest be the result of evaluating
TemplateMiddleList . ReturnIfAbrupt (rest).- Let middle be the TV of
TemplateMiddle as defined in12.8.6 . - Let subRef be the result of evaluating
Expression . - Let sub be ?
GetValue (subRef). - Let last be ?
ToString (sub). - Return the
string-concatenation of rest, middle, and last.
The string conversion semantics applied to the String.prototype.concat
rather than the +
operator.
13.2.10 The Grouping Operator
13.2.10.1 Static Semantics: Early Errors
-
It is a Syntax Error if
CoverParenthesizedExpressionAndArrowParameterList is notcovering aParenthesizedExpression . -
All Early Error rules for
ParenthesizedExpression and its derived productions also apply toCoveredParenthesizedExpression ofCoverParenthesizedExpressionAndArrowParameterList .
13.2.10.2 Runtime Semantics: Evaluation
- Let expr be
CoveredParenthesizedExpression ofCoverParenthesizedExpressionAndArrowParameterList . - Return the result of evaluating expr.
- Return the result of evaluating
Expression . This may be of type Reference.
This algorithm does not apply delete
and typeof
may be applied to parenthesized expressions.