[parser] Skipping inner funcs: fix destructuring catch variables.
Make PreParser match what Parser does. BUG=v8:5516 Change-Id: I2801206fd17b9a5047bc43c6112f4945971596b7 Reviewed-on: https://chromium-review.googlesource.com/544949 Commit-Queue: Marja Hölttä <marja@chromium.org> Reviewed-by: Daniel Vogelheim <vogelheim@chromium.org> Cr-Commit-Position: refs/heads/master@{#46169}
This commit is contained in:
parent
b6bbfaec17
commit
2c260da393
@ -1060,11 +1060,16 @@ class PreParser : public ParserBase<PreParser> {
|
||||
|
||||
V8_INLINE void RewriteCatchPattern(CatchInfo* catch_info, bool* ok) {
|
||||
if (track_unresolved_variables_) {
|
||||
if (catch_info->name.string_ != nullptr) {
|
||||
// Unlike in the parser, we need to declare the catch variable as LET
|
||||
// variable, so that it won't get hoisted out of the scope.
|
||||
catch_info->scope->DeclareVariableName(catch_info->name.string_, LET);
|
||||
const AstRawString* catch_name = catch_info->name.string_;
|
||||
if (catch_name == nullptr) {
|
||||
catch_name = ast_value_factory()->dot_catch_string();
|
||||
}
|
||||
// Unlike in the parser, we need to declare the catch variable as LET
|
||||
// variable, so that it won't get hoisted out of the scope. (Parser uses
|
||||
// DeclareLocal instead of DeclareVariable to prevent hoisting.) Another
|
||||
// solution would've been to add DeclareLocalName just for this purpose.
|
||||
catch_info->scope->DeclareVariableName(catch_name, LET);
|
||||
|
||||
if (catch_info->pattern.variables_ != nullptr) {
|
||||
for (auto variable : *catch_info->pattern.variables_) {
|
||||
scope()->DeclareVariableName(variable->raw_name(), LET);
|
||||
|
@ -593,7 +593,11 @@ TEST(PreParserScopeAnalysis) {
|
||||
{"try { } catch(var1) { var1 = 3; }"},
|
||||
{"try { } catch(var1) { function f() { var1; } }"},
|
||||
{"try { } catch(var1) { function f() { var1 = 3; } }"},
|
||||
// FIXME(marja): Add tests for destructuring catch.
|
||||
|
||||
{"try { } catch({var1, var2}) { function f() { var1 = 3; } }"},
|
||||
{"try { } catch([var1, var2]) { function f() { var1 = 3; } }"},
|
||||
{"try { } catch({}) { }"},
|
||||
{"try { } catch([]) { }"},
|
||||
|
||||
// Shadowing the catch variable
|
||||
{"try { } catch(var1) { var var1 = 3; }"},
|
||||
|
Loading…
Reference in New Issue
Block a user