Set .name of anonymous functions on the RHS of logical assignment.

https://github.com/tc39/proposal-logical-assignment/pull/24 reached
consensus in June TC39.

Drive-by refactoring of testing for logical assignment ops using
IsInRange.

Bug: v8:10579
Change-Id: I5a203ba552a905cd28f75c5d223998431a1966ce
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2225809
Reviewed-by: Marja Hölttä <marja@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68101}
This commit is contained in:
Shu-yu Guo 2020-06-01 17:38:42 -07:00 committed by Commit Bot
parent 6463c0f00c
commit c342ba8247
3 changed files with 38 additions and 4 deletions

View File

@ -2755,8 +2755,7 @@ ParserBase<Impl>::ParseAssignmentExpressionCoverGrammar() {
Token::Value op = peek();
if (!Token::IsArrowOrAssignmentOp(op)) return expression;
if ((op == Token::ASSIGN_NULLISH || op == Token::ASSIGN_OR ||
op == Token::ASSIGN_AND) &&
if (Token::IsLogicalAssignmentOp(op) &&
!flags().allow_harmony_logical_assignment()) {
return expression;
}
@ -2830,12 +2829,16 @@ ParserBase<Impl>::ParseAssignmentExpressionCoverGrammar() {
ExpressionT right = ParseAssignmentExpression();
if (op == Token::ASSIGN) {
if (op == Token::ASSIGN || Token::IsLogicalAssignmentOp(op)) {
// We try to estimate the set of properties set by constructors. We define a
// new property whenever there is an assignment to a property of 'this'. We
// should probably only add properties if we haven't seen them before.
// Otherwise we'll probably overestimate the number of properties.
if (impl()->IsThisProperty(expression)) function_state_->AddProperty();
//
// Do not count logical assignments, because they are conditional.
if (op == Token::ASSIGN && impl()->IsThisProperty(expression)) {
function_state_->AddProperty();
}
impl()->CheckAssigningFunctionLiteralToProperty(expression, right);

View File

@ -284,6 +284,10 @@ class V8_EXPORT_PRIVATE Token {
return base::IsInRange(token, INIT, ASSIGN_SUB);
}
static bool IsLogicalAssignmentOp(Value token) {
return base::IsInRange(token, ASSIGN_NULLISH, ASSIGN_AND);
}
static bool IsBinaryOp(Value op) { return base::IsInRange(op, COMMA, SUB); }
static bool IsCompareOp(Value op) { return base::IsInRange(op, EQ, IN); }

View File

@ -0,0 +1,27 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-logical-assignment
{
let x = undefined;
x ??= function() {};
assertEquals(x.name, "x");
}
{
let y = false;
y ||= function() {};
assertEquals(y.name, "y");
}
{
let z = true;
z &&= function() {};
assertEquals(z.name, "z");
}