[parser] Always return a valid var from DeclareVariableName

That way we can continue running in failure mode.

Bug: chromium:933214
Change-Id: I975901a72f615e2b7ed9955b75ce86bbcad0bbbb
Reviewed-on: https://chromium-review.googlesource.com/c/1481219
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59813}
This commit is contained in:
Toon Verwaest 2019-02-21 17:24:43 +01:00 committed by Commit Bot
parent 42a38d2ada
commit e14a24d32e
3 changed files with 19 additions and 4 deletions

View File

@ -56,7 +56,8 @@ class ExpressionScope {
// with or catch scope. In those cases the proxy isn't guaranteed to
// refer to the declared variable, so consider it unresolved.
parser()->scope()->AddUnresolved(result);
} else if (var) {
} else {
DCHECK_NOT_NULL(var);
result->BindTo(var);
}
}
@ -327,9 +328,8 @@ class VariableDeclarationParsingScope : public ExpressionScope<Types> {
//
// This also handles marking of loop variables in for-in and for-of
// loops, as determined by loop-nesting-depth.
if (V8_LIKELY(var)) {
var->set_maybe_assigned();
}
DCHECK_NOT_NULL(var);
var->set_maybe_assigned();
}
}
return var;

View File

@ -1110,6 +1110,8 @@ class PreParser : public ParserBase<PreParser> {
Variable* var = scope->DeclareVariableName(name, mode, was_added, kind);
if (var == nullptr) {
ReportUnidentifiableError();
if (!IsLexicalVariableMode(mode)) scope = scope->GetDeclarationScope();
var = scope->LookupLocal(name);
} else if (var->scope() != scope) {
DCHECK_NE(kNoSourcePosition, position);
DCHECK_EQ(VariableMode::kVar, mode);

View File

@ -0,0 +1,13 @@
// 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.
assertThrows(`
function __v_0() {
function __v_2() {
try {
function* __v_0() {}
function __v_0() {}
}
}
}`, SyntaxError);