From 670399facb90d896a51bb82dd44a8ba029ace120 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Fri, 5 Nov 2021 14:43:17 -0700 Subject: [PATCH] [parsing] Fix -Wshadow warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: v8:12244,v8:12245 Change-Id: Ic84020ea7e54c50dc8f773eb655078582bb33fa7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3264361 Reviewed-by: Marja Hölttä Reviewed-by: Shu-yu Guo Commit-Queue: Zhi An Ng Cr-Commit-Position: refs/heads/main@{#77771} --- src/parsing/expression-scope.h | 8 +-- src/parsing/parser-base.h | 8 +-- src/parsing/parser.cc | 4 +- test/cctest/test-parsing.cc | 109 ++++++++++++++++----------------- 4 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/parsing/expression-scope.h b/src/parsing/expression-scope.h index d6c117f73b..c49fae7519 100644 --- a/src/parsing/expression-scope.h +++ b/src/parsing/expression-scope.h @@ -63,16 +63,16 @@ class ExpressionScope { if (scope->is_with_scope()) { passed_through_with = true; } else if (scope->is_catch_scope()) { - Variable* var = scope->LookupLocal(name); + Variable* masking_var = scope->LookupLocal(name); // If a variable is declared in a catch scope with a masking // catch-declared variable, the initializing assignment is an // assignment to the catch-declared variable instead. // https://tc39.es/ecma262/#sec-variablestatements-in-catch-blocks - if (var != nullptr) { + if (masking_var != nullptr) { result->set_is_assigned(); if (passed_through_with) break; - result->BindTo(var); - var->SetMaybeAssigned(); + result->BindTo(masking_var); + masking_var->SetMaybeAssigned(); return result; } } diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h index 9a0f4e580f..64d491f312 100644 --- a/src/parsing/parser-base.h +++ b/src/parsing/parser-base.h @@ -3446,7 +3446,7 @@ ParserBase::ParseLeftHandSideContinuation(ExpressionT result) { // async () => ... if (!args.length()) return factory()->NewEmptyParentheses(pos); // async ( Arguments ) => ... - ExpressionT result = impl()->ExpressionListToExpression(args); + result = impl()->ExpressionListToExpression(args); result->mark_parenthesized(); return result; } @@ -4581,8 +4581,8 @@ ParserBase::ParseArrowFunctionLiteral( if (has_error()) return impl()->FailureExpression(); DeclarationScope* function_scope = next_arrow_function_info_.scope; - FunctionState function_state(&function_state_, &scope_, - function_scope); + FunctionState inner_function_state(&function_state_, &scope_, + function_scope); Scanner::Location loc(function_scope->start_position(), end_position()); FormalParametersT parameters(function_scope); @@ -4934,7 +4934,7 @@ typename ParserBase::ExpressionT ParserBase::ParseTemplateLiteral( Next(); pos = position(); - bool is_valid = CheckTemplateEscapes(forbid_illegal_escapes); + is_valid = CheckTemplateEscapes(forbid_illegal_escapes); impl()->AddTemplateSpan(&ts, is_valid, next == Token::TEMPLATE_TAIL); } while (next == Token::TEMPLATE_SPAN); diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index d1e734ddbe..55914dc2e8 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -954,14 +954,14 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info, // Parsing patterns as variable reference expression creates // NewUnresolved references in current scope. Enter arrow function // scope for formal parameter parsing. - BlockState block_state(&scope_, scope); + BlockState inner_block_state(&scope_, scope); if (Check(Token::LPAREN)) { // '(' StrictFormalParameters ')' ParseFormalParameterList(&formals); Expect(Token::RPAREN); } else { // BindingIdentifier - ParameterParsingScope scope(impl(), &formals); + ParameterParsingScope parameter_parsing_scope(impl(), &formals); ParseFormalParameter(&formals); DeclareFormalParameters(&formals); } diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index 8181edfc8e..ef1e7aae62 100644 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -74,28 +74,28 @@ void MockUseCounterCallback(v8::Isolate* isolate, // Helpers for parsing and checking that the result has no error, implemented as // macros to report the correct test error location. -#define FAIL_WITH_PENDING_PARSER_ERROR(info, script, isolate) \ - do { \ - (info)->pending_error_handler()->PrepareErrors( \ - (isolate), (info)->ast_value_factory()); \ - (info)->pending_error_handler()->ReportErrors((isolate), (script)); \ - \ - i::Handle exception_handle( \ - i::JSObject::cast((isolate)->pending_exception()), (isolate)); \ - i::Handle message_string = i::Handle::cast( \ - i::JSReceiver::GetProperty((isolate), exception_handle, "message") \ - .ToHandleChecked()); \ - (isolate)->clear_pending_exception(); \ - \ - String source = String::cast((script)->source()); \ - \ - FATAL( \ - "Parser failed on:\n" \ - "\t%s\n" \ - "with error:\n" \ - "\t%s\n" \ - "However, we expected no error.", \ - source.ToCString().get(), message_string->ToCString().get()); \ +#define FAIL_WITH_PENDING_PARSER_ERROR(info, script, isolate) \ + do { \ + (info)->pending_error_handler()->PrepareErrors( \ + (isolate), (info)->ast_value_factory()); \ + (info)->pending_error_handler()->ReportErrors((isolate), (script)); \ + \ + i::Handle exception_handle( \ + i::JSObject::cast((isolate)->pending_exception()), (isolate)); \ + i::Handle message_string = i::Handle::cast( \ + i::JSReceiver::GetProperty((isolate), exception_handle, "message") \ + .ToHandleChecked()); \ + (isolate)->clear_pending_exception(); \ + \ + String script_source = String::cast((script)->source()); \ + \ + FATAL( \ + "Parser failed on:\n" \ + "\t%s\n" \ + "with error:\n" \ + "\t%s\n" \ + "However, we expected no error.", \ + script_source.ToCString().get(), message_string->ToCString().get()); \ } while (false) #define CHECK_PARSE_PROGRAM(info, script, isolate) \ @@ -1666,8 +1666,8 @@ void TestParserSyncWithFlags(i::Handle source, isolate->counters()->runtime_call_stats(), isolate->logger(), compile_flags); scanner.Initialize(); - i::PreParser::PreParseResult result = preparser.PreParseProgram(); - CHECK_EQ(i::PreParser::kPreParseSuccess, result); + i::PreParser::PreParseResult pre_parse_result = preparser.PreParseProgram(); + CHECK_EQ(i::PreParser::kPreParseSuccess, pre_parse_result); } // Parse the data @@ -3417,7 +3417,7 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) { TEST(InnerAssignment) { i::Isolate* isolate = CcTest::i_isolate(); i::Factory* factory = isolate->factory(); - i::HandleScope scope(isolate); + i::HandleScope handle_scope(isolate); LocalContext env; const char* prefix = "function f() {"; @@ -3594,7 +3594,7 @@ TEST(InnerAssignment) { TEST(MaybeAssignedParameters) { i::Isolate* isolate = CcTest::i_isolate(); - i::HandleScope scope(isolate); + i::HandleScope handle_scope(isolate); LocalContext env; struct { @@ -9114,36 +9114,35 @@ TEST(DestructuringPositiveTests) { // clang-format on RunParserSyncTest(context_data, data, kSuccess); - - // v8:5201 - { - // clang-format off - const char* sloppy_context_data[][2] = { - {"var ", " = {};"}, - {"function f(", ") {}"}, - {"function f(argument1, ", ") {}"}, - {"var f = (", ") => {};"}, - {"var f = (argument1,", ") => {};"}, - {"try {} catch(", ") {}"}, - {nullptr, nullptr} - }; - - const char* data[] = { - "{arguments}", - "{eval}", - "{x: arguments}", - "{x: eval}", - "{arguments = false}", - "{eval = false}", - "{...arguments}", - "{...eval}", - nullptr - }; - // clang-format on - RunParserSyncTest(sloppy_context_data, data, kSuccess); - } } +// v8:5201 +TEST(SloppyContextDestructuringPositiveTests) { + // clang-format off + const char* sloppy_context_data[][2] = { + {"var ", " = {};"}, + {"function f(", ") {}"}, + {"function f(argument1, ", ") {}"}, + {"var f = (", ") => {};"}, + {"var f = (argument1,", ") => {};"}, + {"try {} catch(", ") {}"}, + {nullptr, nullptr} + }; + + const char* data[] = { + "{arguments}", + "{eval}", + "{x: arguments}", + "{x: eval}", + "{arguments = false}", + "{eval = false}", + "{...arguments}", + "{...eval}", + nullptr + }; + // clang-format on + RunParserSyncTest(sloppy_context_data, data, kSuccess); +} TEST(DestructuringNegativeTests) { { // All modes. @@ -11233,7 +11232,7 @@ TEST(ArgumentsRedeclaration) { TEST(NoPessimisticContextAllocation) { i::Isolate* isolate = CcTest::i_isolate(); i::Factory* factory = isolate->factory(); - i::HandleScope scope(isolate); + i::HandleScope handle_scope(isolate); LocalContext env; const char* prefix = "(function outer() { var my_var; ";