[parser] Don't mark const variables as assigned

Since const variables are  immutable, ignore SetMaybeAssigned for them.

Bug: chromium:999450, chromium:1000170, v8:8510
Change-Id: Idc1b71677b3d03bb63cc025017c119710b8f392d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1782170
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63579}
This commit is contained in:
Dan Elphick 2019-09-05 14:52:24 +01:00 committed by Commit Bot
parent 9a6f23c258
commit a35a705983
3 changed files with 24 additions and 1 deletions

View File

@ -73,6 +73,8 @@ class Variable final : public ZoneObject {
return MaybeAssignedFlagField::decode(bit_field_); return MaybeAssignedFlagField::decode(bit_field_);
} }
void SetMaybeAssigned() { void SetMaybeAssigned() {
if (mode() == VariableMode::kConst) return;
// If this variable is dynamically shadowing another variable, then that // If this variable is dynamically shadowing another variable, then that
// variable could also be assigned (in the non-shadowing case). // variable could also be assigned (in the non-shadowing case).
if (has_local_if_not_shadowed()) { if (has_local_if_not_shadowed()) {
@ -81,7 +83,8 @@ class Variable final : public ZoneObject {
if (!maybe_assigned()) { if (!maybe_assigned()) {
local_if_not_shadowed()->SetMaybeAssigned(); local_if_not_shadowed()->SetMaybeAssigned();
} }
DCHECK(local_if_not_shadowed()->maybe_assigned()); DCHECK_IMPLIES(local_if_not_shadowed()->mode() != VariableMode::kConst,
local_if_not_shadowed()->maybe_assigned());
} }
set_maybe_assigned(); set_maybe_assigned();
} }

View File

@ -0,0 +1,10 @@
// Copyright 2019 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: --no-lazy --stress-lazy-source-positions --enable-lazy-source-positions
(function a() {
function b() { a(); }
function c() { eval(); }
})();

View File

@ -0,0 +1,10 @@
// Copyright 2019 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: --no-lazy --stress-lazy-source-positions --enable-lazy-source-positions
(function foo() {
foo = null;
() => foo;
})