12 ECMAScript Language: Expressions
12.1 Identifiers
Syntax
yield and await are permitted as
let
await 0;
12.1.1 Static Semantics: Early Errors
-
It is a Syntax Error if the code matched by this production is contained in
strict mode code and the StringValue ofIdentifier is"arguments" or"eval" .
-
It is a Syntax Error if the code matched by this production is contained in
strict mode code .
-
It is a Syntax Error if the
goal symbol of the syntactic grammar isModule .
- It is a Syntax Error if this production has a [Yield] parameter.
- It is a Syntax Error if this production has an [Await] parameter.
-
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" .
-
It is a Syntax Error if this phrase is contained in
strict mode code and the StringValue ofIdentifierName is:"implements" ,"interface" ,"let" ,"package" ,"private" ,"protected" ,"public" ,"static" , or"yield" . -
It is a Syntax Error if the
goal symbol of the syntactic grammar isModule and the StringValue ofIdentifierName is"await" . -
It is a Syntax Error if StringValue of
IdentifierName is the same String value as the StringValue of anyReservedWord except foryieldorawait.
StringValue of
12.1.2 Static Semantics: BoundNames
- Return a new
List containing the StringValue ofIdentifier .
- Return a new
List containing"yield" .
- Return a new
List containing"await" .
12.1.3 Static Semantics: AssignmentTargetType
- If this
IdentifierReference is contained instrict mode code and StringValue ofIdentifier is"eval" or"arguments" , returninvalid . - Return
simple .
- Return
simple .
- Return
simple .
12.1.4 Static Semantics: StringValue
- Return
"yield" .
- Return
"await" .
- Return the StringValue of
IdentifierName .
12.1.5 Runtime Semantics: BindingInitialization
With parameters value and environment.
var statements and formal parameter lists of some non-strict functions (See
- Let name be StringValue of
Identifier . - Return ?
InitializeBoundName (name, value, environment).
- Return ?
InitializeBoundName ("yield" , value, environment).
- Return ?
InitializeBoundName ("await" , value, environment).
12.1.5.1 Runtime Semantics: InitializeBoundName ( name, value, environment )
Assert :Type (name) is String.- If environment is not
undefined , then- Let env be the
EnvironmentRecord component of environment. - Perform env.InitializeBinding(name, value).
- Return
NormalCompletion (undefined ).
- Let env be the
- Else,
- Let lhs be
ResolveBinding (name). - Return ?
PutValue (lhs, value).
- Let lhs be
12.1.6 Runtime Semantics: Evaluation
- Return ?
ResolveBinding (StringValue ofIdentifier ).
- Return ?
ResolveBinding ("yield" ).
- Return ?
ResolveBinding ("await" ).
The result of evaluating an
In yield may be used as an identifier. Evaluating the yield as if it was an
12.2 Primary Expression
Syntax
Supplemental Syntax
When processing an instance of the production
the interpretation of
12.2.1 Semantics
12.2.1.1 Static Semantics: CoveredParenthesizedExpression
12.2.1.2 Static Semantics: HasName
- Let expr be CoveredParenthesizedExpression of
CoverParenthesizedExpressionAndArrowParameterList . - If IsFunctionDefinition of expr is
false , returnfalse . - Return HasName of expr.
12.2.1.3 Static Semantics: IsFunctionDefinition
- Return
false .
- Let expr be CoveredParenthesizedExpression of
CoverParenthesizedExpressionAndArrowParameterList . - Return IsFunctionDefinition of expr.
12.2.1.4 Static Semantics: IsIdentifierRef
- Return
true .
- Return
false .
12.2.1.5 Static Semantics: AssignmentTargetType
- Return
invalid .
- Let expr be CoveredParenthesizedExpression of
CoverParenthesizedExpressionAndArrowParameterList . - Return AssignmentTargetType of expr.
12.2.2 The this Keyword
12.2.2.1 Runtime Semantics: Evaluation
- Return ?
ResolveThisBinding ().
12.2.3 Identifier Reference
See
12.2.4 Literals
12.2.4.1 Runtime Semantics: Evaluation
- Return
null .
- If
BooleanLiteral is the tokenfalse, returnfalse . - If
BooleanLiteral is the tokentrue, returntrue .
- Return the NumericValue of
NumericLiteral as defined in11.8.3 .
- Return the StringValue of
StringLiteral as defined in11.8.4.1 .
12.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
12.2.5.1 Runtime Semantics: ArrayAccumulation
With parameters array and nextIndex.
- Return the result of performing ArrayAccumulation for
Elision with arguments array and nextIndex + 1.
- If
Elision is present, thenSet nextIndex to the result of performing ArrayAccumulation forElision with arguments array and nextIndex.ReturnIfAbrupt (nextIndex).
- 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, thenSet nextIndex to the result of performing ArrayAccumulation forElision with arguments array and nextIndex.ReturnIfAbrupt (nextIndex).
- Return the result of performing ArrayAccumulation for
SpreadElement 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, thenSet nextIndex to the result of performing ArrayAccumulation forElision with arguments array and nextIndex.ReturnIfAbrupt (nextIndex).
- 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, thenSet nextIndex to the result of performing ArrayAccumulation forElision with arguments array and nextIndex.ReturnIfAbrupt (nextIndex).
- Return the result of performing ArrayAccumulation for
SpreadElement 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 ?
12.2.5.2 Runtime Semantics: Evaluation
- Let array be !
ArrayCreate (0). - If
Elision is present, then- Let len be the result of performing ArrayAccumulation for
Elision with arguments array and 0. ReturnIfAbrupt (len).
- Let len be the result of performing ArrayAccumulation for
- Return array.
- Let array be !
ArrayCreate (0). - Let len be the result of performing ArrayAccumulation for
ElementList with arguments array and 0. ReturnIfAbrupt (len).- Return array.
- Let array be !
ArrayCreate (0). - Let nextIndex be the result of performing ArrayAccumulation for
ElementList with arguments array and 0. ReturnIfAbrupt (nextIndex).- If
Elision is present, then- Let len be the result of performing ArrayAccumulation for
Elision with arguments array and nextIndex. ReturnIfAbrupt (len).
- Let len be the result of performing ArrayAccumulation for
- Return array.
12.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,
12.2.6.1 Static Semantics: Early Errors
-
It is a Syntax Error if HasDirectSuper of
MethodDefinition 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
12.2.6.2 Static Semantics: ComputedPropertyContains
With parameter symbol.
- Return
false .
- Return the result of
ComputedPropertyName Contains symbol.
12.2.6.3 Static Semantics: Contains
With parameter symbol.
- If symbol is
MethodDefinition , returntrue . - Return the result of ComputedPropertyContains for
MethodDefinition with argument symbol.
Static semantic rules that depend upon substructure generally do not look into function definitions.
- If symbol is a
ReservedWord , returnfalse . - If symbol is an
Identifier and StringValue of symbol is the same value as the StringValue ofIdentifierName , returntrue . - Return
false .
12.2.6.4 Static Semantics: IsComputedPropertyKey
12.2.6.5 Static Semantics: PropName
- Return StringValue of
IdentifierReference .
- Return
empty .
- Return PropName of
PropertyName .
- Return StringValue of
IdentifierName .
- Return the String value whose code units are the SV of
StringLiteral .
- Let nbr be the NumericValue of
NumericLiteral . - Return !
ToString (nbr).
- Return
empty .
12.2.6.6 Static Semantics: PropertyNameList
- If PropName of
PropertyDefinition isempty , return a new emptyList . - Return a new
List containing PropName ofPropertyDefinition .
- Let list be PropertyNameList of
PropertyDefinitionList . - If PropName of
PropertyDefinition isempty , return list. - Append PropName of
PropertyDefinition to the end of list. - Return list.
12.2.6.7 Runtime Semantics: Evaluation
- Return
OrdinaryObjectCreate (%Object.prototype% ).
- Let obj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform ? PropertyDefinitionEvaluation of
PropertyDefinitionList with arguments obj andtrue . - Return obj.
- Return StringValue of
IdentifierName .
- Return the String value whose code units are the SV of
StringLiteral .
- Let nbr be the NumericValue of
NumericLiteral . - Return !
ToString (nbr).
- Let exprValue be the result of evaluating
AssignmentExpression . - Let propName be ?
GetValue (exprValue). - Return ?
ToPropertyKey (propName).
12.2.6.8 Runtime Semantics: PropertyDefinitionEvaluation
With parameters object and enumerable.
- Perform ? PropertyDefinitionEvaluation of
PropertyDefinitionList with arguments object and enumerable. - Return the result of performing PropertyDefinitionEvaluation of
PropertyDefinition 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 of
IdentifierReference . - 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 of
AssignmentExpression with argument propKey.
- Let propValue be NamedEvaluation of
- 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
12.2.7 Function Defining Expressions
See
See
See
See
See
12.2.8 Regular Expression Literals
Syntax
See
12.2.8.1 Static Semantics: Early Errors
-
It is a Syntax Error if
IsValidRegularExpressionLiteral (RegularExpressionLiteral ) isfalse .
12.2.8.2 Static Semantics: IsValidRegularExpressionLiteral ( literal )
The abstract operation IsValidRegularExpressionLiteral determines if its argument is a valid regular expression literal. The following steps are taken:
Assert : literal is aRegularExpressionLiteral .- If FlagText of literal contains any code points other than
g,i,m,s,u, ory, or if it contains the same code point more than once, returnfalse . - Let P be BodyText of literal.
- If FlagText of literal contains
u, then- Parse P using the grammars in
21.2.1 . Thegoal symbol for the parse isPattern . If P did not conform to the grammar, if any elements of P were not matched by the parse, or if any Early Error conditions exist, return[+U, +N] false . Otherwise, returntrue .
- Parse P using the grammars in
- Let stringValue be
UTF16Encode (P). - Let pText be 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.
- Parse pText using the grammars in
21.2.1 . Thegoal symbol for the parse isPattern . If the result of parsing contains a[~U, ~N] GroupName , reparse with thegoal symbol Pattern . If P did not conform to the grammar, if any elements of P were not matched by the parse, or if any Early Error conditions exist, return[~U, +N] false . Otherwise, returntrue .
12.2.8.3 Runtime Semantics: Evaluation
- Let pattern be !
UTF16Encode (BodyText ofRegularExpressionLiteral ). - Let flags be !
UTF16Encode (FlagText ofRegularExpressionLiteral ). - Return
RegExpCreate (pattern, flags).
12.2.9 Template Literals
Syntax
12.2.9.1 Static Semantics: Early Errors
-
It is a Syntax Error if the [Tagged] parameter was not set and
NoSubstitutionTemplate ContainsNotEscapeSequence .
-
It is a Syntax Error if the number of elements in the result of TemplateStrings of
TemplateLiteral with argumentfalse is greater than 232 - 1.
-
It is a Syntax Error if the [Tagged] parameter was not set and
TemplateHead ContainsNotEscapeSequence .
-
It is a Syntax Error if the [Tagged] parameter was not set and
TemplateTail ContainsNotEscapeSequence .
-
It is a Syntax Error if the [Tagged] parameter was not set and
TemplateMiddle ContainsNotEscapeSequence .
12.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 containing the single element, 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 of
TemplateSpans with argument raw. - Return a
List containing head followed by the elements, in order, 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 containing the single element, tail.
- Let middle be TemplateStrings of
TemplateMiddleList 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 containing the elements, in order, 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 containing the single element, string.
- Let front be TemplateStrings of
TemplateMiddleList 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.
12.2.9.3 Runtime Semantics: ArgumentListEvaluation
- Let templateLiteral be this
TemplateLiteral . - Let siteObj be
GetTemplateObject (templateLiteral). - Return a
List containing the one element which is siteObj.
- Let templateLiteral be this
TemplateLiteral . - Let siteObj be
GetTemplateObject (templateLiteral). - Let firstSubRef be the result of evaluating
Expression . - Let firstSub be ?
GetValue (firstSubRef). - Let restSub be ? SubstitutionEvaluation of
TemplateSpans . Assert : restSub is aList .- Return a
List whose first element is siteObj, whose second elements is firstSub, and whose subsequent elements are the elements of restSub, in order. restSub may contain no elements.
12.2.9.4 Runtime Semantics: GetTemplateObject ( templateLiteral )
The abstract operation GetTemplateObject is called with a
- Let rawStrings be TemplateStrings of templateLiteral with argument
true . - 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 cookedStrings be TemplateStrings of templateLiteral with argument
false . - 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 the String value cookedStrings[index].
- Call template.[[DefineOwnProperty]](prop, PropertyDescriptor { [[Value]]: cookedValue, [[Writable]]:
false , [[Enumerable]]:true , [[Configurable]]:false }). - Let rawValue be the String value rawStrings[index].
- Call rawObj.[[DefineOwnProperty]](prop, PropertyDescriptor { [[Value]]: rawValue, [[Writable]]:
false , [[Enumerable]]:true , [[Configurable]]:false }). Set index to index + 1.
- Let prop be !
- Perform
SetIntegrityLevel (rawObj,frozen ). - Call template.[[DefineOwnProperty]](
"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.
12.2.9.5 Runtime Semantics: SubstitutionEvaluation
- Return a new empty
List .
- Return the result of SubstitutionEvaluation of
TemplateMiddleList .
- Let subRef be the result of evaluating
Expression . - Let sub be ?
GetValue (subRef). - Return a
List containing only sub.
- Let preceding be ? SubstitutionEvaluation of
TemplateMiddleList . - 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.
12.2.9.6 Runtime Semantics: Evaluation
- Return the String value whose code units are the elements of the TV of
NoSubstitutionTemplate as defined in11.8.6 .
- Let head be the TV of
TemplateHead as defined in11.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.
- Let tail be the TV of
TemplateTail as defined in11.8.6 . - Return the String value consisting of the code units of tail.
- Let head be the result of evaluating
TemplateMiddleList . ReturnIfAbrupt (head).- Let tail be the TV of
TemplateTail as defined in11.8.6 . - Return the
string-concatenation of head and tail.
- Let head be the TV of
TemplateMiddle as defined in11.8.6 . - Let subRef be the result of evaluating
Expression . - Let sub be ?
GetValue (subRef). - Let middle be ?
ToString (sub). - Return the sequence of code units consisting of the code units of head followed by the elements of 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 in11.8.6 . - Let subRef be the result of evaluating
Expression . - Let sub be ?
GetValue (subRef). - Let last be ?
ToString (sub). - Return the sequence of code units consisting of the elements of rest followed by the code units of middle followed by the elements of last.
The string conversion semantics applied to the String.prototype.concat rather than the + operator.
12.2.10 The Grouping Operator
12.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 to CoveredParenthesizedExpression ofCoverParenthesizedExpressionAndArrowParameterList .
12.2.10.2 Static Semantics: IsFunctionDefinition
12.2.10.3 Static Semantics: AssignmentTargetType
12.2.10.4 Runtime Semantics: NamedEvaluation
With parameter name.
- Let expr be CoveredParenthesizedExpression of
CoverParenthesizedExpressionAndArrowParameterList . - Return the result of performing NamedEvaluation for expr with argument name.
Assert :IsAnonymousFunctionDefinition (Expression ) istrue .- Return the result of performing NamedEvaluation for
Expression with argument name.
12.2.10.5 Runtime Semantics: Evaluation
- Let expr be CoveredParenthesizedExpression of
CoverParenthesizedExpressionAndArrowParameterList . - Return the result of evaluating expr.
- Return the result of evaluating
Expression . This may be oftype Reference .
This algorithm does not apply delete and typeof may be applied to parenthesized expressions.
12.3 Left-Hand-Side Expressions
Syntax
Supplemental Syntax
When processing an instance of the production
12.3.1 Static Semantics
12.3.1.1 Static Semantics: Early Errors
- It is a Syntax Error if any code matches this production.
This production exists in order to prevent automatic semicolon insertion rules (
a?.b
`c`
so that it would be interpreted as two valid statements. The purpose is to maintain consistency with similar code without optional chaining:
a.b
`c`
which is a valid statement and where automatic semicolon insertion does not apply.
-
It is a Syntax Error if the syntactic
goal symbol is notModule .
12.3.1.2 Static Semantics: CoveredCallExpression
12.3.1.3 Static Semantics: Contains
With parameter symbol.
- If
MemberExpression Contains symbol istrue , returntrue . - If symbol is a
ReservedWord , returnfalse . - If symbol is an
Identifier and StringValue of symbol is the same value as the StringValue ofIdentifierName , returntrue . - Return
false .
- If symbol is the
ReservedWord super, returntrue . - If symbol is a
ReservedWord , returnfalse . - If symbol is an
Identifier and StringValue of symbol is the same value as the StringValue ofIdentifierName , returntrue . - Return
false .
- If
CallExpression Contains symbol istrue , returntrue . - If symbol is a
ReservedWord , returnfalse . - If symbol is an
Identifier and StringValue of symbol is the same value as the StringValue ofIdentifierName , returntrue . - Return
false .
- If symbol is a
ReservedWord , returnfalse . - If symbol is an
Identifier and StringValue of symbol is the same value as the StringValue ofIdentifierName , returntrue . - Return
false .
- If
OptionalChain Contains symbol istrue , returntrue . - If symbol is a
ReservedWord , returnfalse . - If symbol is an
Identifier and StringValue of symbol is the same value as the StringValue ofIdentifierName , returntrue . - Return
false .
12.3.1.4 Static Semantics: IsFunctionDefinition
12.3.1.5 Static Semantics: IsDestructuring
- If
PrimaryExpression is either anObjectLiteral or anArrayLiteral , returntrue . - Return
false .
- Return
false .
12.3.1.6 Static Semantics: IsIdentifierRef
12.3.1.7 Static Semantics: AssignmentTargetType
- Return
simple .
- Return
invalid .
12.3.2 Property Accessors
Properties are accessed by name, using either the dot notation:
or the bracket notation:
The dot notation is explained by the following syntactic conversion:
is identical in its behaviour to
and similarly
is identical in its behaviour to
where <identifier-name-string> is the result of evaluating StringValue of
12.3.2.1 Runtime Semantics: Evaluation
- Let baseReference be the result of evaluating
MemberExpression . - Let baseValue be ?
GetValue (baseReference). - If the code matched by this
MemberExpression isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- Let baseReference be the result of evaluating
MemberExpression . - Let baseValue be ?
GetValue (baseReference). - If the code matched by this
MemberExpression isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
- Let baseReference be the result of evaluating
CallExpression . - Let baseValue be ?
GetValue (baseReference). - If the code matched by this
CallExpression isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- Let baseReference be the result of evaluating
CallExpression . - Let baseValue be ?
GetValue (baseReference). - If the code matched by this
CallExpression isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
12.3.3 Runtime Semantics: EvaluatePropertyAccessWithExpressionKey ( baseValue, expression, strict )
The abstract operation EvaluatePropertyAccessWithExpressionKey takes as arguments a value baseValue, a
- Let propertyNameReference be the result of evaluating expression.
- Let propertyNameValue be ?
GetValue (propertyNameReference). - Let bv be ?
RequireObjectCoercible (baseValue). - Let propertyKey be ?
ToPropertyKey (propertyNameValue). - Return a value of
type Reference whose base value component is bv, whose referenced name component is propertyKey, and whose strict reference flag is strict.
12.3.4 Runtime Semantics: EvaluatePropertyAccessWithIdentifierKey ( baseValue, identifierName, strict )
The abstract operation EvaluatePropertyAccessWithIdentifierKey takes as arguments a value baseValue, a
Assert : identifierName is anIdentifierName .- Let bv be ?
RequireObjectCoercible (baseValue). - Let propertyNameString be StringValue of identifierName.
- Return a value of
type Reference whose base value component is bv, whose referenced name component is propertyNameString, and whose strict reference flag is strict.
12.3.5 The new Operator
12.3.5.1 Runtime Semantics: Evaluation
- Return ?
EvaluateNew (NewExpression ,empty ).
- Return ?
EvaluateNew (MemberExpression ,Arguments ).
12.3.5.1.1 Runtime Semantics: EvaluateNew ( constructExpr, arguments )
The abstract operation EvaluateNew with arguments constructExpr, and arguments performs the following steps:
Assert : constructExpr is either aNewExpression or aMemberExpression .Assert : arguments is eitherempty or anArguments .- Let ref be the result of evaluating constructExpr.
- Let constructor be ?
GetValue (ref). - If arguments is
empty , let argList be a new emptyList . - Else,
- Let argList be ? ArgumentListEvaluation of arguments.
- If
IsConstructor (constructor) isfalse , throw aTypeError exception. - Return ?
Construct (constructor, argList).
12.3.6 Function Calls
12.3.6.1 Runtime Semantics: Evaluation
- Let expr be CoveredCallExpression of
CoverCallExpressionAndAsyncArrowHead . - Let memberExpr be the
MemberExpression of expr. - Let arguments be the
Arguments of expr. - Let ref be the result of evaluating memberExpr.
- Let func be ?
GetValue (ref). - If
Type (ref) isReference ,IsPropertyReference (ref) isfalse , andGetReferencedName (ref) is"eval" , then- If
SameValue (func,%eval% ) istrue , then- Let argList be ? ArgumentListEvaluation of arguments.
- If argList has no elements, return
undefined . - Let evalArg be the first element of argList.
- If the source code matching this
CallExpression isstrict mode code , let strictCaller betrue . Otherwise let strictCaller befalse . - Let evalRealm be
the current Realm Record . - Return ?
PerformEval (evalArg, evalRealm, strictCaller,true ).
- If
- Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (func, ref, arguments, tailCall).
A
- Let ref be the result of evaluating
CallExpression . - Let func be ?
GetValue (ref). - Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (func, ref,Arguments , tailCall).
12.3.6.2 Runtime Semantics: EvaluateCall ( func, ref, arguments, tailPosition )
The abstract operation EvaluateCall takes as arguments a value func, a value ref, a
- If
Type (ref) isReference , then- If
IsPropertyReference (ref) istrue , then- Let thisValue be
GetThisValue (ref).
- Let thisValue be
- Else,
Assert : the base of ref is anEnvironment Record .- Let refEnv be
GetBase (ref). - Let thisValue be refEnv.WithBaseObject().
- If
- Else,
- Let thisValue be
undefined .
- Let thisValue be
- Let argList be ? ArgumentListEvaluation of arguments.
- If
Type (func) is not Object, throw aTypeError exception. - If
IsCallable (func) isfalse , throw aTypeError exception. - If tailPosition is
true , performPrepareForTailCall (). - Let result be
Call (func, thisValue, argList). Assert : If tailPosition istrue , the above call will not return here, but instead evaluation will continue as if the following return has already occurred.Assert : If result is not anabrupt completion , thenType (result) is anECMAScript language type .- Return result.
12.3.7 The super Keyword
12.3.7.1 Runtime Semantics: Evaluation
- Let env be
GetThisEnvironment (). - Let actualThis be ? env.GetThisBinding().
- Let propertyNameReference be the result of evaluating
Expression . - Let propertyNameValue be ?
GetValue (propertyNameReference). - Let propertyKey be ?
ToPropertyKey (propertyNameValue). - If the code matched by this
SuperProperty isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
MakeSuperPropertyReference (actualThis, propertyKey, strict).
- Let env be
GetThisEnvironment (). - Let actualThis be ? env.GetThisBinding().
- Let propertyKey be StringValue of
IdentifierName . - If the code matched by this
SuperProperty isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
MakeSuperPropertyReference (actualThis, propertyKey, strict).
- Let newTarget be
GetNewTarget (). Assert :Type (newTarget) is Object.- Let func be !
GetSuperConstructor (). - Let argList be ? ArgumentListEvaluation of
Arguments . - If
IsConstructor (func) isfalse , throw aTypeError exception. - Let result be ?
Construct (func, argList, newTarget). - Let thisER be
GetThisEnvironment (). - Return ? thisER.BindThisValue(result).
12.3.7.2 Runtime Semantics: GetSuperConstructor ( )
The abstract operation GetSuperConstructor performs the following steps:
- Let envRec be
GetThisEnvironment (). Assert : envRec is afunction Environment Record .- Let activeFunction be envRec.[[FunctionObject]].
Assert : activeFunction is an ECMAScriptfunction object .- Let superConstructor be ! activeFunction.[[GetPrototypeOf]]().
- Return superConstructor.
12.3.7.3 Runtime Semantics: MakeSuperPropertyReference ( actualThis, propertyKey, strict )
The abstract operation MakeSuperPropertyReference with arguments actualThis, propertyKey, and strict performs the following steps:
- Let env be
GetThisEnvironment (). Assert : env.HasSuperBinding() istrue .- Let baseValue be ? env.GetSuperBase().
- Let bv be ?
RequireObjectCoercible (baseValue). - Return a value of
type Reference that is aSuper Reference whose base value component is bv, whose referenced name component is propertyKey, whose thisValue component is actualThis, and whose strict reference flag is strict.
12.3.8 Argument Lists
The evaluation of an argument list produces a
12.3.8.1 Runtime Semantics: ArgumentListEvaluation
- Return a new empty
List .
- Let ref be the result of evaluating
AssignmentExpression . - Let arg be ?
GetValue (ref). - Return a
List whose sole item is arg.
- Let list be a new empty
List . - 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 list. - Let nextArg be ?
IteratorValue (next). - Append nextArg as the last element of list.
- Let next be ?
- Let precedingArgs be ? ArgumentListEvaluation of
ArgumentList . - Let ref be the result of evaluating
AssignmentExpression . - Let arg be ?
GetValue (ref). - Append arg to the end of precedingArgs.
- Return precedingArgs.
- Let precedingArgs be ? ArgumentListEvaluation of
ArgumentList . - Let spreadRef be the result of evaluating
AssignmentExpression . - Let iteratorRecord be ?
GetIterator (?GetValue (spreadRef)). - Repeat,
- Let next be ?
IteratorStep (iteratorRecord). - If next is
false , return precedingArgs. - Let nextArg be ?
IteratorValue (next). - Append nextArg as the last element of precedingArgs.
- Let next be ?
12.3.9 Optional Chains
?..12.3.9.1 Runtime Semantics: Evaluation
- Let baseReference be the result of evaluating
MemberExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is
undefined ornull , then- Return
undefined .
- Return
- Return the result of performing ChainEvaluation of
OptionalChain with arguments baseValue and baseReference.
- Let baseReference be the result of evaluating
CallExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is
undefined ornull , then- Return
undefined .
- Return
- Return the result of performing ChainEvaluation of
OptionalChain with arguments baseValue and baseReference.
- Let baseReference be the result of evaluating
OptionalExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is
undefined ornull , then- Return
undefined .
- Return
- Return the result of performing ChainEvaluation of
OptionalChain with arguments baseValue and baseReference.
12.3.9.2 Runtime Semantics: ChainEvaluation
With parameters baseValue and baseReference.
- Let thisChain be this
OptionalChain . - Let tailCall be
IsInTailPosition (thisChain). - Return ?
EvaluateCall (baseValue, baseReference,Arguments , tailCall).
- If the code matched by this
OptionalChain isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- If the code matched by this
OptionalChain isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
- Let optionalChain be
OptionalChain . - Let newReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
- Let newValue be ?
GetValue (newReference). - Let thisChain be this
OptionalChain . - Let tailCall be
IsInTailPosition (thisChain). - Return ?
EvaluateCall (newValue, newReference,Arguments , tailCall).
- Let optionalChain be
OptionalChain . - Let newReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
- Let newValue be ?
GetValue (newReference). - If the code matched by this
OptionalChain isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithExpressionKey (newValue,Expression , strict).
- Let optionalChain be
OptionalChain . - Let newReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
- Let newValue be ?
GetValue (newReference). - If the code matched by this
OptionalChain isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithIdentifierKey (newValue,IdentifierName , strict).
12.3.10 Import Calls
12.3.10.1 Runtime Semantics: Evaluation
- Let referencingScriptOrModule be !
GetActiveScriptOrModule (). - Let argRef be the result of evaluating
AssignmentExpression . - Let specifier be ?
GetValue (argRef). - Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let specifierString be
ToString (specifier). IfAbruptRejectPromise (specifierString, promiseCapability).- Perform !
HostImportModuleDynamically (referencingScriptOrModule, specifierString, promiseCapability). - Return promiseCapability.[[Promise]].
12.3.11 Tagged Templates
A tagged template is a function call where the arguments of the call are derived from a
12.3.11.1 Runtime Semantics: Evaluation
- Let tagRef be the result of evaluating
MemberExpression . - Let tagFunc be ?
GetValue (tagRef). - Let thisCall be this
MemberExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (tagFunc, tagRef,TemplateLiteral , tailCall).
- Let tagRef be the result of evaluating
CallExpression . - Let tagFunc be ?
GetValue (tagRef). - Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (tagFunc, tagRef,TemplateLiteral , tailCall).
12.3.12 Meta Properties
12.3.12.1 Runtime Semantics: Evaluation
- Return
GetNewTarget ().
- Let module be !
GetActiveScriptOrModule (). Assert : module is aSource Text Module Record .- Let importMeta be module.[[ImportMeta]].
- If importMeta is
empty , thenSet importMeta to !OrdinaryObjectCreate (null ).- Let importMetaValues be !
HostGetImportMetaProperties (module). - For each
Record { [[Key]], [[Value]] } p that is an element of importMetaValues, do- Perform !
CreateDataPropertyOrThrow (importMeta, p.[[Key]], p.[[Value]]).
- Perform !
- Perform !
HostFinalizeImportMeta (importMeta, module). Set module.[[ImportMeta]] to importMeta.- Return importMeta.
- Else,
12.3.12.1.1 Runtime Semantics: HostGetImportMetaProperties ( moduleRecord )
HostGetImportMetaProperties is an implementation-defined abstract operation that allows hosts to provide property keys and values for the object returned from import.meta.
The implementation of HostGetImportMetaProperties must conform to the following requirements:
- It must return a
List , whose values are all Records with two fields, [[Key]] and [[Value]]. - Each such
Record 's [[Key]] field must be a property key, i.e.,IsPropertyKey must returntrue when applied to it. - Each such
Record 's [[Value]] field must be an ECMAScript value. - It must always complete normally (i.e., not return an
abrupt completion ).
The default implementation of HostGetImportMetaProperties is to return a new empty
12.3.12.1.2 Runtime Semantics: HostFinalizeImportMeta ( importMeta, moduleRecord )
HostFinalizeImportMeta is an implementation-defined abstract operation that allows hosts to perform any extraordinary operations to prepare the object returned from import.meta.
Most hosts will be able to simply define
The implementation of HostFinalizeImportMeta must conform to the following requirements:
- It must always complete normally (i.e., not return an
abrupt completion ).
The default implementation of HostFinalizeImportMeta is to return
12.4 Update Expressions
Syntax
12.4.1 Static Semantics: Early Errors
-
It is an early Syntax Error if AssignmentTargetType of
LeftHandSideExpression is notsimple .
-
It is an early Syntax Error if AssignmentTargetType of
UnaryExpression is notsimple .
12.4.2 Static Semantics: IsFunctionDefinition
- Return
false .
12.4.3 Static Semantics: AssignmentTargetType
- Return
invalid .
12.4.4 Postfix Increment Operator
12.4.4.1 Runtime Semantics: Evaluation
12.4.5 Postfix Decrement Operator
12.4.5.1 Runtime Semantics: Evaluation
12.4.6 Prefix Increment Operator
12.4.6.1 Runtime Semantics: Evaluation
12.4.7 Prefix Decrement Operator
12.4.7.1 Runtime Semantics: Evaluation
12.5 Unary Operators
Syntax
12.5.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.5.2 Static Semantics: AssignmentTargetType
- Return
invalid .
12.5.3 The delete Operator
12.5.3.1 Static Semantics: Early Errors
-
It is a Syntax Error if the
UnaryExpression is contained instrict mode code and the derivedUnaryExpression is .PrimaryExpression : IdentifierReference -
It is a Syntax Error if the derived
UnaryExpression is
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
andCoverParenthesizedExpressionAndArrowParameterList ultimately derives a phrase that, if used in place ofUnaryExpression , would produce a Syntax Error according to these rules. This rule is recursively applied.
The last rule means that expressions such as delete (((foo))) produce early errors because of recursive application of the first rule.
12.5.3.2 Runtime Semantics: Evaluation
- Let ref be the result of evaluating
UnaryExpression . ReturnIfAbrupt (ref).- If
Type (ref) is notReference , returntrue . - If
IsUnresolvableReference (ref) istrue , thenAssert :IsStrictReference (ref) isfalse .- Return
true .
- If
IsPropertyReference (ref) istrue , then- If
IsSuperReference (ref) istrue , throw aReferenceError exception. - Let baseObj be !
ToObject (GetBase (ref)). - Let deleteStatus be ? baseObj.[[Delete]](
GetReferencedName (ref)). - If deleteStatus is
false andIsStrictReference (ref) istrue , throw aTypeError exception. - Return deleteStatus.
- If
- Else,
Assert : ref is aReference to anEnvironment Record binding.- Let bindings be
GetBase (ref). - Return ? bindings.DeleteBinding(
GetReferencedName (ref)).
When a delete operator occurs within delete operator occurs within
12.5.4 The void Operator
12.5.4.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Perform ?
GetValue (expr). - Return
undefined .
12.5.5 The typeof Operator
12.5.5.1 Runtime Semantics: Evaluation
- Let val be the result of evaluating
UnaryExpression . - If
Type (val) isReference , then- If
IsUnresolvableReference (val) istrue , return"undefined" .
- If
Set val to ?GetValue (val).- Return a String according to
Table 35 .
|
|
Result |
|---|---|
| Undefined |
|
| Null |
|
| Boolean |
|
| Number |
|
| String |
|
| Symbol |
|
| BigInt |
|
| Object (does not implement [[Call]]) |
|
| Object (implements [[Call]]) |
|
12.5.6 Unary + Operator
The unary + operator converts its operand to Number
12.5.6.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Return ?
ToNumber (?GetValue (expr)).
12.5.7 Unary - Operator
The unary - operator converts its operand to Number
12.5.7.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Let oldValue be ?
ToNumeric (?GetValue (expr)). - Let T be
Type (oldValue). - Return ! T::unaryMinus(oldValue).
12.5.8 Bitwise NOT Operator ( ~ )
12.5.8.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Let oldValue be ?
ToNumeric (?GetValue (expr)). - Let T be
Type (oldValue). - Return ! T::bitwiseNOT(oldValue).
12.5.9 Logical NOT Operator ( ! )
12.5.9.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Let oldValue be !
ToBoolean (?GetValue (expr)). - If oldValue is
true , returnfalse . - Return
true .
12.6 Exponentiation Operator
Syntax
12.6.1 Static Semantics: IsFunctionDefinition
12.6.2 Static Semantics: AssignmentTargetType
12.6.3 Runtime Semantics: Evaluation
- Let left be the result of evaluating
UpdateExpression . - Let leftValue be ?
GetValue (left). - Let right be the result of evaluating
ExponentiationExpression . - Let rightValue be ?
GetValue (right). - Let base be ?
ToNumeric (leftValue). - Let exponent be ?
ToNumeric (rightValue). - If
Type (base) is different fromType (exponent), throw aTypeError exception. - Return ?
Type (base)::exponentiate(base, exponent).
12.7 Multiplicative Operators
Syntax
12.7.1 Static Semantics: IsFunctionDefinition
12.7.2 Static Semantics: AssignmentTargetType
12.7.3 Runtime Semantics: Evaluation
- Let left be the result of evaluating
MultiplicativeExpression . - Let leftValue be ?
GetValue (left). - Let right be the result of evaluating
ExponentiationExpression . - Let rightValue be ?
GetValue (right). - Let lnum be ?
ToNumeric (leftValue). - Let rnum be ?
ToNumeric (rightValue). - If
Type (lnum) is different fromType (rnum), throw aTypeError exception. - Let T be
Type (lnum). - If
MultiplicativeOperator is*, return T::multiply(lnum, rnum). - If
MultiplicativeOperator is/, return T::divide(lnum, rnum). - Else,
Assert :MultiplicativeOperator is%.- Return T::remainder(lnum, rnum).
12.8 Additive Operators
Syntax
12.8.1 Static Semantics: IsFunctionDefinition
12.8.2 Static Semantics: AssignmentTargetType
- Return
invalid .
12.8.3 The Addition Operator ( + )
The addition operator either performs string concatenation or numeric addition.
12.8.3.1 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
AdditiveExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
MultiplicativeExpression . - Let rval be ?
GetValue (rref). - Let lprim be ?
ToPrimitive (lval). - Let rprim be ?
ToPrimitive (rval). - If
Type (lprim) is String orType (rprim) is String, then- Let lstr be ?
ToString (lprim). - Let rstr be ?
ToString (rprim). - Return the
string-concatenation of lstr and rstr.
- Let lstr be ?
- Let lnum be ?
ToNumeric (lprim). - Let rnum be ?
ToNumeric (rprim). - If
Type (lnum) is different fromType (rnum), throw aTypeError exception. - Let T be
Type (lnum). - Return T::add(lnum, rnum).
No hint is provided in the calls to
Step 7 differs from step 3 of the
12.8.4 The Subtraction Operator ( - )
12.8.4.1 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
AdditiveExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
MultiplicativeExpression . - Let rval be ?
GetValue (rref). - Let lnum be ?
ToNumeric (lval). - Let rnum be ?
ToNumeric (rval). - If
Type (lnum) is different fromType (rnum), throw aTypeError exception. - Let T be
Type (lnum). - Return T::subtract(lnum, rnum).
12.9 Bitwise Shift Operators
Syntax
12.9.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.9.2 Static Semantics: AssignmentTargetType
- Return
invalid .
12.9.3 The Left Shift Operator ( << )
Performs a bitwise left shift operation on the left operand by the amount specified by the right operand.
12.9.3.1 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
ShiftExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
AdditiveExpression . - Let rval be ?
GetValue (rref). - Let lnum be ?
ToNumeric (lval). - Let rnum be ?
ToNumeric (rval). - If
Type (lnum) is different fromType (rnum), throw aTypeError exception. - Let T be
Type (lnum). - Return T::leftShift(lnum, rnum).
12.9.4 The Signed Right Shift Operator ( >> )
Performs a sign-filling bitwise right shift operation on the left operand by the amount specified by the right operand.
12.9.4.1 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
ShiftExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
AdditiveExpression . - Let rval be ?
GetValue (rref). - Let lnum be ?
ToNumeric (lval). - Let rnum be ?
ToNumeric (rval). - If
Type (lnum) is different fromType (rnum), throw aTypeError exception. - Let T be
Type (lnum). - Return T::signedRightShift(lnum, rnum).
12.9.5 The Unsigned Right Shift Operator ( >>> )
Performs a zero-filling bitwise right shift operation on the left operand by the amount specified by the right operand.
12.9.5.1 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
ShiftExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
AdditiveExpression . - Let rval be ?
GetValue (rref). - Let lnum be ?
ToNumeric (lval). - Let rnum be ?
ToNumeric (rval). - If
Type (lnum) is different fromType (rnum), throw aTypeError exception. - Let T be
Type (lnum). - Return T::unsignedRightShift(lnum, rnum).
12.10 Relational Operators
The result of evaluating a relational operator is always of
Syntax
The [In] grammar parameter is needed to avoid confusing the in operator in a relational expression with the in operator in a for statement.
12.10.1 Static Semantics: IsFunctionDefinition
12.10.2 Static Semantics: AssignmentTargetType
12.10.3 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
RelationalExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
ShiftExpression . - Let rval be ?
GetValue (rref). - Let r be the result of performing
Abstract Relational Comparison lval < rval. ReturnIfAbrupt (r).- If r is
undefined , returnfalse . Otherwise, return r.
- Let lref be the result of evaluating
RelationalExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
ShiftExpression . - Let rval be ?
GetValue (rref). - Let r be the result of performing
Abstract Relational Comparison rval < lval with LeftFirst equal tofalse . ReturnIfAbrupt (r).- If r is
undefined , returnfalse . Otherwise, return r.
- Let lref be the result of evaluating
RelationalExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
ShiftExpression . - Let rval be ?
GetValue (rref). - Let r be the result of performing
Abstract Relational Comparison rval < lval with LeftFirst equal tofalse . ReturnIfAbrupt (r).- If r is
true orundefined , returnfalse . Otherwise, returntrue .
- Let lref be the result of evaluating
RelationalExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
ShiftExpression . - Let rval be ?
GetValue (rref). - Let r be the result of performing
Abstract Relational Comparison lval < rval. ReturnIfAbrupt (r).- If r is
true orundefined , returnfalse . Otherwise, returntrue .
- Let lref be the result of evaluating
RelationalExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
ShiftExpression . - Let rval be ?
GetValue (rref). - Return ?
InstanceofOperator (lval, rval).
- Let lref be the result of evaluating
RelationalExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
ShiftExpression . - Let rval be ?
GetValue (rref). - If
Type (rval) is not Object, throw aTypeError exception. - Return ?
HasProperty (rval, ?ToPropertyKey (lval)).
12.10.4 Runtime Semantics: InstanceofOperator ( V, target )
The abstract operation InstanceofOperator(V, target) implements the generic algorithm for determining if ECMAScript value V is an instance of object target either by consulting target's @@hasInstance method or, if absent, determining whether the value of target's
- If
Type (target) is not Object, throw aTypeError exception. - Let instOfHandler be ?
GetMethod (target, @@hasInstance). - If instOfHandler is not
undefined , then - If
IsCallable (target) isfalse , throw aTypeError exception. - Return ?
OrdinaryHasInstance (target, V).
Steps 4 and 5 provide compatibility with previous editions of ECMAScript that did not use a @@hasInstance method to define the instanceof operator semantics. If an object does not define or inherit @@hasInstance it uses the default instanceof semantics.
12.11 Equality Operators
The result of evaluating an equality operator is always of
Syntax
12.11.1 Static Semantics: IsFunctionDefinition
12.11.2 Static Semantics: AssignmentTargetType
12.11.3 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
EqualityExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
RelationalExpression . - Let rval be ?
GetValue (rref). - Return the result of performing
Abstract Equality Comparison rval == lval.
- Let lref be the result of evaluating
EqualityExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
RelationalExpression . - Let rval be ?
GetValue (rref). - Let r be the result of performing
Abstract Equality Comparison rval == lval. ReturnIfAbrupt (r).- If r is
true , returnfalse . Otherwise, returntrue .
- Let lref be the result of evaluating
EqualityExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
RelationalExpression . - Let rval be ?
GetValue (rref). - Return the result of performing
Strict Equality Comparison rval === lval.
- Let lref be the result of evaluating
EqualityExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
RelationalExpression . - Let rval be ?
GetValue (rref). - Let r be the result of performing
Strict Equality Comparison rval === lval. Assert : r is a normal completion.- If r.[[Value]] is
true , returnfalse . Otherwise, returntrue .
Given the above definition of equality:
-
String comparison can be forced by:
\${a}\== \${b}\``. -
Numeric comparison can be forced by:
+a == +b. -
Boolean comparison can be forced by:
!a == !b.
The equality operators maintain the following invariants:
-
A != Bis equivalent to!(A == B). -
A == Bis equivalent toB == A, except in the order of evaluation ofAandB.
The equality operator is not always transitive. For example, there might be two distinct String objects, each representing the same String value; each String object would be considered equal to the String value by the == operator, but the two String objects would not be equal to each other. For example:
-
new String("a") == "a"and"a" == new String("a")are bothtrue . -
new String("a") == new String("a")isfalse .
Comparison of Strings uses a simple equality test on sequences of code unit values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and collating order defined in the Unicode specification. Therefore Strings values that are canonically equal according to the Unicode standard could test as unequal. In effect this algorithm assumes that both Strings are already in normalized form.
12.12 Binary Bitwise Operators
Syntax
12.12.1 Static Semantics: IsFunctionDefinition
12.12.2 Static Semantics: AssignmentTargetType
12.12.3 Runtime Semantics: Evaluation
The production
- Let lref be the result of evaluating A.
- Let lval be ?
GetValue (lref). - Let rref be the result of evaluating B.
- Let rval be ?
GetValue (rref). - Let lnum be ?
ToNumeric (lval). - Let rnum be ?
ToNumeric (rval). - If
Type (lnum) is different fromType (rnum), throw aTypeError exception. - Let T be
Type (lnum). - If @ is
&, return T::bitwiseAND(lnum, rnum). - If @ is
|, return T::bitwiseOR(lnum, rnum). - Else,
Assert : @ is^.- Return T::bitwiseXOR(lnum, rnum).
12.13 Binary Logical Operators
Syntax
The value produced by a && or || operator is not necessarily of
12.13.1 Static Semantics: IsFunctionDefinition
12.13.2 Static Semantics: AssignmentTargetType
12.13.3 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
LogicalANDExpression . - Let lval be ?
GetValue (lref). - Let lbool be !
ToBoolean (lval). - If lbool is
false , return lval. - Let rref be the result of evaluating
BitwiseORExpression . - Return ?
GetValue (rref).
- Let lref be the result of evaluating
LogicalORExpression . - Let lval be ?
GetValue (lref). - Let lbool be !
ToBoolean (lval). - If lbool is
true , return lval. - Let rref be the result of evaluating
LogicalANDExpression . - Return ?
GetValue (rref).
- Let lref be the result of evaluating
CoalesceExpressionHead . - Let lval be ?
GetValue (lref). - If lval is
undefined ornull , then- Let rref be the result of evaluating
BitwiseORExpression . - Return ?
GetValue (rref).
- Let rref be the result of evaluating
- Otherwise, return lval.
12.14 Conditional Operator ( ? : )
Syntax
The grammar for a
12.14.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.14.2 Static Semantics: AssignmentTargetType
- Return
invalid .
12.14.3 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
ShortCircuitExpression . - Let lval be !
ToBoolean (?GetValue (lref)). - If lval is
true , then- Let trueRef be the result of evaluating the first
AssignmentExpression . - Return ?
GetValue (trueRef).
- Let trueRef be the result of evaluating the first
- Else,
- Let falseRef be the result of evaluating the second
AssignmentExpression . - Return ?
GetValue (falseRef).
- Let falseRef be the result of evaluating the second
12.15 Assignment Operators
Syntax
12.15.1 Static Semantics: Early Errors
If
-
It is a Syntax Error if
LeftHandSideExpression is notcovering anAssignmentPattern . -
All Early Error rules for
AssignmentPattern and its derived productions also apply to theAssignmentPattern that iscovered byLeftHandSideExpression .
If
-
It is a Syntax Error if AssignmentTargetType of
LeftHandSideExpression is notsimple .
-
It is a Syntax Error if AssignmentTargetType of
LeftHandSideExpression is notsimple .
12.15.2 Static Semantics: IsFunctionDefinition
12.15.3 Static Semantics: AssignmentTargetType
12.15.4 Runtime Semantics: Evaluation
- If
LeftHandSideExpression is neither anObjectLiteral nor anArrayLiteral , then- Let lref be the result of evaluating
LeftHandSideExpression . ReturnIfAbrupt (lref).- If
IsAnonymousFunctionDefinition (AssignmentExpression ) and IsIdentifierRef ofLeftHandSideExpression are bothtrue , then- Let rval be NamedEvaluation of
AssignmentExpression with argumentGetReferencedName (lref).
- Let rval be NamedEvaluation of
- Else,
- Let rref be the result of evaluating
AssignmentExpression . - Let rval be ?
GetValue (rref).
- Let rref be the result of evaluating
- Perform ?
PutValue (lref, rval). - Return rval.
- Let lref be the result of evaluating
- Let assignmentPattern be the
AssignmentPattern that iscovered byLeftHandSideExpression . - Let rref be the result of evaluating
AssignmentExpression . - Let rval be ?
GetValue (rref). - Perform ? DestructuringAssignmentEvaluation of assignmentPattern using rval as the argument.
- Return rval.
- Let lref be the result of evaluating
LeftHandSideExpression . - Let lval be ?
GetValue (lref). - Let rref be the result of evaluating
AssignmentExpression . - Let rval be ?
GetValue (rref). - Let op be the
@whereAssignmentOperator is@=. - Let r be the result of applying op to lval and rval as if evaluating the expression lval op rval.
- Perform ?
PutValue (lref, r). - Return r.
When an assignment occurs within
12.15.5 Destructuring Assignment
Supplemental Syntax
In certain circumstances when processing an instance of the production
12.15.5.1 Static Semantics: Early Errors
-
It is a Syntax Error if AssignmentTargetType of
IdentifierReference is notsimple .
-
It is a Syntax Error if
DestructuringAssignmentTarget is anArrayLiteral or anObjectLiteral .
If
-
It is a Syntax Error if
LeftHandSideExpression is notcovering anAssignmentPattern . -
All Early Error rules for
AssignmentPattern and its derived productions also apply to theAssignmentPattern that iscovered byLeftHandSideExpression .
If
-
It is a Syntax Error if AssignmentTargetType of
LeftHandSideExpression is notsimple .
12.15.5.2 Runtime Semantics: DestructuringAssignmentEvaluation
With parameter value.
- Perform ?
RequireObjectCoercible (value). - Return
NormalCompletion (empty ).
- Perform ?
RequireObjectCoercible (value). - Perform ? PropertyDestructuringAssignmentEvaluation for
AssignmentPropertyList using value as the argument. - Return
NormalCompletion (empty ).
- Let iteratorRecord be ?
GetIterator (value). - Return ?
IteratorClose (iteratorRecord,NormalCompletion (empty )).
- Let iteratorRecord be ?
GetIterator (value). - Let result be IteratorDestructuringAssignmentEvaluation of
Elision with argument iteratorRecord. - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, result). - Return result.
- Let iteratorRecord be ?
GetIterator (value). - If
Elision is present, then- Let status be IteratorDestructuringAssignmentEvaluation of
Elision with argument iteratorRecord. - If status is an
abrupt completion , thenAssert : iteratorRecord.[[Done]] istrue .- Return
Completion (status).
- Let status be IteratorDestructuringAssignmentEvaluation of
- Let result be IteratorDestructuringAssignmentEvaluation of
AssignmentRestElement with argument iteratorRecord. - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, result). - Return result.
- Let iteratorRecord be ?
GetIterator (value). - Let result be IteratorDestructuringAssignmentEvaluation of
AssignmentElementList with argument iteratorRecord. - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, result). - Return result.
- Let iteratorRecord be ?
GetIterator (value). - Let status be IteratorDestructuringAssignmentEvaluation of
AssignmentElementList with argument iteratorRecord. - If status is an
abrupt completion , then- If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, status). - Return
Completion (status).
- If iteratorRecord.[[Done]] is
- If
Elision is present, thenSet status to the result of performing IteratorDestructuringAssignmentEvaluation ofElision with iteratorRecord as the argument.- If status is an
abrupt completion , thenAssert : iteratorRecord.[[Done]] istrue .- Return
Completion (status).
- If
AssignmentRestElement is present, thenSet status to the result of performing IteratorDestructuringAssignmentEvaluation ofAssignmentRestElement with iteratorRecord as the argument.
- If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, status). - Return
Completion (status).
- Perform ?
RequireObjectCoercible (value). - Let excludedNames be a new empty
List . - Return the result of performing RestDestructuringAssignmentEvaluation of
AssignmentRestProperty with value and excludedNames as the arguments.
- Perform ?
RequireObjectCoercible (value). - Let excludedNames be ? PropertyDestructuringAssignmentEvaluation of
AssignmentPropertyList with argument value. - Return the result of performing RestDestructuringAssignmentEvaluation of
AssignmentRestProperty with arguments value and excludedNames.
12.15.5.3 Runtime Semantics: PropertyDestructuringAssignmentEvaluation
With parameter value.
- Let propertyNames be ? PropertyDestructuringAssignmentEvaluation of
AssignmentPropertyList with argument value. - Let nextNames be ? PropertyDestructuringAssignmentEvaluation of
AssignmentProperty with argument value. - Append each item in nextNames to the end of propertyNames.
- Return propertyNames.
- Let P be StringValue of
IdentifierReference . - Let lref be ?
ResolveBinding (P). - Let v be ?
GetV (value, P). - If
Initializer_opt is present and v isundefined , then- If
IsAnonymousFunctionDefinition (Initializer ) istrue , thenSet v to the result of performing NamedEvaluation forInitializer with argument P.
- Else,
- Let defaultValue be the result of evaluating
Initializer . Set v to ?GetValue (defaultValue).
- Let defaultValue be the result of evaluating
- If
- Perform ?
PutValue (lref, v). - Return a new
List containing P.
- Let name be the result of evaluating
PropertyName . ReturnIfAbrupt (name).- Perform ? KeyedDestructuringAssignmentEvaluation of
AssignmentElement with value and name as the arguments. - Return a new
List containing name.
12.15.5.4 Runtime Semantics: RestDestructuringAssignmentEvaluation
With parameters value and excludedNames.
- Let lref be the result of evaluating
DestructuringAssignmentTarget . ReturnIfAbrupt (lref).- Let restObj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform ?
CopyDataProperties (restObj, value, excludedNames). - Return
PutValue (lref, restObj).
12.15.5.5 Runtime Semantics: IteratorDestructuringAssignmentEvaluation
With parameter iteratorRecord.
- Return the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElisionElement using iteratorRecord as the argument.
- Perform ? IteratorDestructuringAssignmentEvaluation of
AssignmentElementList using iteratorRecord as the argument. - Return the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElisionElement using iteratorRecord as the argument.
- Return the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElement with iteratorRecord as the argument.
- Perform ? IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. - Return the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElement with iteratorRecord as the argument.
- If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue .
- Let next be
- Return
NormalCompletion (empty ).
- Perform ? IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. - If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue .
- Let next be
- Return
NormalCompletion (empty ).
- If
DestructuringAssignmentTarget is neither anObjectLiteral nor anArrayLiteral , then- Let lref be the result of evaluating
DestructuringAssignmentTarget . ReturnIfAbrupt (lref).
- Let lref be the result of evaluating
- If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue . - Else,
- Let value be
IteratorValue (next). - If value is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (value).
- Let value be
- Let next be
- If iteratorRecord.[[Done]] is
true , let value beundefined . - If
Initializer is present and value isundefined , then- If
IsAnonymousFunctionDefinition (Initializer ) and IsIdentifierRef ofDestructuringAssignmentTarget are bothtrue , then- Let v be NamedEvaluation of
Initializer with argumentGetReferencedName (lref).
- Let v be NamedEvaluation of
- Else,
- Let defaultValue be the result of evaluating
Initializer . - Let v be ?
GetValue (defaultValue).
- Let defaultValue be the result of evaluating
- If
- Else, let v be value.
- If
DestructuringAssignmentTarget is anObjectLiteral or anArrayLiteral , then- Let nestedAssignmentPattern be the
AssignmentPattern that iscovered byDestructuringAssignmentTarget . - Return the result of performing DestructuringAssignmentEvaluation of nestedAssignmentPattern with v as the argument.
- Let nestedAssignmentPattern be the
- Return ?
PutValue (lref, v).
Left to right evaluation order is maintained by evaluating a
- If
DestructuringAssignmentTarget is neither anObjectLiteral nor anArrayLiteral , then- Let lref be the result of evaluating
DestructuringAssignmentTarget . ReturnIfAbrupt (lref).
- Let lref be the result of evaluating
- Let A be !
ArrayCreate (0). - Let n be 0.
- Repeat, while iteratorRecord.[[Done]] is
false ,- Let next be
IteratorStep (iteratorRecord). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue . - Else,
- Let nextValue be
IteratorValue (next). - If nextValue is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (nextValue).- Perform !
CreateDataPropertyOrThrow (A, !ToString (n), nextValue). Set n to n + 1.
- Let nextValue be
- Let next be
- If
DestructuringAssignmentTarget is neither anObjectLiteral nor anArrayLiteral , then- Return ?
PutValue (lref, A).
- Return ?
- Let nestedAssignmentPattern be the
AssignmentPattern that iscovered byDestructuringAssignmentTarget . - Return the result of performing DestructuringAssignmentEvaluation of nestedAssignmentPattern with A as the argument.
12.15.5.6 Runtime Semantics: KeyedDestructuringAssignmentEvaluation
With parameters value and propertyName.
- If
DestructuringAssignmentTarget is neither anObjectLiteral nor anArrayLiteral , then- Let lref be the result of evaluating
DestructuringAssignmentTarget . ReturnIfAbrupt (lref).
- Let lref be the result of evaluating
- Let v be ?
GetV (value, propertyName). - If
Initializer is present and v isundefined , then- If
IsAnonymousFunctionDefinition (Initializer ) and IsIdentifierRef ofDestructuringAssignmentTarget are bothtrue , then- Let rhsValue be NamedEvaluation of
Initializer with argumentGetReferencedName (lref).
- Let rhsValue be NamedEvaluation of
- Else,
- Let defaultValue be the result of evaluating
Initializer . - Let rhsValue be ?
GetValue (defaultValue).
- Let defaultValue be the result of evaluating
- If
- Else, let rhsValue be v.
- If
DestructuringAssignmentTarget is anObjectLiteral or anArrayLiteral , then- Let assignmentPattern be the
AssignmentPattern that iscovered byDestructuringAssignmentTarget . - Return the result of performing DestructuringAssignmentEvaluation of assignmentPattern with rhsValue as the argument.
- Let assignmentPattern be the
- Return ?
PutValue (lref, rhsValue).
12.16 Comma Operator ( , )
Syntax
12.16.1 Static Semantics: IsFunctionDefinition
12.16.2 Static Semantics: AssignmentTargetType
12.16.3 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
Expression . - Perform ?
GetValue (lref). - Let rref be the result of evaluating
AssignmentExpression . - Return ?
GetValue (rref).