13 ECMAScript Language: Expressions
13.1 Identifiers
Syntax
yield and await are permitted as
let
await 0;
13.1.1 Static Semantics: Early Errors
-
It is a Syntax Error if
IsStrict (this production) istrue and theStringValue ofIdentifier is either"arguments" or"eval" .
-
It is a Syntax Error if
IsStrict (this production) istrue .
-
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 the
StringValue ofIdentifier is"yield" . -
It is a Syntax Error if this production has an [Await] parameter and the
StringValue ofIdentifier is"await" .
-
It is a Syntax Error if
IsStrict (this phrase) istrue and theStringValue ofIdentifierName is one of"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 theStringValue ofIdentifierName is"await" . -
It is a Syntax Error if the
StringValue ofIdentifierName is theStringValue of anyReservedWord except foryieldorawait.
The
13.1.2 Static Semantics: StringValue
The
- Let idTextUnescaped be the
IdentifierCodePoints ofIdentifierName . - Return
CodePointsToString (idTextUnescaped).
- Return
"yield" .
- Return
"await" .
- Return the StringValue of
IdentifierName .
- Return the
string-concatenation of 0x0023 (NUMBER SIGN) and the StringValue ofIdentifierName .
- Return the
SV ofStringLiteral .
13.1.3 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
13.2 Primary Expression
Syntax
Supplemental Syntax
When processing an instance of the production
the interpretation of
13.2.1 The this Keyword
13.2.1.1 Runtime Semantics: Evaluation
- Return ?
ResolveThisBinding ().
13.2.2 Identifier Reference
See
13.2.3 Literals
13.2.3.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.9.3 .
- Return the
SV ofStringLiteral as defined in12.9.4.2 .
13.2.4 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.4.1 Runtime Semantics: ArrayAccumulation
The
- Return ? ArrayAccumulation of
Elision with arguments array and (nextIndex + 1).
- If
Elision is present, then- Set nextIndex to ? ArrayAccumulation of
Elision with arguments array and nextIndex.
- Set nextIndex to ? ArrayAccumulation of
- Let initResult be ?
Evaluation ofAssignmentExpression . - Let initValue be ?
GetValue (initResult). - Perform !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (nextIndex)), initValue). - Return nextIndex + 1.
- If
Elision is present, then- Set nextIndex to ? ArrayAccumulation of
Elision with arguments array and nextIndex.
- Set nextIndex to ? ArrayAccumulation of
- Return ? ArrayAccumulation of
SpreadElement with arguments array and nextIndex.
- Set nextIndex to ? ArrayAccumulation of the derived
ElementList with arguments array and nextIndex. - If
Elision is present, then- Set nextIndex to ? ArrayAccumulation of
Elision with arguments array and nextIndex.
- Set nextIndex to ? ArrayAccumulation of
- Let initResult be ?
Evaluation ofAssignmentExpression . - Let initValue be ?
GetValue (initResult). - Perform !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (nextIndex)), initValue). - Return nextIndex + 1.
- Set nextIndex to ? ArrayAccumulation of the derived
ElementList with arguments array and nextIndex. - If
Elision is present, then- Set nextIndex to ? ArrayAccumulation of
Elision with arguments array and nextIndex.
- Set nextIndex to ? ArrayAccumulation of
- Return ? ArrayAccumulation of
SpreadElement with arguments array and nextIndex.
- Let spreadRef be ?
Evaluation ofAssignmentExpression . - Let spreadObj be ?
GetValue (spreadRef). - Let iteratorRecord be ?
GetIterator (spreadObj,sync ). - Repeat,
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , return nextIndex. - Perform !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (nextIndex)), next). - Set nextIndex to nextIndex + 1.
- Let next be ?
13.2.4.2 Runtime Semantics: Evaluation
- Let array be !
ArrayCreate (0). - If
Elision is present, then- Perform ?
ArrayAccumulation ofElision with arguments array and 0.
- Perform ?
- Return array.
- Let array be !
ArrayCreate (0). - Perform ?
ArrayAccumulation ofElementList with arguments array and 0. - Return array.
- Let array be !
ArrayCreate (0). - Let nextIndex be ?
ArrayAccumulation ofElementList with arguments array and 0. - If
Elision is present, then- Perform ?
ArrayAccumulation ofElision with arguments array and nextIndex.
- Perform ?
- Return array.
13.2.5 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
Syntax
In certain contexts,
13.2.5.1 Static Semantics: Early Errors
-
It is a Syntax Error if
HasDirectSuper ofMethodDefinition istrue . -
It is a Syntax Error if the
PrivateBoundIdentifiers ofMethodDefinition is not empty.
In addition to describing an actual object initializer the
- It is a Syntax Error if any source text is matched by this production.
This production exists so that
-
It is a Syntax Error if the
PropertyNameList ofPropertyDefinitionList contains any duplicate entries for"__proto__" and at least two of those entries were obtained from productions of the form . This rule is not applied if thisPropertyDefinition : PropertyName : AssignmentExpression ObjectLiteral is contained within aScript that is being parsed forParseJSON (see step3 ofParseJSON ).
The
13.2.5.2 Static Semantics: IsComputedPropertyKey
The
- Return
false .
- Return
true .
13.2.5.3 Static Semantics: PropertyDefinitionNodes
The
- Return a new empty
List .
- Return «
PropertyDefinition ».
- Let head be the PropertyDefinitionNodes of the derived
PropertyDefinitionList . - Return the
list-concatenation of head and «PropertyDefinition ».
13.2.5.4 Static Semantics: PropertyNameList
The
- Let propName be the
PropName ofPropertyDefinition . - If propName is
empty , return a new emptyList . - Return « propName ».
- Let list be the PropertyNameList of
PropertyDefinitionList . - Let propName be the
PropName ofPropertyDefinition . - If propName is
empty , return list. - Return the
list-concatenation of list and « propName ».
13.2.5.5 Runtime Semantics: Evaluation
- Return
OrdinaryObjectCreate (%Object.prototype% ).
- Let obj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform ?
PropertyDefinitionEvaluation ofPropertyDefinitionList with argument obj. - Return obj.
- Return the
StringValue ofIdentifierName .
- Return the
SV ofStringLiteral .
- Let nbr be the
NumericValue ofNumericLiteral . - Return !
ToString (nbr).
- Let exprValue be ?
Evaluation ofAssignmentExpression . - Let propName be ?
GetValue (exprValue). - Return ?
ToPropertyKey (propName).
13.2.5.6 Runtime Semantics: PropertyDefinitionEvaluation
The
- Perform ? PropertyDefinitionEvaluation of
PropertyDefinitionList with argument object. - Perform ? PropertyDefinitionEvaluation of
PropertyDefinition with argument object. - Return
unused .
- Let exprValue be ?
Evaluation ofAssignmentExpression . - Let fromValue be ?
GetValue (exprValue). - Let excludedNames be a new empty
List . - Perform ?
CopyDataProperties (object, fromValue, excludedNames). - Return
unused .
- Let propName be the
StringValue ofIdentifierReference . - Let exprValue be ?
Evaluation ofIdentifierReference . - Let propValue be ?
GetValue (exprValue). Assert : object is an ordinary, extensible object with no non-configurable properties.- Perform !
CreateDataPropertyOrThrow (object, propName, propValue). - Return
unused .
- Let propKey be ?
Evaluation ofPropertyName . - If this
PropertyDefinition is contained within aScript that is being evaluated forParseJSON (see step6 ofParseJSON ), then- Let isProtoSetter be
false .
- Let isProtoSetter be
- Else if propKey is
"__proto__" andIsComputedPropertyKey ofPropertyName isfalse , then- Let isProtoSetter be
true .
- Let isProtoSetter be
- Else,
- Let isProtoSetter be
false .
- Let isProtoSetter be
- If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue and isProtoSetter isfalse , then- Let propValue be ?
NamedEvaluation ofAssignmentExpression with argument propKey.
- Let propValue be ?
- Else,
- Let exprValueRef be ?
Evaluation ofAssignmentExpression . - Let propValue be ?
GetValue (exprValueRef).
- Let exprValueRef be ?
- If isProtoSetter is
true , then- If propValue
is an Object or propValue isnull , then- Perform !
object.[[SetPrototypeOf]](propValue) .
- Perform !
- Return
unused .
- If propValue
Assert : object is an ordinary, extensible object with no non-configurable properties.- Perform !
CreateDataPropertyOrThrow (object, propKey, propValue). - Return
unused .
- Perform ?
MethodDefinitionEvaluation ofMethodDefinition with arguments object andtrue . - Return
unused .
13.2.6 Function Defining Expressions
See
See
See
See
See
13.2.7 Regular Expression Literals
Syntax
See
13.2.7.1 Static Semantics: Early Errors
-
It is a Syntax Error if
IsValidRegularExpressionLiteral (RegularExpressionLiteral ) isfalse .
13.2.7.2 Static Semantics: IsValidRegularExpressionLiteral ( literal )
The abstract operation IsValidRegularExpressionLiteral takes argument literal (a
- Let flags be the
FlagText of literal. - If flags contains any code points other than
d,g,i,m,s,u,v, ory, or if flags contains any code point more than once, returnfalse . - If flags contains
u, let u betrue ; else let u befalse . - If flags contains
v, let v betrue ; else let v befalse . - Let patternText be the
BodyText of literal. - If u is
false and v isfalse , 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, v). - If parseResult is a
Parse Node , returntrue . - Return
false .
13.2.7.3 Runtime Semantics: Evaluation
- Let pattern be
CodePointsToString (BodyText ofRegularExpressionLiteral ). - Let flags be
CodePointsToString (FlagText ofRegularExpressionLiteral ). - Return !
RegExpCreate (pattern, flags).
13.2.8 Template Literals
Syntax
13.2.8.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
TemplateStrings ofTemplateLiteral with argumentfalse is greater than or equal to 232.
-
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.8.2 Static Semantics: TemplateStrings
The
- Return «
TemplateString (NoSubstitutionTemplate , raw) ».
- Let head be «
TemplateString (TemplateHead , raw) ». - Let tail be the TemplateStrings of
TemplateSpans with argument raw. - Return the
list-concatenation of head and tail.
- Return «
TemplateString (TemplateTail , raw) ».
- Let middle be the TemplateStrings of
TemplateMiddleList with argument raw. - Let tail be «
TemplateString (TemplateTail , raw) ». - Return the
list-concatenation of middle and tail.
- Return «
TemplateString (TemplateMiddle , raw) ».
- Let front be the TemplateStrings of
TemplateMiddleList with argument raw. - Let last be «
TemplateString (TemplateMiddle , raw) ». - Return the
list-concatenation of front and last.
13.2.8.3 Static Semantics: TemplateString ( templateToken, raw )
The abstract operation TemplateString takes arguments templateToken (a
This operation returns
13.2.8.4 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 the
TemplateStrings of templateLiteral with argumenttrue . Assert : rawStrings is aList of Strings.- Let cookedStrings be the
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 realm.[[TemplateMap]]. - 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.8.5 Runtime Semantics: SubstitutionEvaluation
The
- Return a new empty
List .
- Return ? SubstitutionEvaluation of
TemplateMiddleList .
- Let subRef be ?
Evaluation ofExpression . - Let sub be ?
GetValue (subRef). - Return « sub ».
- Let preceding be ? SubstitutionEvaluation of
TemplateMiddleList . - Let nextRef be ?
Evaluation ofExpression . - Let next be ?
GetValue (nextRef). - Return the
list-concatenation of preceding and « next ».
13.2.8.6 Runtime Semantics: Evaluation
- Return the
TV ofNoSubstitutionTemplate as defined in12.9.6 .
- Let head be the
TV ofTemplateHead as defined in12.9.6 . - Let subRef be ?
Evaluation ofExpression . - Let sub be ?
GetValue (subRef). - Let middle be ?
ToString (sub). - Let tail be ?
Evaluation ofTemplateSpans . - 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 ofTemplateTail as defined in12.9.6 .
- Let head be ?
Evaluation ofTemplateMiddleList . - Let tail be the
TV ofTemplateTail as defined in12.9.6 . - Return the
string-concatenation of head and tail.
- Let head be the
TV ofTemplateMiddle as defined in12.9.6 . - Let subRef be ?
Evaluation ofExpression . - 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 ?
Evaluation ofTemplateMiddleList . - Let middle be the
TV ofTemplateMiddle as defined in12.9.6 . - Let subRef be ?
Evaluation ofExpression . - 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.9 The Grouping Operator
13.2.9.1 Static Semantics: Early Errors
13.2.9.2 Runtime Semantics: Evaluation
- Let expr be the
ParenthesizedExpression that iscovered byCoverParenthesizedExpressionAndArrowParameterList . - Return ?
Evaluation of expr.
- Return ?
Evaluation ofExpression . This may be of type Reference.
This algorithm does not apply delete and typeof may be applied to parenthesized expressions.
13.3 Left-Hand-Side Expressions
Syntax
Supplemental Syntax
When processing an instance of the production
the interpretation of
13.3.1 Static Semantics
13.3.1.1 Static Semantics: Early Errors
- It is a Syntax Error if any source text is matched by 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 .
13.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
13.3.2.1 Runtime Semantics: Evaluation
- Let baseReference be ?
Evaluation ofMemberExpression . - Let baseValue be ?
GetValue (baseReference). - Let strict be
IsStrict (thisMemberExpression ). - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- Let baseReference be ?
Evaluation ofMemberExpression . - Let baseValue be ?
GetValue (baseReference). - Let strict be
IsStrict (thisMemberExpression ). - Return
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
- Let baseReference be ?
Evaluation ofMemberExpression . - Let baseValue be ?
GetValue (baseReference). - Let fieldNameString be the
StringValue ofPrivateIdentifier . - Return
MakePrivateReference (baseValue, fieldNameString).
- Let baseReference be ?
Evaluation ofCallExpression . - Let baseValue be ?
GetValue (baseReference). - Let strict be
IsStrict (thisCallExpression ). - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- Let baseReference be ?
Evaluation ofCallExpression . - Let baseValue be ?
GetValue (baseReference). - Let strict be
IsStrict (thisCallExpression ). - Return
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
- Let baseReference be ?
Evaluation ofCallExpression . - Let baseValue be ?
GetValue (baseReference). - Let fieldNameString be the
StringValue ofPrivateIdentifier . - Return
MakePrivateReference (baseValue, fieldNameString).
13.3.3 EvaluatePropertyAccessWithExpressionKey ( baseValue, expression, strict )
The abstract operation EvaluatePropertyAccessWithExpressionKey takes arguments baseValue (an
- Let propertyNameReference be ?
Evaluation of expression. - Let propertyNameValue be ?
GetValue (propertyNameReference). - NOTE: In most cases,
ToPropertyKey will be performed on propertyNameValue immediately after this step. However, in the case ofa[b] = c, it will not be performed until after evaluation ofc. - Return the
Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyNameValue, [[Strict]]: strict, [[ThisValue]]:empty }.
13.3.4 EvaluatePropertyAccessWithIdentifierKey ( baseValue, identifierName, strict )
The abstract operation EvaluatePropertyAccessWithIdentifierKey takes arguments baseValue (an
- Let propertyNameString be the
StringValue of identifierName. - Return the
Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyNameString, [[Strict]]: strict, [[ThisValue]]:empty }.
13.3.5 The new Operator
13.3.5.1 Runtime Semantics: Evaluation
- Return ?
EvaluateNew (NewExpression ,empty ).
- Return ?
EvaluateNew (MemberExpression ,Arguments ).
13.3.5.1.1 EvaluateNew ( constructExpr, arguments )
The abstract operation EvaluateNew takes arguments constructExpr (a
- Let ref be ?
Evaluation of constructExpr. - Let constructor be ?
GetValue (ref). - If arguments is
empty , then- Let argList be a new empty
List .
- Let argList be a new empty
- Else,
- Let argList be ?
ArgumentListEvaluation of arguments.
- Let argList be ?
- If
IsConstructor (constructor) isfalse , throw aTypeError exception. - Return ?
Construct (constructor, argList).
13.3.6 Function Calls
13.3.6.1 Runtime Semantics: Evaluation
- Let expr be the
CallMemberExpression that iscovered byCoverCallExpressionAndAsyncArrowHead . - Let memberExpr be the
MemberExpression of expr. - Let arguments be the
Arguments of expr. - Let ref be ?
Evaluation of memberExpr. - Let func be ?
GetValue (ref). - If ref is a
Reference Record ,IsPropertyReference (ref) isfalse , and ref.[[ReferencedName]] 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
IsStrict (thisCallExpression ) istrue , let strictCaller betrue ; else let strictCaller befalse . - Return ?
PerformEval (evalArg, strictCaller,true ).
- Let argList be ?
- If
- Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (func, ref, arguments, tailCall).
A
- Let ref be ?
Evaluation ofCallExpression . - Let func be ?
GetValue (ref). - Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (func, ref,Arguments , tailCall).
13.3.6.2 EvaluateCall ( func, ref, arguments, tailPosition )
The abstract operation EvaluateCall takes arguments func (an
- If ref is a
Reference Record , then- If
IsPropertyReference (ref) istrue , then- Let thisValue be
GetThisValue (ref).
- Let thisValue be
- Else,
- Let refEnv be ref.[[Base]].
Assert : refEnv is anEnvironment Record .- Let thisValue be refEnv.WithBaseObject().
- If
- Else,
- Let thisValue be
undefined .
- Let thisValue be
- Let argList be ?
ArgumentListEvaluation of arguments. - If func
is not an Object , throw aTypeError exception. - If
IsCallable (func) isfalse , throw aTypeError exception. - If tailPosition is
true , performPrepareForTailCall (). - Return ?
Call (func, thisValue, argList).
13.3.7 The super Keyword
13.3.7.1 Runtime Semantics: Evaluation
- Let env be
GetThisEnvironment (). - Let actualThis be ? env.GetThisBinding().
- Let propertyNameReference be ?
Evaluation ofExpression . - Let propertyNameValue be ?
GetValue (propertyNameReference). - Let strict be
IsStrict (thisSuperProperty ). - NOTE: In most cases,
ToPropertyKey will be performed on propertyNameValue immediately after this step. However, in the case ofsuper[b] = c, it will not be performed until after evaluation ofc. - Return
MakeSuperPropertyReference (actualThis, propertyNameValue, strict).
- Let env be
GetThisEnvironment (). - Let actualThis be ? env.GetThisBinding().
- Let propertyKey be the
StringValue ofIdentifierName . - Let strict be
IsStrict (thisSuperProperty ). - Return
MakeSuperPropertyReference (actualThis, propertyKey, strict).
- Let newTarget be
GetNewTarget (). Assert : newTarget is aconstructor .- Let func be
GetSuperConstructor (). - Let argList be ?
ArgumentListEvaluation ofArguments . - If
IsConstructor (func) isfalse , throw aTypeError exception. - Let result be ?
Construct (func, argList, newTarget). - Let thisER be
GetThisEnvironment (). Assert : thisER is aFunction Environment Record .- Perform ?
BindThisValue (thisER, result). - Let F be thisER.[[FunctionObject]].
Assert : F is an ECMAScriptfunction object .- Perform ?
InitializeInstanceElements (result, F). - Return result.
13.3.7.2 GetSuperConstructor ( )
The abstract operation GetSuperConstructor takes no arguments and returns an
- 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.
13.3.7.3 MakeSuperPropertyReference ( actualThis, propertyKey, strict )
The abstract operation MakeSuperPropertyReference takes arguments actualThis (an
- Let env be
GetThisEnvironment (). Assert : env.HasSuperBinding() istrue .Assert : env is aFunction Environment Record .- Let baseValue be
GetSuperBase (env). - Return the
Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }.
13.3.8 Argument Lists
The evaluation of an argument list produces a
13.3.8.1 Runtime Semantics: ArgumentListEvaluation
The
- Return a new empty
List .
- Let ref be ?
Evaluation ofAssignmentExpression . - Let arg be ?
GetValue (ref). - Return « arg ».
- Let list be a new empty
List . - Let spreadRef be ?
Evaluation ofAssignmentExpression . - Let spreadObj be ?
GetValue (spreadRef). - Let iteratorRecord be ?
GetIterator (spreadObj,sync ). - Repeat,
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , return list. - Append next to list.
- Let next be ?
- Let precedingArgs be ? ArgumentListEvaluation of
ArgumentList . - Let ref be ?
Evaluation ofAssignmentExpression . - Let arg be ?
GetValue (ref). - Return the
list-concatenation of precedingArgs and « arg ».
- Let precedingArgs be ? ArgumentListEvaluation of
ArgumentList . - Let spreadRef be ?
Evaluation ofAssignmentExpression . - Let iteratorRecord be ?
GetIterator (?GetValue (spreadRef),sync ). - Repeat,
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , return precedingArgs. - Append next to precedingArgs.
- Let next be ?
- Let templateLiteral be this
TemplateLiteral . - Let siteObj be
GetTemplateObject (templateLiteral). - Return « siteObj ».
- Let templateLiteral be this
TemplateLiteral . - Let siteObj be
GetTemplateObject (templateLiteral). - Let remaining be ? ArgumentListEvaluation of
SubstitutionTemplate . - Return the
list-concatenation of « siteObj » and remaining.
- Let firstSubRef be ?
Evaluation ofExpression . - Let firstSub be ?
GetValue (firstSubRef). - Let restSub be ?
SubstitutionEvaluation ofTemplateSpans . Assert : restSub is a possibly emptyList .- Return the
list-concatenation of « firstSub » and restSub.
13.3.9 Optional Chains
?..13.3.9.1 Runtime Semantics: Evaluation
- Let baseReference be ?
Evaluation ofMemberExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is either
undefined ornull , then- Return
undefined .
- Return
- Return ?
ChainEvaluation ofOptionalChain with arguments baseValue and baseReference.
- Let baseReference be ?
Evaluation ofCallExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is either
undefined ornull , then- Return
undefined .
- Return
- Return ?
ChainEvaluation ofOptionalChain with arguments baseValue and baseReference.
- Let baseReference be ?
Evaluation ofOptionalExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is either
undefined ornull , then- Return
undefined .
- Return
- Return ?
ChainEvaluation ofOptionalChain with arguments baseValue and baseReference.
13.3.9.2 Runtime Semantics: ChainEvaluation
The
- Let thisChain be this
OptionalChain . - Let tailCall be
IsInTailPosition (thisChain). - Return ?
EvaluateCall (baseValue, baseReference,Arguments , tailCall).
- Let strict be
IsStrict (thisOptionalChain ). - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- Let strict be
IsStrict (thisOptionalChain ). - Return
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
- Let fieldNameString be the
StringValue ofPrivateIdentifier . - Return
MakePrivateReference (baseValue, fieldNameString).
- 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). - Let strict be
IsStrict (thisOptionalChain ). - 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). - Let strict be
IsStrict (thisOptionalChain ). - Return
EvaluatePropertyAccessWithIdentifierKey (newValue,IdentifierName , strict).
- Let optionalChain be
OptionalChain . - Let newReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
- Let newValue be ?
GetValue (newReference). - Let fieldNameString be the
StringValue ofPrivateIdentifier . - Return
MakePrivateReference (newValue, fieldNameString).
13.3.10 Import Calls
13.3.10.1 Runtime Semantics: Evaluation
- Return ?
EvaluateImportCall (AssignmentExpression ).
- Return ?
EvaluateImportCall (the firstAssignmentExpression , the secondAssignmentExpression ).
13.3.10.2 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
The abstract operation EvaluateImportCall takes argument specifierExpression (a
- Let referrer be
GetActiveScriptOrModule (). - If referrer is
null , set referrer tothe current Realm Record . - Let specifierRef be ?
Evaluation of specifierExpression. - Let specifier be ?
GetValue (specifierRef). - If optionsExpression is present, then
- Let optionsRef be ?
Evaluation of optionsExpression. - Let options be ?
GetValue (optionsRef).
- Let optionsRef be ?
- Else,
- Let options be
undefined .
- Let options be
- Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let specifierString be
Completion (ToString (specifier)). IfAbruptRejectPromise (specifierString, promiseCapability).- Let attributes be a new empty
List . - If options is not
undefined , then- If options
is not an Object , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « a newly createdTypeError object »). - Return promiseCapability.[[Promise]].
- Perform !
- Let attributesObj be
Completion (Get (options,"with" )). IfAbruptRejectPromise (attributesObj, promiseCapability).- If attributesObj is not
undefined , then- If attributesObj
is not an Object , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « a newly createdTypeError object »). - Return promiseCapability.[[Promise]].
- Perform !
- Let entries be
Completion (EnumerableOwnProperties (attributesObj,key+value )). IfAbruptRejectPromise (entries, promiseCapability).- For each element entry of entries, do
- Let key be !
Get (entry,"0" ). - Let value be !
Get (entry,"1" ). - If key
is a String , then- If value
is not a String , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « a newly createdTypeError object »). - Return promiseCapability.[[Promise]].
- Perform !
- Append the
ImportAttribute Record { [[Key]]: key, [[Value]]: value } to attributes.
- If value
- Let key be !
- If attributesObj
- If
AllImportAttributesSupported (attributes) isfalse , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « a newly createdTypeError object »). - Return promiseCapability.[[Promise]].
- Perform !
- Sort attributes according to the lexicographic order of their [[Key]] field, treating the value of each such field as a sequence of UTF-16 code unit values. NOTE: This sorting is observable only in that
hosts are prohibited from changing behaviour based on the order in which attributes are enumerated.
- If options
- Let moduleRequest be a new
ModuleRequest Record { [[Specifier]]: specifierString, [[Attributes]]: attributes }. - Perform
HostLoadImportedModule (referrer, moduleRequest,empty , promiseCapability). - Return promiseCapability.[[Promise]].
13.3.10.3 ContinueDynamicImport ( promiseCapability, moduleCompletion )
The abstract operation ContinueDynamicImport takes arguments promiseCapability (a import()
- If moduleCompletion is an
abrupt completion , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « moduleCompletion.[[Value]] »). - Return
unused .
- Perform !
- Let module be moduleCompletion.[[Value]].
- Let loadPromise be module.LoadRequestedModules().
- Let rejectedClosure be a new
Abstract Closure with parameters (reason) that captures promiseCapability and performs the following steps when called:- Perform !
Call (promiseCapability.[[Reject]],undefined , « reason »). - Return
NormalCompletion (undefined ).
- Perform !
- Let onRejected be
CreateBuiltinFunction (rejectedClosure, 1,"" , « »). - Let linkAndEvaluateClosure be a new
Abstract Closure with no parameters that captures module, promiseCapability, and onRejected and performs the following steps when called:- Let link be
Completion (module.Link()). - If link is an
abrupt completion , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « link.[[Value]] »). - Return
NormalCompletion (undefined ).
- Perform !
- Let evaluatePromise be module.Evaluate().
- Let fulfilledClosure be a new
Abstract Closure with no parameters that captures module and promiseCapability and performs the following steps when called:- Let namespace be
GetModuleNamespace (module). - Perform !
.Call (promiseCapability.[[Resolve]],undefined , « namespace ») - Return
NormalCompletion (undefined ).
- Let namespace be
- Let onFulfilled be
CreateBuiltinFunction (fulfilledClosure, 0,"" , « »). - Perform
PerformPromiseThen (evaluatePromise, onFulfilled, onRejected). - Return
unused .
- Let link be
- Let linkAndEvaluate be
CreateBuiltinFunction (linkAndEvaluateClosure, 0,"" , « »). - Perform
PerformPromiseThen (loadPromise, linkAndEvaluate, onRejected). - Return
unused .
13.3.11 Tagged Templates
A tagged template is a function call where the arguments of the call are derived from a
13.3.11.1 Runtime Semantics: Evaluation
- Let tagRef be ?
Evaluation ofMemberExpression . - Let tagFunc be ?
GetValue (tagRef). - Let thisCall be this
MemberExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (tagFunc, tagRef,TemplateLiteral , tailCall).
- Let tagRef be ?
Evaluation ofCallExpression . - Let tagFunc be ?
GetValue (tagRef). - Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (tagFunc, tagRef,TemplateLiteral , tailCall).
13.3.12 Meta Properties
13.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 , then- Set importMeta to
OrdinaryObjectCreate (null ). - Let importMetaValues be
HostGetImportMetaProperties (module). - For each
Record { [[Key]], [[Value]] } p of importMetaValues, do- Perform !
CreateDataPropertyOrThrow (importMeta, p.[[Key]], p.[[Value]]).
- Perform !
- Perform
HostFinalizeImportMeta (importMeta, module). - Set module.[[ImportMeta]] to importMeta.
- Return importMeta.
- Set importMeta to
Assert : importMetais an Object .- Return importMeta.
13.3.12.1.1 HostGetImportMetaProperties ( moduleRecord )
The import.meta.
The default implementation of HostGetImportMetaProperties is to return a new empty
13.3.12.1.2 HostFinalizeImportMeta ( importMeta, moduleRecord )
The import.meta.
Most
The default implementation of HostFinalizeImportMeta is to return
13.4 Update Expressions
Syntax
13.4.1 Static Semantics: Early Errors
-
It is an early Syntax Error if the
AssignmentTargetType ofLeftHandSideExpression isinvalid .
-
It is an early Syntax Error if the
AssignmentTargetType ofUnaryExpression isinvalid .
13.4.2 Postfix Increment Operator
13.4.2.1 Runtime Semantics: Evaluation
- Let lhs be ?
Evaluation ofLeftHandSideExpression . - If the
AssignmentTargetType ofLeftHandSideExpression isweb-compat , throw aReferenceError exception. - Let oldValue be ?
ToNumeric (?GetValue (lhs)). - If oldValue
is a Number , then- Let newValue be
Number::add (oldValue,1 𝔽).
- Let newValue be
- Else,
Assert : oldValueis a BigInt .- Let newValue be
BigInt::add (oldValue,1 ℤ).
- Perform ?
PutValue (lhs, newValue). - Return oldValue.
13.4.3 Postfix Decrement Operator
13.4.3.1 Runtime Semantics: Evaluation
- Let lhs be ?
Evaluation ofLeftHandSideExpression . - If the
AssignmentTargetType ofLeftHandSideExpression isweb-compat , throw aReferenceError exception. - Let oldValue be ?
ToNumeric (?GetValue (lhs)). - If oldValue
is a Number , then- Let newValue be
Number::subtract (oldValue,1 𝔽).
- Let newValue be
- Else,
Assert : oldValueis a BigInt .- Let newValue be
BigInt::subtract (oldValue,1 ℤ).
- Perform ?
PutValue (lhs, newValue). - Return oldValue.
13.4.4 Prefix Increment Operator
13.4.4.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - If the
AssignmentTargetType ofUnaryExpression isweb-compat , throw aReferenceError exception. - Let oldValue be ?
ToNumeric (?GetValue (expr)). - If oldValue
is a Number , then- Let newValue be
Number::add (oldValue,1 𝔽).
- Let newValue be
- Else,
Assert : oldValueis a BigInt .- Let newValue be
BigInt::add (oldValue,1 ℤ).
- Perform ?
PutValue (expr, newValue). - Return newValue.
13.4.5 Prefix Decrement Operator
13.4.5.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - If the
AssignmentTargetType ofUnaryExpression isweb-compat , throw aReferenceError exception. - Let oldValue be ?
ToNumeric (?GetValue (expr)). - If oldValue
is a Number , then- Let newValue be
Number::subtract (oldValue,1 𝔽).
- Let newValue be
- Else,
Assert : oldValueis a BigInt .- Let newValue be
BigInt::subtract (oldValue,1 ℤ).
- Perform ?
PutValue (expr, newValue). - Return newValue.
13.5 Unary Operators
Syntax
13.5.1 The delete Operator
13.5.1.1 Static Semantics: Early Errors
-
It is a Syntax Error if
IsStrict (theUnaryExpression ) istrue and the derivedUnaryExpression is ,PrimaryExpression : IdentifierReference ,MemberExpression : MemberExpression . PrivateIdentifier ,CallExpression : CallExpression . PrivateIdentifier , orOptionalChain : ?. PrivateIdentifier .OptionalChain : OptionalChain . PrivateIdentifier -
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
13.5.1.2 Runtime Semantics: Evaluation
- Let ref be ?
Evaluation ofUnaryExpression . - If ref is not a
Reference Record , returntrue . - If
IsUnresolvableReference (ref) istrue , thenAssert : ref.[[Strict]] isfalse .- Return
true .
- If
IsPropertyReference (ref) istrue , thenAssert :IsPrivateReference (ref) isfalse .- If
IsSuperReference (ref) istrue , throw aReferenceError exception. - Let baseObj be ?
ToObject (ref.[[Base]]). - If ref.[[ReferencedName]] is not a
property key , then- Set ref.[[ReferencedName]] to ?
ToPropertyKey (ref.[[ReferencedName]]).
- Set ref.[[ReferencedName]] to ?
- Let deleteStatus be ?
baseObj.[[Delete]](ref.[[ReferencedName]]) . - If deleteStatus is
false and ref.[[Strict]] istrue , throw aTypeError exception. - Return deleteStatus.
- Let base be ref.[[Base]].
Assert : base is anEnvironment Record .- Return ?
base.DeleteBinding(ref.[[ReferencedName]]) .
When a delete operator occurs within delete operator occurs within
The object that may be created in step
13.5.2 The void Operator
13.5.2.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Perform ?
GetValue (expr). - Return
undefined .
13.5.3 The typeof Operator
13.5.3.1 Runtime Semantics: Evaluation
- Let val be ?
Evaluation ofUnaryExpression . - If val is a
Reference Record , then- If
IsUnresolvableReference (val) istrue , return"undefined" .
- If
- Set val to ?
GetValue (val). - If val is
undefined , return"undefined" . - If val is
null , return"object" . - If val
is a String , return"string" . - If val
is a Symbol , return"symbol" . - If val
is a Boolean , return"boolean" . - If val
is a Number , return"number" . - If val
is a BigInt , return"bigint" . Assert : valis an Object .- If the
host is a web browser orotherwise supports The [[IsHTMLDDA]] Internal Slot , then- If val has an [[IsHTMLDDA]] internal slot, return
"undefined" .
- If val has an [[IsHTMLDDA]] internal slot, return
- If val has a [[Call]] internal method, return
"function" . - Return
"object" .
13.5.4 Unary + Operator
The unary + operator converts its operand to
13.5.4.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Return ?
ToNumber (?GetValue (expr)).
13.5.5 Unary - Operator
The unary - operator converts its operand to a numeric value and then negates it. Negating
13.5.5.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Let oldValue be ?
ToNumeric (?GetValue (expr)). - If oldValue
is a Number , returnNumber::unaryMinus (oldValue). Assert : oldValueis a BigInt .- Return
BigInt::unaryMinus (oldValue).
13.5.6 Bitwise NOT Operator ( ~ )
13.5.6.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Let oldValue be ?
ToNumeric (?GetValue (expr)). - If oldValue
is a Number , returnNumber::bitwiseNOT (oldValue). Assert : oldValueis a BigInt .- Return
BigInt::bitwiseNOT (oldValue).
13.5.7 Logical NOT Operator ( ! )
13.5.7.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Let oldValue be
ToBoolean (?GetValue (expr)). - If oldValue is
true , returnfalse . - Return
true .
13.6 Exponentiation Operator
Syntax
13.6.1 Runtime Semantics: Evaluation
13.7 Multiplicative Operators
Syntax
- The
*operator performs multiplication, producing the product of its operands. - The
/operator performs division, producing the quotient of its operands. - The
%operator yields the remainder of its operands from an implied division.
13.7.1 Runtime Semantics: Evaluation
13.8 Additive Operators
Syntax
13.8.1 The Addition Operator ( + )
The addition operator either performs string concatenation or numeric addition.
13.8.1.1 Runtime Semantics: Evaluation
13.8.2 The Subtraction Operator ( - )
The - operator performs subtraction, producing the difference of its operands.
13.8.2.1 Runtime Semantics: Evaluation
13.9 Bitwise Shift Operators
Syntax
13.9.1 The Left Shift Operator ( << )
Performs a bitwise left shift operation on the left operand by the amount specified by the right operand.
13.9.1.1 Runtime Semantics: Evaluation
13.9.2 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.
13.9.2.1 Runtime Semantics: Evaluation
13.9.3 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.
13.9.3.1 Runtime Semantics: Evaluation
13.10 Relational Operators
The result of evaluating a relational operator is always of type Boolean, reflecting whether the relationship named by the operator holds between its two operands.
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.
13.10.1 Runtime Semantics: Evaluation
- Let lRef be ?
Evaluation ofRelationalExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofShiftExpression . - Let rVal be ?
GetValue (rRef). - Let r be ?
IsLessThan (lVal, rVal,true ). - If r is
undefined , returnfalse . - Return r.
- Let lRef be ?
Evaluation ofRelationalExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofShiftExpression . - Let rVal be ?
GetValue (rRef). - Let r be ?
IsLessThan (rVal, lVal,false ). - If r is
undefined , returnfalse . - Return r.
- Let lRef be ?
Evaluation ofRelationalExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofShiftExpression . - Let rVal be ?
GetValue (rRef). - Let r be ?
IsLessThan (rVal, lVal,false ). - If r is either
true orundefined , returnfalse . - Return
true .
- Let lRef be ?
Evaluation ofRelationalExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofShiftExpression . - Let rVal be ?
GetValue (rRef). - Let r be ?
IsLessThan (lVal, rVal,true ). - If r is either
true orundefined , returnfalse . - Return
true .
- Let lRef be ?
Evaluation ofRelationalExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofShiftExpression . - Let rVal be ?
GetValue (rRef). - Return ?
InstanceofOperator (lVal, rVal).
- Let lRef be ?
Evaluation ofRelationalExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofShiftExpression . - Let rVal be ?
GetValue (rRef). - If rVal
is not an Object , throw aTypeError exception. - Return ?
HasProperty (rVal, ?ToPropertyKey (lVal)).
- Let privateIdentifier be the
StringValue ofPrivateIdentifier . - Let rRef be ?
Evaluation ofShiftExpression . - Let rVal be ?
GetValue (rRef). - If rVal
is not an Object , throw aTypeError exception. - Let privateEnv be the
running execution context 's PrivateEnvironment. Assert : privateEnv is notnull .- Let privateName be
ResolvePrivateIdentifier (privateEnv, privateIdentifier). - If
PrivateElementFind (rVal, privateName) isempty , returnfalse . - Return
true .
13.10.2 InstanceofOperator ( V, target )
The abstract operation InstanceofOperator takes arguments V (an
- If target
is not an Object , throw aTypeError exception. - Let instOfHandler be ?
GetMethod (target,%Symbol.hasInstance% ). - If instOfHandler is not
undefined , then - If
IsCallable (target) isfalse , throw aTypeError exception. - Return ?
OrdinaryHasInstance (target, V).
13.11 Equality Operators
The result of evaluating an equality operator is always of type Boolean, reflecting whether the relationship named by the operator holds between its two operands.
Syntax
13.11.1 Runtime Semantics: Evaluation
- Let lRef be ?
Evaluation ofEqualityExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofRelationalExpression . - Let rVal be ?
GetValue (rRef). - Return ?
IsLooselyEqual (rVal, lVal).
- Let lRef be ?
Evaluation ofEqualityExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofRelationalExpression . - Let rVal be ?
GetValue (rRef). - Let r be ?
IsLooselyEqual (rVal, lVal). - If r is
true , returnfalse . - Return
true .
- Let lRef be ?
Evaluation ofEqualityExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofRelationalExpression . - Let rVal be ?
GetValue (rRef). - Return
IsStrictlyEqual (rVal, lVal).
- Let lRef be ?
Evaluation ofEqualityExpression . - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofRelationalExpression . - Let rVal be ?
GetValue (rRef). - Let r be
IsStrictlyEqual (rVal, lVal). - If r is
true , returnfalse . - Return
true .
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.
13.12 Binary Bitwise Operators
Syntax
13.12.1 Runtime Semantics: Evaluation
13.13 Binary Logical Operators
Syntax
The value produced by a && or || operator is not necessarily of type Boolean. The value produced will always be the value of one of the two operand expressions.
13.13.1 Runtime Semantics: Evaluation
- Let lRef be ?
Evaluation ofLogicalANDExpression . - Let lVal be ?
GetValue (lRef). - If
ToBoolean (lVal) isfalse , return lVal. - Let rRef be ?
Evaluation ofBitwiseORExpression . - Return ?
GetValue (rRef).
- Let lRef be ?
Evaluation ofLogicalORExpression . - Let lVal be ?
GetValue (lRef). - If
ToBoolean (lVal) istrue , return lVal. - Let rRef be ?
Evaluation ofLogicalANDExpression . - Return ?
GetValue (rRef).
- Let lRef be ?
Evaluation ofCoalesceExpressionHead . - Let lVal be ?
GetValue (lRef). - If lVal is neither
undefined nornull , return lVal. - Let rRef be ?
Evaluation ofBitwiseORExpression . - Return ?
GetValue (rRef).
13.14 Conditional Operator ( ? : )
Syntax
The grammar for a
13.14.1 Runtime Semantics: Evaluation
- Let lRef be ?
Evaluation ofShortCircuitExpression . - Let lVal be
ToBoolean (?GetValue (lRef)). - If lVal is
true , then- Let trueRef be ?
Evaluation of the firstAssignmentExpression . - Return ?
GetValue (trueRef).
- Let trueRef be ?
- Let falseRef be ?
Evaluation of the secondAssignmentExpression . - Return ?
GetValue (falseRef).
13.15 Assignment Operators
Syntax
13.15.1 Static Semantics: Early Errors
-
If
LeftHandSideExpression is either anObjectLiteral or anArrayLiteral ,LeftHandSideExpression must cover anAssignmentPattern . -
If
LeftHandSideExpression is neither anObjectLiteral nor anArrayLiteral , it is a Syntax Error if theAssignmentTargetType ofLeftHandSideExpression isinvalid .
-
It is a Syntax Error if the
AssignmentTargetType ofLeftHandSideExpression isinvalid .
-
It is a Syntax Error if the
AssignmentTargetType ofLeftHandSideExpression is notsimple .
13.15.2 Runtime Semantics: Evaluation
- If
LeftHandSideExpression is neither anObjectLiteral nor anArrayLiteral , then- Let lRef be ?
Evaluation ofLeftHandSideExpression . - If the
AssignmentTargetType ofLeftHandSideExpression isweb-compat , throw aReferenceError exception. - If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue andIsIdentifierRef ofLeftHandSideExpression istrue , then- Let lhs be the
StringValue ofLeftHandSideExpression . - Let rVal be ?
NamedEvaluation ofAssignmentExpression with argument lhs.
- Let lhs be the
- Else,
- Let rRef be ?
Evaluation ofAssignmentExpression . - Let rVal be ?
GetValue (rRef).
- Let rRef be ?
- Perform ?
PutValue (lRef, rVal). - Return rVal.
- Let lRef be ?
- Let assignmentPattern be the
AssignmentPattern that iscovered byLeftHandSideExpression . - Let rRef be ?
Evaluation ofAssignmentExpression . - Let rVal be ?
GetValue (rRef). - Perform ?
DestructuringAssignmentEvaluation of assignmentPattern with argument rVal. - Return rVal.
- Let lRef be ?
Evaluation ofLeftHandSideExpression . - If the
AssignmentTargetType ofLeftHandSideExpression isweb-compat , throw aReferenceError exception. - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation ofAssignmentExpression . - Let rVal be ?
GetValue (rRef). - Let assignmentOpText be the
source text matched by AssignmentOperator . - Let opText be the sequence of Unicode code points associated with assignmentOpText in the following table:
assignmentOpText opText **=***=*/=/%=%+=+-=-<<=<<>>=>>>>>=>>>&=&^=^|=| - Let r be ?
ApplyStringOrNumericBinaryOperator (lVal, opText, rVal). - Perform ?
PutValue (lRef, r). - Return r.
- Let lRef be ?
Evaluation ofLeftHandSideExpression . - Let lVal be ?
GetValue (lRef). - If
ToBoolean (lVal) isfalse , return lVal. - If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue andIsIdentifierRef ofLeftHandSideExpression istrue , then- Let lhs be the
StringValue ofLeftHandSideExpression . - Let rVal be ?
NamedEvaluation ofAssignmentExpression with argument lhs.
- Let lhs be the
- Else,
- Let rRef be ?
Evaluation ofAssignmentExpression . - Let rVal be ?
GetValue (rRef).
- Let rRef be ?
- Perform ?
PutValue (lRef, rVal). - Return rVal.
- Let lRef be ?
Evaluation ofLeftHandSideExpression . - Let lVal be ?
GetValue (lRef). - If
ToBoolean (lVal) istrue , return lVal. - If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue andIsIdentifierRef ofLeftHandSideExpression istrue , then- Let lhs be the
StringValue ofLeftHandSideExpression . - Let rVal be ?
NamedEvaluation ofAssignmentExpression with argument lhs.
- Let lhs be the
- Else,
- Let rRef be ?
Evaluation ofAssignmentExpression . - Let rVal be ?
GetValue (rRef).
- Let rRef be ?
- Perform ?
PutValue (lRef, rVal). - Return rVal.
- Let lRef be ?
Evaluation ofLeftHandSideExpression . - Let lVal be ?
GetValue (lRef). - If lVal is neither
undefined nornull , return lVal. - If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue andIsIdentifierRef ofLeftHandSideExpression istrue , then- Let lhs be the
StringValue ofLeftHandSideExpression . - Let rVal be ?
NamedEvaluation ofAssignmentExpression with argument lhs.
- Let lhs be the
- Else,
- Let rRef be ?
Evaluation ofAssignmentExpression . - Let rVal be ?
GetValue (rRef).
- Let rRef be ?
- Perform ?
PutValue (lRef, rVal). - Return rVal.
When this expression occurs within
13.15.3 ApplyStringOrNumericBinaryOperator ( lVal, opText, rVal )
The abstract operation ApplyStringOrNumericBinaryOperator takes arguments lVal (an **, *, /, %, +, -, <<, >>, >>>, &, ^, or |), and rVal (an
- If opText is
+, then- Let lPrim be ?
ToPrimitive (lVal). - Let rPrim be ?
ToPrimitive (rVal). - If lPrim
is a String or rPrimis a String , then- Let lStr be ?
ToString (lPrim). - Let rStr be ?
ToString (rPrim). - Return the
string-concatenation of lStr and rStr.
- Let lStr be ?
- Set lVal to lPrim.
- Set rVal to rPrim.
- Let lPrim be ?
- NOTE: At this point, it must be a numeric operation.
- Let lNum be ?
ToNumeric (lVal). - Let rNum be ?
ToNumeric (rVal). - If
SameType (lNum, rNum) isfalse , throw aTypeError exception. - If lNum
is a BigInt , then- If opText is
**, return ?BigInt::exponentiate (lNum, rNum). - If opText is
/, return ?BigInt::divide (lNum, rNum). - If opText is
%, return ?BigInt::remainder (lNum, rNum). - If opText is
>>>, return ?BigInt::unsignedRightShift (lNum, rNum). - Let operation be the abstract operation associated with opText in the following table:
opText operation *BigInt::multiply +BigInt::add -BigInt::subtract <<BigInt::leftShift >>BigInt::signedRightShift &BigInt::bitwiseAND ^BigInt::bitwiseXOR |BigInt::bitwiseOR
- If opText is
- Else,
Assert : lNumis a Number .- Let operation be the abstract operation associated with opText in the following table:
opText operation **Number::exponentiate *Number::multiply /Number::divide %Number::remainder +Number::add -Number::subtract <<Number::leftShift >>Number::signedRightShift >>>Number::unsignedRightShift &Number::bitwiseAND ^Number::bitwiseXOR |Number::bitwiseOR
- Return operation(lNum, rNum).
No hint is provided in the calls to
Step
13.15.4 EvaluateStringOrNumericBinaryExpression ( leftOperand, opText, rightOperand )
The abstract operation EvaluateStringOrNumericBinaryExpression takes arguments leftOperand (a
- Let lRef be ?
Evaluation of leftOperand. - Let lVal be ?
GetValue (lRef). - Let rRef be ?
Evaluation of rightOperand. - Let rVal be ?
GetValue (rRef). - Return ?
ApplyStringOrNumericBinaryOperator (lVal, opText, rVal).
13.15.5 Destructuring Assignment
Supplemental Syntax
In certain circumstances when processing an instance of the production
the interpretation of
13.15.5.1 Static Semantics: Early Errors
-
It is a Syntax Error if the
AssignmentTargetType ofIdentifierReference is notsimple .
-
It is a Syntax Error if
DestructuringAssignmentTarget is either anArrayLiteral or anObjectLiteral .
-
If
LeftHandSideExpression is either anObjectLiteral or anArrayLiteral ,LeftHandSideExpression must cover anAssignmentPattern . -
If
LeftHandSideExpression is neither anObjectLiteral nor anArrayLiteral , it is a Syntax Error if theAssignmentTargetType ofLeftHandSideExpression is notsimple .
13.15.5.2 Runtime Semantics: DestructuringAssignmentEvaluation
The
- Perform ?
RequireObjectCoercible (value). - Return
unused .
- Perform ?
RequireObjectCoercible (value). - Perform ?
PropertyDestructuringAssignmentEvaluation ofAssignmentPropertyList with argument value. - Return
unused .
- Perform ?
RequireObjectCoercible (value). - Let excludedNames be a new empty
List . - Return ?
RestDestructuringAssignmentEvaluation ofAssignmentRestProperty with arguments value and excludedNames.
- Perform ?
RequireObjectCoercible (value). - Let excludedNames be ?
PropertyDestructuringAssignmentEvaluation ofAssignmentPropertyList with argument value. - Return ?
RestDestructuringAssignmentEvaluation ofAssignmentRestProperty with arguments value and excludedNames.
- Let iteratorRecord be ?
GetIterator (value,sync ). - Return ?
IteratorClose (iteratorRecord,NormalCompletion (unused )).
- Let iteratorRecord be ?
GetIterator (value,sync ). - Let result be
Completion (IteratorDestructuringAssignmentEvaluation ofElision with argument iteratorRecord). - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, result). - Return result.
- Let iteratorRecord be ?
GetIterator (value,sync ). - If
Elision is present, then- Let status be
Completion (IteratorDestructuringAssignmentEvaluation ofElision with argument iteratorRecord). - If status is an
abrupt completion , thenAssert : iteratorRecord.[[Done]] istrue .- Return ? status.
- Let status be
- Let result be
Completion (IteratorDestructuringAssignmentEvaluation ofAssignmentRestElement with argument iteratorRecord). - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, result). - Return result.
- Let iteratorRecord be ?
GetIterator (value,sync ). - Let result be
Completion (IteratorDestructuringAssignmentEvaluation ofAssignmentElementList with argument iteratorRecord). - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, result). - Return result.
- Let iteratorRecord be ?
GetIterator (value,sync ). - Let status be
Completion (IteratorDestructuringAssignmentEvaluation ofAssignmentElementList with argument iteratorRecord). - If status is an
abrupt completion , then- If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, status). - Return ? status.
- If iteratorRecord.[[Done]] is
- If
Elision is present, then- Set status to
Completion (IteratorDestructuringAssignmentEvaluation ofElision with argument iteratorRecord). - If status is an
abrupt completion , thenAssert : iteratorRecord.[[Done]] istrue .- Return ? status.
- Set status to
- If
AssignmentRestElement is present, then- Set status to
Completion (IteratorDestructuringAssignmentEvaluation ofAssignmentRestElement with argument iteratorRecord).
- Set status to
- If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iteratorRecord, status). - Return ? status.
13.15.5.3 Runtime Semantics: PropertyDestructuringAssignmentEvaluation
The
- Let propertyNames be ? PropertyDestructuringAssignmentEvaluation of
AssignmentPropertyList with argument value. - Let nextNames be ? PropertyDestructuringAssignmentEvaluation of
AssignmentProperty with argument value. - Return the
list-concatenation of propertyNames and nextNames.
- Let P be the
StringValue ofIdentifierReference . - Let lRef be ?
ResolveBinding (P). - Let v be ?
GetV (value, P). - If
Initializer is present and v isundefined , then- If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Set v to ?
NamedEvaluation ofInitializer with argument P.
- Set v to ?
- Else,
- Let defaultValue be ?
Evaluation ofInitializer . - Set v to ?
GetValue (defaultValue).
- Let defaultValue be ?
- If
- Perform ?
PutValue (lRef, v). - Return « P ».
- Let name be ?
Evaluation ofPropertyName . - Perform ?
KeyedDestructuringAssignmentEvaluation ofAssignmentElement with arguments value and name. - Return « name ».
13.15.5.4 Runtime Semantics: RestDestructuringAssignmentEvaluation
The
- Let lRef be ?
Evaluation ofDestructuringAssignmentTarget . - Let restObj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform ?
CopyDataProperties (restObj, value, excludedNames). - Return ?
PutValue (lRef, restObj).
13.15.5.5 Runtime Semantics: IteratorDestructuringAssignmentEvaluation
The
- Return ? IteratorDestructuringAssignmentEvaluation of
AssignmentElisionElement with argument iteratorRecord.
- Perform ? IteratorDestructuringAssignmentEvaluation of
AssignmentElementList with argument iteratorRecord. - Return ? IteratorDestructuringAssignmentEvaluation of
AssignmentElisionElement with argument iteratorRecord.
- Return ? IteratorDestructuringAssignmentEvaluation of
AssignmentElement with argument iteratorRecord.
- Perform ? IteratorDestructuringAssignmentEvaluation of
Elision with argument iteratorRecord. - Return ? IteratorDestructuringAssignmentEvaluation of
AssignmentElement with argument iteratorRecord.
- If iteratorRecord.[[Done]] is
false , then- Perform ?
IteratorStep (iteratorRecord).
- Perform ?
- Return
unused .
- Perform ? IteratorDestructuringAssignmentEvaluation of
Elision with argument iteratorRecord. - If iteratorRecord.[[Done]] is
false , then- Perform ?
IteratorStep (iteratorRecord).
- Perform ?
- Return
unused .
- If
DestructuringAssignmentTarget is neither anObjectLiteral nor anArrayLiteral , then- Let lRef be ?
Evaluation ofDestructuringAssignmentTarget .
- Let lRef be ?
- Let value be
undefined . - If iteratorRecord.[[Done]] is
false , then- Let next be ?
IteratorStepValue (iteratorRecord). - If next is not
done , then- Set value to next.
- Let next be ?
- If
Initializer is present and value isundefined , then- If
IsAnonymousFunctionDefinition (Initializer ) istrue andIsIdentifierRef ofDestructuringAssignmentTarget istrue , then- Let target be the
StringValue ofDestructuringAssignmentTarget . - Let v be ?
NamedEvaluation ofInitializer with argument target.
- Let target be the
- Else,
- Let defaultValue be ?
Evaluation ofInitializer . - Let v be ?
GetValue (defaultValue).
- Let defaultValue be ?
- If
- Else,
- Let v be value.
- If
DestructuringAssignmentTarget is either anObjectLiteral or anArrayLiteral , then- Let nestedAssignmentPattern be the
AssignmentPattern that iscovered byDestructuringAssignmentTarget . - Return ?
DestructuringAssignmentEvaluation of nestedAssignmentPattern with argument v.
- 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 ?
Evaluation ofDestructuringAssignmentTarget .
- Let lRef be ?
- Let A be !
ArrayCreate (0). - Let n be 0.
- Repeat, while iteratorRecord.[[Done]] is
false ,- Let next be ?
IteratorStepValue (iteratorRecord). - If next is not
done , then- Perform !
CreateDataPropertyOrThrow (A, !ToString (𝔽 (n)), next). - Set n to n + 1.
- Perform !
- 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 ?
DestructuringAssignmentEvaluation of nestedAssignmentPattern with argument A.
13.15.5.6 Runtime Semantics: KeyedDestructuringAssignmentEvaluation
The
- If
DestructuringAssignmentTarget is neither anObjectLiteral nor anArrayLiteral , then- Let lRef be ?
Evaluation ofDestructuringAssignmentTarget .
- Let lRef be ?
- Let v be ?
GetV (value, propertyName). - If
Initializer is present and v isundefined , then- If
IsAnonymousFunctionDefinition (Initializer ) istrue andIsIdentifierRef ofDestructuringAssignmentTarget istrue , then- Let target be the
StringValue ofDestructuringAssignmentTarget . - Let rhsValue be ?
NamedEvaluation ofInitializer with argument target.
- Let target be the
- Else,
- Let defaultValue be ?
Evaluation ofInitializer . - Let rhsValue be ?
GetValue (defaultValue).
- Let defaultValue be ?
- If
- Else,
- Let rhsValue be v.
- If
DestructuringAssignmentTarget is either anObjectLiteral or anArrayLiteral , then- Let assignmentPattern be the
AssignmentPattern that iscovered byDestructuringAssignmentTarget . - Return ?
DestructuringAssignmentEvaluation of assignmentPattern with argument rhsValue.
- Let assignmentPattern be the
- Return ?
PutValue (lRef, rhsValue).
13.16 Comma Operator ( , )
Syntax
13.16.1 Runtime Semantics: Evaluation
- Let lRef be ?
Evaluation ofExpression . - Perform ?
GetValue (lRef). - Let rRef be ?
Evaluation ofAssignmentExpression . - Return ?
GetValue (rRef).