13.15 Assignment Operators
Syntax
13.15.1 Static Semantics: Early Errors
If
If
-
It is a Syntax Error if
AssignmentTargetType ofLeftHandSideExpression is notsimple .
-
It is a Syntax Error if
AssignmentTargetType ofLeftHandSideExpression is notsimple .
13.15.2 Runtime Semantics: Evaluation
- If
LeftHandSideExpression is neither anObjectLiteral nor anArrayLiteral , then- Let lref be ?
Evaluation ofLeftHandSideExpression . - If
IsAnonymousFunctionDefinition (AssignmentExpression ) andIsIdentifierRef ofLeftHandSideExpression are bothtrue , then- Let rval be ?
NamedEvaluation ofAssignmentExpression with argument lref.[[ReferencedName]].
- Let rval be ?
- 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 . - 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). - Let lbool be
ToBoolean (lval). - If lbool is
false , return lval. - If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue andIsIdentifierRef ofLeftHandSideExpression istrue , then- Let rval be ?
NamedEvaluation ofAssignmentExpression with argument lref.[[ReferencedName]].
- Let rval be ?
- 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). - Let lbool be
ToBoolean (lval). - If lbool is
true , return lval. - If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue andIsIdentifierRef ofLeftHandSideExpression istrue , then- Let rval be ?
NamedEvaluation ofAssignmentExpression with argument lref.[[ReferencedName]].
- Let rval be ?
- 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 rval be ?
NamedEvaluation ofAssignmentExpression with argument lref.[[ReferencedName]].
- Let rval be ?
- 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
Type (lnum) is notType (rnum), 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).
- If opText is
- Let operation be the abstract operation associated with opText and
Type (lnum) in the following table:opText Type (lnum)operation **
Number Number::exponentiate *
Number Number::multiply *
BigInt BigInt::multiply /
Number Number::divide %
Number Number::remainder +
Number Number::add +
BigInt BigInt::add -
Number Number::subtract -
BigInt BigInt::subtract <<
Number Number::leftShift <<
BigInt BigInt::leftShift >>
Number Number::signedRightShift >>
BigInt BigInt::signedRightShift >>>
Number Number::unsignedRightShift &
Number Number::bitwiseAND &
BigInt BigInt::bitwiseAND ^
Number Number::bitwiseXOR ^
BigInt BigInt::bitwiseXOR |
Number Number::bitwiseOR |
BigInt BigInt::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
AssignmentTargetType ofIdentifierReference is notsimple .
-
It is a Syntax Error if
DestructuringAssignmentTarget is either anArrayLiteral or anObjectLiteral .
If
If
-
It is a Syntax Error if
AssignmentTargetType 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 ofAssignmentPropertyList with argument value. - Let nextNames be ?
PropertyDestructuringAssignmentEvaluation ofAssignmentProperty with argument value. - Return the
list-concatenation of propertyNames and nextNames.
- Let P be
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 ofAssignmentElisionElement with argument iteratorRecord.
- Perform ?
IteratorDestructuringAssignmentEvaluation ofAssignmentElementList with argument iteratorRecord. - Return ?
IteratorDestructuringAssignmentEvaluation ofAssignmentElisionElement with argument iteratorRecord.
- Return ?
IteratorDestructuringAssignmentEvaluation ofAssignmentElement with argument iteratorRecord.
- Perform ?
IteratorDestructuringAssignmentEvaluation ofElision with argument iteratorRecord. - Return ?
IteratorDestructuringAssignmentEvaluation ofAssignmentElement with argument iteratorRecord.
- If iteratorRecord.[[Done]] is
false , then- Let next be
Completion (IteratorStep (iteratorRecord)). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue .
- Let next be
- Return
unused .
- Perform ?
IteratorDestructuringAssignmentEvaluation ofElision with argument iteratorRecord. - If iteratorRecord.[[Done]] is
false , then- Let next be
Completion (IteratorStep (iteratorRecord)). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue .
- Let next be
- Return
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 v be ?
NamedEvaluation ofInitializer with argument lref.[[ReferencedName]].
- Let v be ?
- 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 ) andIsIdentifierRef ofDestructuringAssignmentTarget are bothtrue , then- Let rhsValue be ?
NamedEvaluation ofInitializer with argument lref.[[ReferencedName]].
- Let rhsValue be ?
- 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).