Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: src/preparser.cc

Issue 1138153003: Use ExpressionClassifier to identify valid arrow function formals (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Fix ASAN stack-check regression by bumping stack limit in test Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { 1017 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) {
1018 // Function :: 1018 // Function ::
1019 // '(' FormalParameterList? ')' '{' FunctionBody '}' 1019 // '(' FormalParameterList? ')' '{' FunctionBody '}'
1020 1020
1021 // Parse function body. 1021 // Parse function body.
1022 bool outer_is_script_scope = scope_->is_script_scope(); 1022 bool outer_is_script_scope = scope_->is_script_scope();
1023 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); 1023 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE);
1024 PreParserFactory factory(NULL); 1024 PreParserFactory factory(NULL);
1025 FunctionState function_state(&function_state_, &scope_, function_scope, kind, 1025 FunctionState function_state(&function_state_, &scope_, function_scope, kind,
1026 &factory); 1026 &factory);
1027 FormalParameterErrorLocations error_locs; 1027 ExpressionClassifier formals_classifier;
1028 1028
1029 bool is_rest = false; 1029 bool is_rest = false;
1030 Expect(Token::LPAREN, CHECK_OK); 1030 Expect(Token::LPAREN, CHECK_OK);
1031 int start_position = scanner()->location().beg_pos; 1031 int start_position = scanner()->location().beg_pos;
1032 function_scope->set_start_position(start_position); 1032 function_scope->set_start_position(start_position);
1033 int num_parameters; 1033 int num_parameters;
1034 { 1034 {
1035 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 1035 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
1036 num_parameters = ParseFormalParameterList(&duplicate_finder, &error_locs, 1036 num_parameters = ParseFormalParameterList(&duplicate_finder, &is_rest,
1037 &is_rest, CHECK_OK); 1037 &formals_classifier, CHECK_OK);
1038 } 1038 }
1039 Expect(Token::RPAREN, CHECK_OK); 1039 Expect(Token::RPAREN, CHECK_OK);
1040 int formals_end_position = scanner()->location().end_pos; 1040 int formals_end_position = scanner()->location().end_pos;
1041 1041
1042 CheckArityRestrictions(num_parameters, arity_restriction, start_position, 1042 CheckArityRestrictions(num_parameters, arity_restriction, start_position,
1043 formals_end_position, CHECK_OK); 1043 formals_end_position, CHECK_OK);
1044 1044
1045 // See Parser::ParseFunctionLiteral for more information about lazy parsing 1045 // See Parser::ParseFunctionLiteral for more information about lazy parsing
1046 // and lazy compilation. 1046 // and lazy compilation.
1047 bool is_lazily_parsed = 1047 bool is_lazily_parsed =
1048 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); 1048 (outer_is_script_scope && allow_lazy() && !parenthesized_function_);
1049 parenthesized_function_ = false; 1049 parenthesized_function_ = false;
1050 1050
1051 Expect(Token::LBRACE, CHECK_OK); 1051 Expect(Token::LBRACE, CHECK_OK);
1052 if (is_lazily_parsed) { 1052 if (is_lazily_parsed) {
1053 ParseLazyFunctionLiteralBody(CHECK_OK); 1053 ParseLazyFunctionLiteralBody(CHECK_OK);
1054 } else { 1054 } else {
1055 ParseStatementList(Token::RBRACE, CHECK_OK); 1055 ParseStatementList(Token::RBRACE, CHECK_OK);
1056 } 1056 }
1057 Expect(Token::RBRACE, CHECK_OK); 1057 Expect(Token::RBRACE, CHECK_OK);
1058 1058
1059 // Validate name and parameter names. We can do this only after parsing the 1059 // Validate name and parameter names. We can do this only after parsing the
1060 // function, since the function can declare itself strict. 1060 // function, since the function can declare itself strict.
1061 CheckFunctionName(language_mode(), kind, function_name, 1061 CheckFunctionName(language_mode(), kind, function_name,
1062 name_is_strict_reserved, function_name_location, CHECK_OK); 1062 name_is_strict_reserved, function_name_location, CHECK_OK);
1063 const bool use_strict_params = is_rest || IsConciseMethod(kind); 1063 const bool strict_formal_parameters = is_rest || IsConciseMethod(kind);
1064 CheckFunctionParameterNames(language_mode(), use_strict_params, error_locs, 1064 const bool allow_duplicate_parameters =
1065 CHECK_OK); 1065 is_sloppy(language_mode()) && !strict_formal_parameters;
1066 ValidateFormalParameters(&formals_classifier, language_mode(),
1067 allow_duplicate_parameters, CHECK_OK);
1066 1068
1067 if (is_strict(language_mode())) { 1069 if (is_strict(language_mode())) {
1068 int end_position = scanner()->location().end_pos; 1070 int end_position = scanner()->location().end_pos;
1069 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 1071 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
1070 } 1072 }
1071 1073
1072 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { 1074 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
1073 if (!function_state.super_location().IsValid()) { 1075 if (!function_state.super_location().IsValid()) {
1074 ReportMessageAt(function_name_location, "strong_super_call_missing", 1076 ReportMessageAt(function_name_location, "strong_super_call_missing",
1075 kReferenceError); 1077 kReferenceError);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 1176
1175 DCHECK(!spread_pos.IsValid()); 1177 DCHECK(!spread_pos.IsValid());
1176 1178
1177 return Expression::Default(); 1179 return Expression::Default();
1178 } 1180 }
1179 1181
1180 #undef CHECK_OK 1182 #undef CHECK_OK
1181 1183
1182 1184
1183 } } // v8::internal 1185 } } // v8::internal
OLDNEW
« src/parser.cc ('K') | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698