Stage 2 Draft / June 2, 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]LogicalAssignmentOperatorAssignmentExpression[?In, ?Yield, ?Await] AssignmentOperator:one of*=/=%=+=-=<<=>>=>>>=&=^=|=**= LogicalAssignmentOperator:one of&&=||=??=

3.1 Static Semantics: Early Errors

AssignmentExpression:LeftHandSideExpression=AssignmentExpression AssignmentExpression:LeftHandSideExpressionAssignmentOperatorAssignmentExpression AssignmentExpression:LeftHandSideExpressionLogicalAssignmentOperatorAssignmentExpression

3.2 Static Semantics: IsFunctionDefinition

AssignmentExpression:ArrowFunction AsyncArrowFunction
  1. Return true.
AssignmentExpression:YieldExpression LeftHandSideExpression=AssignmentExpression LeftHandSideExpressionAssignmentOperatorAssignmentExpression LeftHandSideExpressionLogicalAssignmentOperatorAssignmentExpression
  1. Return false.

3.3 Static Semantics: AssignmentTargetType

AssignmentExpression:YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression=AssignmentExpression LeftHandSideExpressionAssignmentOperatorAssignmentExpression LeftHandSideExpressionLogicalAssignmentOperatorAssignmentExpression
  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.

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.