Stage 3 Draft / June 9, 2020

Logical Assignment Operators

1 Scope

This is the spec text of the Logical Assignment proposal in ECMAScript.

Each Logical Assignment operator embraces the short-circuiting semantics of the respective Binary Logical operator. If the operator short circuits, then the [[Set]] operation is skipped.

The new LogicalAssignmentPunctuator production defined in Punctuators section is used only to highlight the new additions. When merged with the main ecma262 spec, the new punctuators should just be added to OtherPunctuator.

2 Punctuators (11.7)

Syntax

Punctuator::LogicalAssignmentPunctuator OptionalChainingPunctuator OtherPunctuator LogicalAssignmentPunctuator::one of&&=||=??= OptionalChainingPunctuator::?.[lookahead ∉ DecimalDigit] OtherPunctuator::one of{()[]....;,<><=>===!====!==+-*%**++--<<>>>>>&|^!~&&||???:=+=-=*=%=**=<<=>>=>>>=&=|=^==> DivPunctuator::/ /= RightBracePunctuator::}

3 Assignment Operators (12.15)

Syntax

AssignmentExpression[In, Yield, Await]:ConditionalExpression[?In, ?Yield, ?Await] [+Yield]YieldExpression[?In, ?Await] ArrowFunction[?In, ?Yield, ?Await] AsyncArrowFunction[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await]=AssignmentExpression[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await]AssignmentOperatorAssignmentExpression[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await]&&=AssignmentExpression[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await]||=AssignmentExpression[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await]??=AssignmentExpression[?In, ?Yield, ?Await] AssignmentOperator:one of*=/=%=+=-=<<=>>=>>>=&=^=|=**=

3.1 Static Semantics: Early Errors

AssignmentExpression:LeftHandSideExpression=AssignmentExpression AssignmentExpression:LeftHandSideExpressionAssignmentOperatorAssignmentExpression LeftHandSideExpression&&=AssignmentExpression LeftHandSideExpression||=AssignmentExpression LeftHandSideExpression??=AssignmentExpression

3.2 Static Semantics: IsFunctionDefinition

AssignmentExpression:ArrowFunction AsyncArrowFunction
  1. Return true.
AssignmentExpression:YieldExpression LeftHandSideExpression=AssignmentExpression LeftHandSideExpressionAssignmentOperatorAssignmentExpression LeftHandSideExpression&&=AssignmentExpression LeftHandSideExpression||=AssignmentExpression LeftHandSideExpression??=AssignmentExpression
  1. Return false.

3.3 Static Semantics: AssignmentTargetType

AssignmentExpression:YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression=AssignmentExpression LeftHandSideExpressionAssignmentOperatorAssignmentExpression LeftHandSideExpression&&=AssignmentExpression LeftHandSideExpression||=AssignmentExpression LeftHandSideExpression??=AssignmentExpression
  1. Return invalid.

3.4 Runtime Semantics: Evaluation

AssignmentExpression:LeftHandSideExpression=AssignmentExpression
  1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then
    1. Let lref be the result of evaluating LeftHandSideExpression.
    2. ReturnIfAbrupt(lref).
    3. If IsAnonymousFunctionDefinition(AssignmentExpression) and IsIdentifierRef of LeftHandSideExpression are both true, then
      1. Let rval be NamedEvaluation of AssignmentExpression with argument GetReferencedName(lref).
    4. Else,
      1. Let rref be the result of evaluating AssignmentExpression.
      2. Let rval be ? GetValue(rref).
    5. Perform ? PutValue(lref, rval).
    6. Return rval.
  2. Let assignmentPattern be the AssignmentPattern that is covered by LeftHandSideExpression.
  3. Let rref be the result of evaluating AssignmentExpression.
  4. Let rval be ? GetValue(rref).
  5. Perform ? DestructuringAssignmentEvaluation of assignmentPattern using rval as the argument.
  6. Return rval.
AssignmentExpression:LeftHandSideExpressionAssignmentOperatorAssignmentExpression
  1. Let lref be the result of evaluating LeftHandSideExpression.
  2. Let lval be ? GetValue(lref).
  3. Let rref be the result of evaluating AssignmentExpression.
  4. Let rval be ? GetValue(rref).
  5. Let op be the @ where AssignmentOperator is @=.
  6. Let r be the result of applying op to lval and rval as if evaluating the expression lval op rval.
  7. Perform ? PutValue(lref, r).
  8. Return r.
AssignmentExpression:LeftHandSideExpression&&=AssignmentExpression
  1. Let lref be the result of evaluating LeftHandSideExpression.
  2. Let lval be ? GetValue(lref).
  3. Let lbool be ! ToBoolean(lval).
  4. If lbool is false, return lval.
  5. If IsAnonymousFunctionDefinition(AssignmentExpression) and IsIdentifierRef of LeftHandSideExpression are both true, then
    1. Let rval be NamedEvaluation of AssignmentExpression with argument GetReferencedName(lref).
  6. Else,
    1. Let rref be the result of evaluating AssignmentExpression.
    2. Let rval be ? GetValue(rref).
  7. Perform ? PutValue(lref, rval).
  8. Return rval.
AssignmentExpression:LeftHandSideExpression||=AssignmentExpression
  1. Let lref be the result of evaluating LeftHandSideExpression.
  2. Let lval be ? GetValue(lref).
  3. Let lbool be ! ToBoolean(lval).
  4. If lbool is true, return lval.
  5. If IsAnonymousFunctionDefinition(AssignmentExpression) and IsIdentifierRef of LeftHandSideExpression are both true, then
    1. Let rval be NamedEvaluation of AssignmentExpression with argument GetReferencedName(lref).
  6. Else,
    1. Let rref be the result of evaluating AssignmentExpression.
    2. Let rval be ? GetValue(rref).
  7. Perform ? PutValue(lref, rval).
  8. Return rval.
AssignmentExpression:LeftHandSideExpression??=AssignmentExpression
  1. Let lref be the result of evaluating LeftHandSideExpression.
  2. Let lval be ? GetValue(lref).
  3. If lval is neither undefined nor null, return lval.
  4. If IsAnonymousFunctionDefinition(AssignmentExpression) and IsIdentifierRef of LeftHandSideExpression are both true, then
    1. Let rval be NamedEvaluation of AssignmentExpression with argument GetReferencedName(lref).
  5. Else,
    1. Let rref be the result of evaluating AssignmentExpression.
    2. Let rval be ? GetValue(rref).
  6. Perform ? PutValue(lref, rval).
  7. Return rval.
Note

When this expression occurs within strict mode code and the respective GetValue of lref step is reached, it is a runtime error if lref is an unresolvable reference. If it is, a ReferenceError exception is thrown. Additionally if the PutValue step is reached, the lref may not be a reference to a data property with the attribute value { [[Writable]]: false }, to an accessor property with the attribute value { [[Set]]: undefined }, nor to a non-existent property of an object for which the IsExtensible predicate returns the value false. In these cases a TypeError exception is thrown.

4 Static Semantics: HasCallInTailPosition (14.9.2)

With parameter call.

Note

call is a Parse Node that represents a specific range of source text. When the following algorithms compare call to another Parse Node, it is a test of whether they represent the same source text.

4.1 Expression Rules (14.9.2.2)

Note

A potential tail position call that is immediately followed by return GetValue of the call result is also a possible tail position call. Function calls cannot return reference values, so such a GetValue operation will always return the same value as the actual function call result.

AssignmentExpression:YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression=AssignmentExpression LeftHandSideExpressionAssignmentOperatorAssignmentExpression LeftHandSideExpression&&=AssignmentExpression LeftHandSideExpression||=AssignmentExpression LeftHandSideExpression??=AssignmentExpression BitwiseANDExpression:BitwiseANDExpression&EqualityExpression BitwiseXORExpression:BitwiseXORExpression^BitwiseANDExpression BitwiseORExpression:BitwiseORExpression|BitwiseXORExpression EqualityExpression:EqualityExpression==RelationalExpression EqualityExpression!=RelationalExpression EqualityExpression===RelationalExpression EqualityExpression!==RelationalExpression RelationalExpression:RelationalExpression<ShiftExpression RelationalExpression>ShiftExpression RelationalExpression<=ShiftExpression RelationalExpression>=ShiftExpression RelationalExpressioninstanceofShiftExpression RelationalExpressioninShiftExpression ShiftExpression:ShiftExpression<<AdditiveExpression ShiftExpression>>AdditiveExpression ShiftExpression>>>AdditiveExpression AdditiveExpression:AdditiveExpression+MultiplicativeExpression AdditiveExpression-MultiplicativeExpression MultiplicativeExpression:MultiplicativeExpressionMultiplicativeOperatorExponentiationExpression ExponentiationExpression:UpdateExpression**ExponentiationExpression UpdateExpression:LeftHandSideExpression++ LeftHandSideExpression-- ++UnaryExpression --UnaryExpression UnaryExpression:deleteUnaryExpression voidUnaryExpression typeofUnaryExpression +UnaryExpression -UnaryExpression ~UnaryExpression !UnaryExpression AwaitExpression CallExpression:SuperCall CallExpression[Expression] CallExpression.IdentifierName NewExpression:newNewExpression MemberExpression:MemberExpression[Expression] MemberExpression.IdentifierName SuperProperty MetaProperty newMemberExpressionArguments PrimaryExpression:this IdentifierReference Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral
  1. Return false.
Expression:AssignmentExpression Expression,AssignmentExpression
  1. Return HasCallInTailPosition of AssignmentExpression with argument call.
ConditionalExpression:ShortCircuitExpression?AssignmentExpression:AssignmentExpression
  1. Let has be HasCallInTailPosition of the first AssignmentExpression with argument call.
  2. If has is true, return true.
  3. Return HasCallInTailPosition of the second AssignmentExpression with argument call.
LogicalANDExpression:LogicalANDExpression&&BitwiseORExpression
  1. Return HasCallInTailPosition of BitwiseORExpression with argument call.
LogicalORExpression:LogicalORExpression||LogicalANDExpression
  1. Return HasCallInTailPosition of LogicalANDExpression with argument call.
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
  1. Return HasCallInTailPosition of BitwiseORExpression with argument call.
CallExpression:CoverCallExpressionAndAsyncArrowHead CallExpressionArguments CallExpressionTemplateLiteral
  1. If this CallExpression is call, return true.
  2. Return false.
OptionalExpression:MemberExpressionOptionalChain CallExpressionOptionalChain OptionalExpressionOptionalChain
  1. Return HasCallInTailPosition of OptionalChain with argument call.
OptionalChain:?.[Expression] ?.IdentifierName OptionalChain[Expression] OptionalChain.IdentifierName
  1. Return false.
OptionalChain:?.Arguments OptionalChainArguments
  1. If this OptionalChain is call, return true.
  2. Return false.
MemberExpression:MemberExpressionTemplateLiteral
  1. If this MemberExpression is call, return true.
  2. Return false.
PrimaryExpression:CoverParenthesizedExpressionAndArrowParameterList
  1. Let expr be CoveredParenthesizedExpression of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return HasCallInTailPosition of expr with argument call.
ParenthesizedExpression:(Expression)
  1. Return HasCallInTailPosition of Expression with argument call.

A Copyright & Software License

Copyright Notice

© 2020 Justin Ridgewell

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.