Commit 6c6dd449 authored by adamk's avatar adamk Committed by Commit bot

Defer CONST_LEGACY redeclaration errors until runtime in harmony mode

This fixes a corner-case in redeclaration handling, where the ES2015
early error case got mixed up with legacy const handling in the parser.

Redeclaration using ES2015 'let' and 'const' should be early errors,
but legacy 'const' redeclaration has historically been a runtime error,
and should stay that way until legacy 'const' is gone.

The fix here is uglier than it might be due to
https://code.google.com/p/v8/issues/detail?id=4577, which keeps us
from simplifying the mess of if/else-if in the current code.

BUG=v8:4576
LOG=n

Review URL: https://codereview.chromium.org/1485943002

Cr-Commit-Position: refs/heads/master@{#32429}
parent 0c9fd2f7
......@@ -2093,7 +2093,9 @@ Variable* Parser::Declare(Declaration* declaration,
// because the var declaration is hoisted to the function scope where 'x'
// is already bound.
DCHECK(IsDeclaredVariableMode(var->mode()));
if (is_strict(language_mode()) || allow_harmony_sloppy()) {
if (is_strict(language_mode()) ||
(allow_harmony_sloppy() && mode != CONST_LEGACY &&
var->mode() != CONST_LEGACY)) {
// In harmony we treat re-declarations as early errors. See
// ES5 16 for a definition of early errors.
if (declaration_kind == DeclarationDescriptor::NORMAL) {
......
// Copyright 2015 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-sloppy --legacy-const
// Should trigger a runtime error, not an early error.
function f() {
const x;
var x;
}
assertThrows(f, SyntaxError);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment