12 ECMAScript Language: Expressions
12.1 Identifiers
Syntax
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 this production has a [Yield] parameter and StringValue of
Identifier is"yield".
-
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 StringValue of
IdentifierName is the same String value as the StringValue of anyReservedWord except foryield.
StringValue of
12.1.2 Static Semantics: BoundNames
12.1.3 Static Semantics: IsValidSimpleAssignmentTarget
- If this
IdentifierReference is contained instrict mode code and StringValue ofIdentifier is"eval"or"arguments", returnfalse . - Return
true .
- Return
true .
12.1.4 Static Semantics: StringValue
- Return
"yield".
- Return the StringValue of
IdentifierName .
12.1.5 Runtime Semantics: BindingInitialization
With arguments 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).
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").
In non-strict code, the keyword yield may be used as an identifier. Evaluating the yield as if it was an yield in binding creation contexts.
12.2 Primary Expression
Syntax
Supplemental Syntax
When processing the production
the interpretation of
12.2.1 Semantics
12.2.1.1 Static Semantics: CoveredParenthesizedExpression
- Return the result of parsing the lexical token stream matched by
CoverParenthesizedExpressionAndArrowParameterList using either[Yield] ParenthesizedExpression orParenthesizedExpression as the goal symbol depending upon whether the [Yield] grammar parameter was present when[Yield] CoverParenthesizedExpressionAndArrowParameterList was matched.
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: IsValidSimpleAssignmentTarget
- Return
false .
- Let expr be CoveredParenthesizedExpression of
CoverParenthesizedExpressionAndArrowParameterList . - Return IsValidSimpleAssignmentTarget 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
Syntax
12.2.4.1 Runtime Semantics: Evaluation
- Return
null .
- Return
false ifBooleanLiteral is the tokenfalse. - Return
true ifBooleanLiteral is the tokentrue.
- Return the number whose value is MV of
NumericLiteral as defined in11.8.3 .
- Return the StringValue of
StringLiteral as defined in11.8.4.2 .
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 Static Semantics: ElisionWidth
- Return the numeric value 1.
- Let preceding be the ElisionWidth of
Elision . - Return preceding+1.
12.2.5.2 Runtime Semantics: ArrayAccumulation
With parameters array and nextIndex.
- Let padding be the ElisionWidth of
Elision ; ifElision is not present, use the numeric value zero. - Let initResult be the result of evaluating
AssignmentExpression . - Let initValue be ?
GetValue (initResult). - Let created be
CreateDataProperty (array,ToString (ToUint32 (nextIndex+padding)), initValue). - Assert: created is
true . - Return nextIndex+padding+1.
- Let padding be the ElisionWidth of
Elision ; ifElision is not present, use the numeric value zero. - Return the result of performing ArrayAccumulation for
SpreadElement with arguments array and nextIndex+padding.
- Let postIndex be the result of performing ArrayAccumulation for
ElementList with arguments array and nextIndex. ReturnIfAbrupt (postIndex).- Let padding be the ElisionWidth of
Elision ; ifElision is not present, use the numeric value zero. - Let initResult be the result of evaluating
AssignmentExpression . - Let initValue be ?
GetValue (initResult). - Let created be
CreateDataProperty (array,ToString (ToUint32 (postIndex+padding)), initValue). - Assert: created is
true . - Return postIndex+padding+1.
- Let postIndex be the result of performing ArrayAccumulation for
ElementList with arguments array and nextIndex. ReturnIfAbrupt (postIndex).- Let padding be the ElisionWidth of
Elision ; ifElision is not present, use the numeric value zero. - Return the result of performing ArrayAccumulation for
SpreadElement with arguments array and postIndex+padding.
- Let spreadRef be the result of evaluating
AssignmentExpression . - Let spreadObj be ?
GetValue (spreadRef). - Let iterator be ?
GetIterator (spreadObj). - Repeat
- Let next be ?
IteratorStep (iterator). - If next is
false , return nextIndex. - Let nextValue be ?
IteratorValue (next). - Let status be
CreateDataProperty (array,ToString (ToUint32 (nextIndex)), nextValue). - Assert: status is
true . - Let nextIndex be nextIndex + 1.
- Let next be ?
12.2.5.3 Runtime Semantics: Evaluation
- Let array be
ArrayCreate (0). - Let pad be the ElisionWidth of
Elision ; ifElision is not present, use the numeric value zero. - Perform
Set (array,"length",ToUint32 (pad),false ). - NOTE: The above Set cannot fail because of the nature of the object returned by
ArrayCreate . - Return array.
- Let array be
ArrayCreate (0). - Let len be the result of performing ArrayAccumulation for
ElementList with arguments array and 0. ReturnIfAbrupt (len).- Perform
Set (array,"length",ToUint32 (len),false ). - NOTE: The above Set cannot fail because of the nature of the object returned by
ArrayCreate . - Return array.
- Let array be
ArrayCreate (0). - Let len be the result of performing ArrayAccumulation for
ElementList with arguments array and 0. ReturnIfAbrupt (len).- Let padding be the ElisionWidth of
Elision ; ifElision is not present, use the numeric value zero. - Perform
Set (array,"length",ToUint32 (padding+len),false ). - NOTE: The above Set cannot fail because of the nature of the object returned by
ArrayCreate . - 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: HasComputedPropertyKey
- If HasComputedPropertyKey of
PropertyDefinitionList istrue , returntrue . - Return HasComputedPropertyKey of
PropertyDefinition .
- Return
false .
- Return IsComputedPropertyKey of
PropertyName .
12.2.6.5 Static Semantics: IsComputedPropertyKey
- Return
false .
- Return
true .
12.2.6.6 Static Semantics: PropName
- Return StringValue of
IdentifierReference .
- Return PropName of
PropertyName .
- Return StringValue of
IdentifierName .
- Return a String value whose code units are the SV of the
StringLiteral .
- Let nbr be the result of forming the value of the
NumericLiteral . - Return !
ToString (nbr).
- Return
empty .
12.2.6.7 Static Semantics: PropertyNameList
- 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.8 Runtime Semantics: Evaluation
- Return
ObjectCreate (%ObjectPrototype% ).
- Let obj be
ObjectCreate (%ObjectPrototype% ). - Let status be the result of performing PropertyDefinitionEvaluation of
PropertyDefinitionList with arguments obj andtrue . ReturnIfAbrupt (status).- Return obj.
- Return StringValue of
IdentifierName .
- Return a String value whose code units are the SV of the
StringLiteral .
- Let nbr be the result of forming the value of the
NumericLiteral . - Return !
ToString (nbr).
- Let exprValue be the result of evaluating
AssignmentExpression . - Let propName be ?
GetValue (exprValue). - Return ?
ToPropertyKey (propName).
12.2.6.9 Runtime Semantics: PropertyDefinitionEvaluation
With parameters object and enumerable.
- Let status be the result of performing PropertyDefinitionEvaluation of
PropertyDefinitionList with arguments object and enumerable. ReturnIfAbrupt (status).- Return the result of performing PropertyDefinitionEvaluation of
PropertyDefinition with arguments object and enumerable.
- Let propName be StringValue of
IdentifierReference . - Let exprValue be the result of evaluating
IdentifierReference . - Let propValue be ?
GetValue (exprValue). - Assert: enumerable is
true . - Return
CreateDataPropertyOrThrow (object, propName, propValue).
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- Let exprValueRef be the result of evaluating
AssignmentExpression . - Let propValue be ?
GetValue (exprValueRef). - If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue , then- Let hasNameProperty be ?
HasOwnProperty (propValue,"name"). - If hasNameProperty is
false , performSetFunctionName (propValue, propKey).
- Let hasNameProperty be ?
- Assert: enumerable is
true . - Return
CreateDataPropertyOrThrow (object, propKey, propValue).
An alternative semantics for this production is given in
12.2.7 Function Defining Expressions
12.2.8 Regular Expression Literals
Syntax
See
12.2.8.1 Static Semantics: Early Errors
-
It is a Syntax Error if BodyText of
RegularExpressionLiteral cannot be recognized using the goal symbolPattern of the ECMAScript RegExp grammar specified in21.2.1 . -
It is a Syntax Error if FlagText of
RegularExpressionLiteral contains any code points other than"g","i","m","u", or"y", or if it contains the same code point more than once.
12.2.8.2 Runtime Semantics: Evaluation
- Let pattern be the String value consisting of the
UTF16Encoding of each code point of BodyText ofRegularExpressionLiteral . - Let flags be the String value consisting of the
UTF16Encoding of each code point of FlagText ofRegularExpressionLiteral . - Return
RegExpCreate (pattern, flags).
12.2.9 Template Literals
Syntax
12.2.9.1 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.2 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 firstSub be the result of evaluating
Expression . ReturnIfAbrupt (firstSub).- Let restSub be SubstitutionEvaluation of
TemplateSpans . ReturnIfAbrupt (restSub).- Assert: restSub is a
List . - 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.3 Runtime Semantics: GetTemplateObject ( templateLiteral )
The abstract operation GetTemplateObject is called with a grammar production, templateLiteral, as an argument. It performs the following steps:
- 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.[[Strings]] and rawStrings contain the same values in the same order, then
- Return e.[[Array]].
- If e.[[Strings]] and rawStrings contain the same values in the same order, then
- Let cookedStrings be TemplateStrings of templateLiteral with argument
false . - Let count be the number of elements in the
List cookedStrings. - 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 }). - Let index be 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 {[[Strings]]: rawStrings, [[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.4 Runtime Semantics: SubstitutionEvaluation
- Return a new empty
List .
- Return the result of SubstitutionEvaluation of
TemplateMiddleList .
- Let sub be the result of evaluating
Expression . ReturnIfAbrupt (sub).- Return a
List containing only sub.
- Let preceding be the result of SubstitutionEvaluation of
TemplateMiddleList . ReturnIfAbrupt (preceding).- Let next be the result of evaluating
Expression . ReturnIfAbrupt (next).- Append next as the last element of the
List preceding. - Return preceding.
12.2.9.5 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 sub be the result of evaluating
Expression . ReturnIfAbrupt (sub).- Let middle be ?
ToString (sub). - Let tail be the result of evaluating
TemplateSpans . ReturnIfAbrupt (tail).- Return the String value whose code units are the elements of head followed by the elements of middle followed by the elements of 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 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 whose code units are the elements of head followed by the elements of tail.
- Let head be the TV of
TemplateMiddle as defined in11.8.6 . - Let sub be the result of evaluating
Expression . ReturnIfAbrupt (sub).- 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 sub be the result of evaluating
Expression . ReturnIfAbrupt (sub).- 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 the lexical token sequence matched by
CoverParenthesizedExpressionAndArrowParameterList cannot be parsed with no tokens left over usingParenthesizedExpression as the goal symbol. -
All Early Errors rules for
ParenthesizedExpression and its derived productions also apply to CoveredParenthesizedExpression ofCoverParenthesizedExpressionAndArrowParameterList .
12.2.10.2 Static Semantics: IsFunctionDefinition
- Return IsFunctionDefinition of
Expression .
12.2.10.3 Static Semantics: IsValidSimpleAssignmentTarget
- Return IsValidSimpleAssignmentTarget of
Expression .
12.2.10.4 Runtime Semantics: Evaluation
- Let expr be CoveredParenthesizedExpression of
CoverParenthesizedExpressionAndArrowParameterList . - Return the result of evaluating expr.
This algorithm does not apply delete and typeof may be applied to parenthesized expressions.
12.3 Left-Hand-Side Expressions
Syntax
12.3.1 Static Semantics
12.3.1.1 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 .
12.3.1.2 Static Semantics: IsFunctionDefinition
- Return
false .
12.3.1.3 Static Semantics: IsDestructuring
- If
PrimaryExpression is either anObjectLiteral or anArrayLiteral , returntrue . - Return
false .
- Return
false .
12.3.1.4 Static Semantics: IsIdentifierRef
- Return
false .
12.3.1.5 Static Semantics: IsValidSimpleAssignmentTarget
- Return
true .
- Return
false .
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
[ <identifier-name-string> ]
and similarly
. is identical in its behaviour to
[ <identifier-name-string> ]
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). - Let propertyNameReference be the result of evaluating
Expression . - Let propertyNameValue be ?
GetValue (propertyNameReference). - Let bv be ?
RequireObjectCoercible (baseValue). - Let propertyKey be ?
ToPropertyKey (propertyNameValue). - If the code matched by the syntactic production that is being evaluated is
strict mode code , let strict betrue , else let strict befalse . - Return a value of
type Reference whose base value is bv, whose referenced name is propertyKey, and whose strict reference flag is strict.
- Let baseReference be the result of evaluating
MemberExpression . - Let baseValue be ?
GetValue (baseReference). - Let bv be ?
RequireObjectCoercible (baseValue). - Let propertyNameString be StringValue of
IdentifierName . - If the code matched by the syntactic production that is being evaluated is
strict mode code , let strict betrue , else let strict befalse . - Return a value of
type Reference whose base value is bv, whose referenced name is propertyNameString, and whose strict reference flag is strict.
Is evaluated in exactly the same manner as
Is evaluated in exactly the same manner as
12.3.3 The new Operator
12.3.3.1 Runtime Semantics: Evaluation
- Return ?
EvaluateNew (NewExpression ,empty ).
- Return ?
EvaluateNew (MemberExpression ,Arguments ).
12.3.3.1.1 Runtime Semantics: EvaluateNew(constructProduction, arguments)
The abstract operation EvaluateNew with arguments constructProduction, and arguments performs the following steps:
- Assert: constructProduction is either a
NewExpression or aMemberExpression . - Assert: arguments is either
empty or anArguments production. - Let ref be the result of evaluating constructProduction.
- Let constructor be ?
GetValue (ref). - If arguments is
empty , let argList be a new emptyList . - Else,
- Let argList be ArgumentListEvaluation of arguments.
ReturnIfAbrupt (argList).
- If
IsConstructor (constructor) isfalse , throw aTypeError exception. - Return ?
Construct (constructor, argList).
12.3.4 Function Calls
12.3.4.1 Runtime Semantics: Evaluation
- Let ref be the result of evaluating
MemberExpression . - Let func be ?
GetValue (ref). - If
Type (ref) isReference and IsPropertyReference(ref) isfalse and GetReferencedName(ref) is"eval", then- If
SameValue (func,%eval% ) istrue , then- Let argList be ? ArgumentListEvaluation(
Arguments ). - If argList has no elements, return
undefined . - Let evalText be the first element of argList.
- If the source code matching this
CallExpression is strict code, let strictCaller betrue . Otherwise let strictCaller befalse . - Let evalRealm be
the current Realm Record . - Return ?
PerformEval (evalText, evalRealm, strictCaller,true ).
- Let argList be ? ArgumentListEvaluation(
- If
- If
Type (ref) isReference , then- If IsPropertyReference(ref) is
true , then- Let thisValue be
GetThisValue (ref).
- Let thisValue be
- Else, the base of ref is an
Environment Record - Let refEnv be GetBase(ref).
- Let thisValue be refEnv.WithBaseObject().
- If IsPropertyReference(ref) is
- Else
Type (ref) is notReference ,- Let thisValue be
undefined .
- Let thisValue be
- Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateDirectCall (func, thisValue,Arguments , tailCall).
A
- Let ref be the result of evaluating
CallExpression . - Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (ref,Arguments , tailCall).
12.3.4.2 Runtime Semantics: EvaluateCall( ref, arguments, tailPosition )
The abstract operation EvaluateCall takes as arguments a value ref, a syntactic grammar production arguments, and a Boolean argument tailPosition. It performs the following steps:
- Let func be ?
GetValue (ref). - If
Type (ref) isReference , then- If IsPropertyReference(ref) is
true , then- Let thisValue be
GetThisValue (ref).
- Let thisValue be
- Else, the base of ref is an
Environment Record - Let refEnv be GetBase(ref).
- Let thisValue be refEnv.WithBaseObject().
- If IsPropertyReference(ref) is
- Else
Type (ref) is notReference ,- Let thisValue be
undefined .
- Let thisValue be
- Return ?
EvaluateDirectCall (func, thisValue, arguments, tailPosition).
12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
The abstract operation EvaluateDirectCall takes as arguments a value func, a value thisValue, a syntactic grammar production arguments, and a Boolean argument tailPosition. It performs the following steps:
- Let argList be ? ArgumentListEvaluation(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 is
true , 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 an
abrupt completion , thenType (result) is anECMAScript language type . - Return result.
12.3.5 The super Keyword
12.3.5.1 Runtime Semantics: Evaluation
- Let propertyNameReference be the result of evaluating
Expression . - Let propertyNameValue be
GetValue (propertyNameReference). - Let propertyKey be ?
ToPropertyKey (propertyNameValue). - If the code matched by the syntactic production that is being evaluated is
strict mode code , let strict betrue , else let strict befalse . - Return ?
MakeSuperPropertyReference (propertyKey, strict).
- Let propertyKey be StringValue of
IdentifierName . - If the code matched by the syntactic production that is being evaluated is
strict mode code , let strict betrue , else let strict befalse . - Return ?
MakeSuperPropertyReference (propertyKey, strict).
- Let newTarget be
GetNewTarget (). - If newTarget is
undefined , throw aReferenceError exception. - Let func be ?
GetSuperConstructor (). - Let argList be ArgumentListEvaluation of
Arguments . ReturnIfAbrupt (argList).- Let result be ?
Construct (func, argList, newTarget). - Let thisER be
GetThisEnvironment ( ). - Return ? thisER.BindThisValue(result).
12.3.5.2 Runtime Semantics: GetSuperConstructor ( )
The abstract operation GetSuperConstructor performs the following steps:
- Let envRec be
GetThisEnvironment ( ). - Assert: envRec is a function
Environment Record . - Let activeFunction be envRec.[[FunctionObject]].
- Let superConstructor be ? activeFunction.[[GetPrototypeOf]]().
- If
IsConstructor (superConstructor) isfalse , throw aTypeError exception. - Return superConstructor.
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference(propertyKey, strict)
The abstract operation MakeSuperPropertyReference with arguments propertyKey and strict performs the following steps:
- Let env be
GetThisEnvironment ( ). - If env.HasSuperBinding() is
false , throw aReferenceError exception. - Let actualThis be ? env.GetThisBinding().
- Let baseValue be ? env.GetSuperBase().
- Let bv be ?
RequireObjectCoercible (baseValue). - Return a value of
type Reference that is a SuperReference whose base value is bv, whose referenced name is propertyKey, whose thisValue is actualThis, and whose strict reference flag is strict.
12.3.6 Argument Lists
The evaluation of an argument list produces a
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
- Return a new empty
List .
- Let list be a new empty
List . - Let spreadRef be the result of evaluating
AssignmentExpression . - Let spreadObj be ?
GetValue (spreadRef). - Let iterator be ?
GetIterator (spreadObj). - Repeat
- Let next be ?
IteratorStep (iterator). - 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 the result of evaluating
ArgumentList . ReturnIfAbrupt (precedingArgs).- 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 the result of evaluating
ArgumentList . - Let spreadRef be the result of evaluating
AssignmentExpression . - Let iterator be ?
GetIterator (?GetValue (spreadRef)). - Repeat
- Let next be ?
IteratorStep (iterator). - If next is
false , return precedingArgs. - Let nextArg be ?
IteratorValue (next). - Append nextArg as the last element of precedingArgs.
- Let next be ?
12.3.7 Tagged Templates
12.3.7.1 Runtime Semantics: Evaluation
- Let tagRef be the result of evaluating
MemberExpression . - Let thisCall be this
MemberExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (tagRef,TemplateLiteral , tailCall).
- Let tagRef be the result of evaluating
CallExpression . - Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (tagRef,TemplateLiteral , tailCall).
12.3.8 Meta Properties
12.3.8.1 Runtime Semantics: Evaluation
- Return
GetNewTarget ().
12.4 Update Expressions
Syntax
12.4.1 Static Semantics: Early Errors
-
It is an early
Reference Error if IsValidSimpleAssignmentTarget ofLeftHandSideExpression isfalse .
-
It is an early
Reference Error if IsValidSimpleAssignmentTarget ofUnaryExpression isfalse .
12.4.2 Static Semantics: IsFunctionDefinition
- Return
false .
12.4.3 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
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: IsValidSimpleAssignmentTarget
- Return
false .
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) is
true , then- Assert: IsStrictReference(ref) is
false . - Return
true .
- Assert: IsStrictReference(ref) is
- If IsPropertyReference(ref) is
true , then- If IsSuperReference(ref) is
true , throw aReferenceError exception. - Let baseObj be !
ToObject (GetBase(ref)). - Let deleteStatus be ? baseObj.[[Delete]](GetReferencedName(ref)).
- If deleteStatus is
false and IsStrictReference(ref) istrue , throw aTypeError exception. - Return deleteStatus.
- If IsSuperReference(ref) is
- Else ref is a
Reference 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
12.5.5 The typeof Operator
12.5.5.1 Runtime Semantics: Evaluation
|
|
Result |
|---|---|
| Undefined |
"undefined"
|
| Null |
"object"
|
| Boolean |
"boolean"
|
| Number |
"number"
|
| String |
"string"
|
| Symbol |
"symbol"
|
| Object (ordinary and does not implement [[Call]]) |
"object"
|
| Object (standard exotic and does not implement [[Call]]) |
"object"
|
| Object (implements [[Call]]) |
"function"
|
| Object (non-standard exotic and does not implement [[Call]]) |
Implementation-defined. Must not be "undefined", "boolean", "function", "number", "symbol", or "string".
|
Implementations are discouraged from defining new typeof result values for non-standard exotic objects. If possible "object" should be used for such objects.
12.5.6 Unary + Operator
The unary + operator converts its operand to Number
12.5.6.1 Runtime Semantics: Evaluation
12.5.7 Unary - Operator
The unary - operator converts its operand to Number
12.5.7.1 Runtime Semantics: Evaluation
12.5.8 Bitwise NOT Operator ( ~ )
12.5.8.1 Runtime Semantics: Evaluation
12.5.9 Logical NOT Operator ( ! )
12.5.9.1 Runtime Semantics: Evaluation
12.6 Exponentiation Operator
Syntax
12.6.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.6.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
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 ?
ToNumber (leftValue). - Let exponent be ?
ToNumber (rightValue). - Return the result of
Applying the ** operator with base and exponent as specified in12.7.3.4 .
12.7 Multiplicative Operators
Syntax
12.7.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.7.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
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 ?
ToNumber (leftValue). - Let rnum be ?
ToNumber (rightValue). - Return the result of applying the
MultiplicativeOperator (*,/, or%) to lnum and rnum as specified in12.7.3.1 ,12.7.3.2 , or12.7.3.3 .
12.7.3.1 Applying the * Operator
The *
The result of a floating-point multiplication is governed by the rules of IEEE 754-2008 binary double-precision arithmetic:
-
If either operand is
NaN , the result isNaN . - The sign of the result is positive if both operands have the same sign, negative if the operands have different signs.
-
Multiplication of an infinity by a zero results in
NaN . - Multiplication of an infinity by an infinity results in an infinity. The sign is determined by the rule already stated above.
- Multiplication of an infinity by a finite nonzero value results in a signed infinity. The sign is determined by the rule already stated above.
-
In the remaining cases, where neither an infinity nor
NaN is involved, the product is computed and rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode. If the magnitude is too large to represent, the result is then an infinity of appropriate sign. If the magnitude is too small to represent, the result is then a zero of appropriate sign. The ECMAScript language requires support of gradual underflow as defined by IEEE 754-2008.
12.7.3.2 Applying the / Operator
The /
-
If either operand is
NaN , the result isNaN . - The sign of the result is positive if both operands have the same sign, negative if the operands have different signs.
-
Division of an infinity by an infinity results in
NaN . - Division of an infinity by a zero results in an infinity. The sign is determined by the rule already stated above.
- Division of an infinity by a nonzero finite value results in a signed infinity. The sign is determined by the rule already stated above.
- Division of a finite value by an infinity results in zero. The sign is determined by the rule already stated above.
-
Division of a zero by a zero results in
NaN ; division of zero by any other finite value results in zero, with the sign determined by the rule already stated above. - Division of a nonzero finite value by a zero results in a signed infinity. The sign is determined by the rule already stated above.
-
In the remaining cases, where neither an infinity, nor a zero, nor
NaN is involved, the quotient is computed and rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode. If the magnitude is too large to represent, the operation overflows; the result is then an infinity of appropriate sign. If the magnitude is too small to represent, the operation underflows and the result is a zero of the appropriate sign. The ECMAScript language requires support of gradual underflow as defined by IEEE 754-2008.
12.7.3.3 Applying the % Operator
The %
In C and C++, the remainder operator accepts only integral operands; in ECMAScript, it also accepts floating-point operands.
The result of a floating-point remainder operation as computed by the % operator is not the same as the “remainder” operation defined by IEEE 754-2008. The IEEE 754-2008 “remainder” operation computes the remainder from a rounding division, not a truncating division, and so its behaviour is not analogous to that of the usual integer remainder operator. Instead the ECMAScript language defines % on floating-point operations to behave in a manner analogous to that of the Java integer remainder operator; this may be compared with the C library function fmod.
The result of an ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetic:
-
If either operand is
NaN , the result isNaN . - The sign of the result equals the sign of the dividend.
-
If the dividend is an infinity, or the divisor is a zero, or both, the result is
NaN . - If the dividend is finite and the divisor is an infinity, the result equals the dividend.
- If the dividend is a zero and the divisor is nonzero and finite, the result is the same as the dividend.
-
In the remaining cases, where neither an infinity, nor a zero, nor
NaN is involved, the floating-point remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n - (d × q) where q is an integer that is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d. r is computed and rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode.
12.7.3.4 Applying the ** Operator
Returns an implementation-dependent approximation of the result of raising base to the power exponent.
- If exponent is
NaN , the result isNaN . - If exponent is
+0 , the result is 1, even if base isNaN . - If exponent is
-0 , the result is 1, even if base isNaN . - If base is
NaN and exponent is nonzero, the result isNaN . - If abs(base) > 1 and exponent is
+∞ , the result is+∞ . - If abs(base) > 1 and exponent is
-∞ , the result is+0 . - If abs(base) is 1 and exponent is
+∞ , the result isNaN . - If abs(base) is 1 and exponent is
-∞ , the result isNaN . - If abs(base) < 1 and exponent is
+∞ , the result is+0 . - If abs(base) < 1 and exponent is
-∞ , the result is+∞ . - If base is
+∞ and exponent > 0, the result is+∞ . - If base is
+∞ and exponent < 0, the result is+0 . - If base is
-∞ and exponent > 0 and exponent is an odd integer, the result is-∞ . - If base is
-∞ and exponent > 0 and exponent is not an odd integer, the result is+∞ . - If base is
-∞ and exponent < 0 and exponent is an odd integer, the result is-0 . - If base is
-∞ and exponent < 0 and exponent is not an odd integer, the result is+0 . - If base is
+0 and exponent > 0, the result is+0 . - If base is
+0 and exponent < 0, the result is+∞ . - If base is
-0 and exponent > 0 and exponent is an odd integer, the result is-0 . - If base is
-0 and exponent > 0 and exponent is not an odd integer, the result is+0 . - If base is
-0 and exponent < 0 and exponent is an odd integer, the result is-∞ . - If base is
-0 and exponent < 0 and exponent is not an odd integer, the result is+∞ . - If base < 0 and base is finite and exponent is finite and exponent is not an integer, the result is
NaN .
The result of base ** exponent when base is
12.8 Additive Operators
Syntax
12.8.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.8.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
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 lnum be ?
ToNumber (lprim). - Let rnum be ?
ToNumber (rprim). - Return the result of applying the addition operation to lnum and rnum. See the Note below
12.8.5 .
No hint is provided in the calls to
Step 7 differs from step 5 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 ?
ToNumber (lval). - Let rnum be ?
ToNumber (rval). - Return the result of applying the subtraction operation to lnum and rnum. See the note below
12.8.5 .
12.8.5 Applying the Additive Operators to Numbers
The + operator performs addition when applied to two operands of numeric - operator performs subtraction, producing the difference of two numeric operands.
Addition is a commutative operation, but not always associative.
The result of an addition is determined using the rules of IEEE 754-2008 binary double-precision arithmetic:
-
If either operand is
NaN , the result isNaN . -
The sum of two infinities of opposite sign is
NaN . - The sum of two infinities of the same sign is the infinity of that sign.
- The sum of an infinity and a finite value is equal to the infinite operand.
-
The sum of two negative zeroes is
-0 . The sum of two positive zeroes, or of two zeroes of opposite sign, is+0 . - The sum of a zero and a nonzero finite value is equal to the nonzero operand.
-
The sum of two nonzero finite values of the same magnitude and opposite sign is
+0 . -
In the remaining cases, where neither an infinity, nor a zero, nor
NaN is involved, and the operands have the same sign or have different magnitudes, the sum is computed and rounded to the nearest representable value using IEEE 754-2008 round to nearest, ties to even mode. If the magnitude is too large to represent, the operation overflows and the result is then an infinity of appropriate sign. The ECMAScript language requires support of gradual underflow as defined by IEEE 754-2008.
The - operator performs subtraction when applied to two operands of numeric a and b, it is always the case that a-b produces the same result as a+(-b).
12.9 Bitwise Shift Operators
Syntax
12.9.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.9.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
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 ?
ToInt32 (lval). - Let rnum be ?
ToUint32 (rval). - Let shiftCount be the result of masking out all but the least significant 5 bits of rnum, that is, compute rnum & 0x1F.
- Return the result of left shifting lnum by shiftCount bits. The result is a signed 32-bit integer.
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 ?
ToInt32 (lval). - Let rnum be ?
ToUint32 (rval). - Let shiftCount be the result of masking out all but the least significant 5 bits of rnum, that is, compute rnum & 0x1F.
- Return the result of performing a sign-extending right shift of lnum by shiftCount bits. The most significant bit is propagated. The result is a signed 32-bit integer.
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 ?
ToUint32 (lval). - Let rnum be ?
ToUint32 (rval). - Let shiftCount be the result of masking out all but the least significant 5 bits of rnum, that is, compute rnum & 0x1F.
- Return the result of performing a zero-filling right shift of lnum by shiftCount bits. Vacated bits are filled with zero. The result is an unsigned 32-bit integer.
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
- Return
false .
12.10.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
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(O, C)
The abstract operation InstanceofOperator(O, C) implements the generic algorithm for determining if an object O inherits from the inheritance path defined by constructor C. This abstract operation performs the following steps:
- If
Type (C) is not Object, throw aTypeError exception. - Let instOfHandler be ?
GetMethod (C, @@hasInstance). - If instOfHandler is not
undefined , then - If
IsCallable (C) isfalse , throw aTypeError exception. - Return ?
OrdinaryHasInstance (C, O).
Steps 5 and 6 provide compatibility with previous editions of ECMAScript that did not use a @@hasInstance method to define the instanceof operator semantics. If a function 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
- Return
false .
12.11.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
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. - 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. - If r 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
- Return
false .
12.12.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
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 ?
ToInt32 (lval). - Let rnum be ?
ToInt32 (rval). - Return the result of applying the bitwise operator @ to lnum and rnum. The result is a signed 32 bit integer.
12.13 Binary Logical Operators
Syntax
The value produced by a && or || operator is not necessarily of
12.13.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.13.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
12.13.3 Runtime Semantics: Evaluation
12.14 Conditional Operator ( ? : )
Syntax
The grammar for a
12.14.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.14.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
12.14.3 Runtime Semantics: Evaluation
- Let lref be the result of evaluating
LogicalORExpression . - 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
-
It is a Syntax Error if
LeftHandSideExpression is either anObjectLiteral or anArrayLiteral and the lexical token sequence matched byLeftHandSideExpression cannot be parsed with no tokens left over usingAssignmentPattern as the goal symbol. -
It is an early
Reference Error ifLeftHandSideExpression is neither anObjectLiteral nor anArrayLiteral and IsValidSimpleAssignmentTarget ofLeftHandSideExpression isfalse .
-
It is an early
Reference Error if IsValidSimpleAssignmentTarget ofLeftHandSideExpression isfalse .
12.15.2 Static Semantics: IsFunctionDefinition
- Return
true .
- Return
false .
12.15.3 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .
12.15.4 Runtime Semantics: Evaluation
- If
LeftHandSideExpression is neither anObjectLiteral nor anArrayLiteral , then- Let lref be the result of evaluating
LeftHandSideExpression . ReturnIfAbrupt (lref).- Let rref be the result of evaluating
AssignmentExpression . - Let rval be ?
GetValue (rref). - If
IsAnonymousFunctionDefinition (AssignmentExpression ) and IsIdentifierRef ofLeftHandSideExpression are bothtrue , then- Let hasNameProperty be ?
HasOwnProperty (rval,"name"). - If hasNameProperty is
false , performSetFunctionName (rval, GetReferencedName(lref)).
- Let hasNameProperty be ?
- Perform ?
PutValue (lref, rval). - Return rval.
- Let lref be the result of evaluating
- Let assignmentPattern be the parse of the source text corresponding to
LeftHandSideExpression usingAssignmentPattern as the goal symbol.[?Yield] - Let rref be the result of evaluating
AssignmentExpression . - Let rval be ?
GetValue (rref). - Let status be the result of performing DestructuringAssignmentEvaluation of assignmentPattern using rval as the argument.
ReturnIfAbrupt (status).- 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 the production
12.15.5.1 Static Semantics: Early Errors
-
It is a Syntax Error if IsValidSimpleAssignmentTarget of
IdentifierReference isfalse .
-
It is a Syntax Error if
LeftHandSideExpression is either anObjectLiteral or anArrayLiteral and if the lexical token sequence matched byLeftHandSideExpression cannot be parsed with no tokens left over usingAssignmentPattern as the goal symbol. -
It is a Syntax Error if
LeftHandSideExpression is neither anObjectLiteral nor anArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression ) isfalse .
12.15.5.2 Runtime Semantics: DestructuringAssignmentEvaluation
with parameter value
- Perform ?
RequireObjectCoercible (value). - Return
NormalCompletion (empty ).
- Perform ?
RequireObjectCoercible (value). - Return the result of performing DestructuringAssignmentEvaluation for
AssignmentPropertyList using value as the argument.
- Let iterator be ?
GetIterator (value). - Return ?
IteratorClose (iterator,NormalCompletion (empty )).
- Let iterator be ?
GetIterator (value). - Let iteratorRecord be
Record {[[Iterator]]: iterator, [[Done]]:false }. - Let result be the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iterator, result). - Return result.
- Let iterator be ?
GetIterator (value). - Let iteratorRecord be
Record {[[Iterator]]: iterator, [[Done]]:false }. - If
Elision is present, then- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. - If status is an
abrupt completion , then- If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iterator, status). - Return
Completion (status).
- If iteratorRecord.[[Done]] is
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
- Let result be the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentRestElement with iteratorRecord as the argument. - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iterator, result). - Return result.
- Let iterator be ?
GetIterator (value). - Let iteratorRecord be
Record {[[Iterator]]: iterator, [[Done]]:false }. - Let result be the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElementList using iteratorRecord as the argument. - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iterator, result). - Return result.
- Let iterator be ?
GetIterator (value). - Let iteratorRecord be
Record {[[Iterator]]: iterator, [[Done]]:false }. - Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElementList using iteratorRecord as the argument. - If status is an
abrupt completion , then- If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iterator, status). - Return
Completion (status).
- If iteratorRecord.[[Done]] is
- If
Elision is present, then- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. - If status is an
abrupt completion , then- If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iterator, status). - Return
Completion (status).
- If iteratorRecord.[[Done]] is
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
- If
AssignmentRestElement is present, then- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentRestElement with iteratorRecord as the argument.
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
- If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iterator, status). - Return
Completion (status).
- Let status be the result of performing DestructuringAssignmentEvaluation for
AssignmentPropertyList using value as the argument. ReturnIfAbrupt (status).- Return the result of performing DestructuringAssignmentEvaluation for
AssignmentProperty using value as the argument.
- 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- Let defaultValue be the result of evaluating
Initializer . - Let v be ?
GetValue (defaultValue). - If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be ?
HasOwnProperty (v,"name"). - If hasNameProperty is
false , performSetFunctionName (v, P).
- Let hasNameProperty be ?
- Let defaultValue be the result of evaluating
- Return ?
PutValue (lref, v).
- Let name be the result of evaluating
PropertyName . ReturnIfAbrupt (name).- Return the result of performing KeyedDestructuringAssignmentEvaluation of
AssignmentElement with value and name as the arguments.
12.15.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation
with parameters iteratorRecord
- Return the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElisionElement using iteratorRecord as the argument.
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElementList using iteratorRecord as the argument. ReturnIfAbrupt (status).- 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.
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. ReturnIfAbrupt (status).- Return the result of performing IteratorDestructuringAssignmentEvaluation of
AssignmentElement with iteratorRecord as the argument.
- If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord.[[Iterator]]). - 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 ).
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. ReturnIfAbrupt (status).- If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord.[[Iterator]]). - 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.[[Iterator]]). - 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- Let defaultValue be the result of evaluating
Initializer . - Let v be ?
GetValue (defaultValue).
- Let defaultValue be the result of evaluating
- Else, let v be value.
- If
DestructuringAssignmentTarget is anObjectLiteral or anArrayLiteral , then- Let nestedAssignmentPattern be the parse of the source text corresponding to
DestructuringAssignmentTarget using eitherAssignmentPattern orAssignmentPattern as the goal symbol depending upon whether this[Yield] AssignmentElement has the [Yield] parameter. - Return the result of performing DestructuringAssignmentEvaluation of nestedAssignmentPattern with v as the argument.
- Let nestedAssignmentPattern be the parse of the source text corresponding to
- If
Initializer is present and value isundefined andIsAnonymousFunctionDefinition (Initializer ) and IsIdentifierRef ofDestructuringAssignmentTarget are bothtrue , then- Let hasNameProperty be ?
HasOwnProperty (v,"name"). - If hasNameProperty is
false , performSetFunctionName (v, GetReferencedName(lref)).
- Let hasNameProperty be ?
- 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.[[Iterator]]). - 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).- Let status be
CreateDataProperty (A, !ToString (n), nextValue). - Assert: status is
true . - Increment n by 1.
- Let nextValue be
- Let next be
- If
DestructuringAssignmentTarget is neither anObjectLiteral nor anArrayLiteral , then- Return ?
PutValue (lref, A).
- Return ?
- Let nestedAssignmentPattern be the parse of the source text corresponding to
DestructuringAssignmentTarget using eitherAssignmentPattern orAssignmentPattern as the goal symbol depending upon whether this[Yield] AssignmentElement has the [Yield] parameter. - Return the result of performing DestructuringAssignmentEvaluation of nestedAssignmentPattern with A as the argument.
12.15.5.4 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- Let defaultValue be the result of evaluating
Initializer . - Let rhsValue be ?
GetValue (defaultValue).
- Let defaultValue be the result of evaluating
- Else, let rhsValue be v.
- If
DestructuringAssignmentTarget is anObjectLiteral or anArrayLiteral , then- Let assignmentPattern be the parse of the source text corresponding to
DestructuringAssignmentTarget using eitherAssignmentPattern orAssignmentPattern as the goal symbol depending upon whether this[Yield] AssignmentElement has the [Yield] parameter. - Return the result of performing DestructuringAssignmentEvaluation of assignmentPattern with rhsValue as the argument.
- Let assignmentPattern be the parse of the source text corresponding to
- If
Initializer is present and v isundefined andIsAnonymousFunctionDefinition (Initializer ) and IsIdentifierRef ofDestructuringAssignmentTarget are bothtrue , then- Let hasNameProperty be ?
HasOwnProperty (rhsValue,"name"). - If hasNameProperty is
false , performSetFunctionName (rhsValue, GetReferencedName(lref)).
- Let hasNameProperty be ?
- Return ?
PutValue (lref, rhsValue).
12.16 Comma Operator ( , )
Syntax
12.16.1 Static Semantics: IsFunctionDefinition
- Return
false .
12.16.2 Static Semantics: IsValidSimpleAssignmentTarget
- Return
false .