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

Side by Side Diff: src/preparser.cc

Issue 1083623002: Refactor formal parameter error locations into a class (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 8 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
« src/preparser.h ('K') | « src/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { 901 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) {
902 // Function :: 902 // Function ::
903 // '(' FormalParameterList? ')' '{' FunctionBody '}' 903 // '(' FormalParameterList? ')' '{' FunctionBody '}'
904 904
905 // Parse function body. 905 // Parse function body.
906 bool outer_is_script_scope = scope_->is_script_scope(); 906 bool outer_is_script_scope = scope_->is_script_scope();
907 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE); 907 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE);
908 PreParserFactory factory(NULL); 908 PreParserFactory factory(NULL);
909 FunctionState function_state(&function_state_, &scope_, function_scope, kind, 909 FunctionState function_state(&function_state_, &scope_, function_scope, kind,
910 &factory); 910 &factory);
911 // We don't yet know if the function will be strict, so we cannot yet produce 911 FormalParameterErrorLocations error_locs;
912 // errors for parameter names or duplicates. However, we remember the
913 // locations of these errors if they occur and produce the errors later.
914 Scanner::Location eval_args_loc = Scanner::Location::invalid();
915 Scanner::Location dupe_loc = Scanner::Location::invalid();
916 Scanner::Location reserved_loc = Scanner::Location::invalid();
917
918 // Similarly for strong mode.
919 Scanner::Location undefined_loc = Scanner::Location::invalid();
920 912
921 bool is_rest = false; 913 bool is_rest = false;
922 Expect(Token::LPAREN, CHECK_OK); 914 Expect(Token::LPAREN, CHECK_OK);
923 int start_position = scanner()->location().beg_pos; 915 int start_position = scanner()->location().beg_pos;
924 PreParserFormalParameterList params = 916 PreParserFormalParameterList params =
925 ParseFormalParameterList(&eval_args_loc, &undefined_loc, &dupe_loc, 917 ParseFormalParameterList(&error_locs, &is_rest, CHECK_OK);
926 &reserved_loc, &is_rest, CHECK_OK);
927 Expect(Token::RPAREN, CHECK_OK); 918 Expect(Token::RPAREN, CHECK_OK);
928 int formals_end_position = scanner()->location().end_pos; 919 int formals_end_position = scanner()->location().end_pos;
929 920
930 CheckArityRestrictions(params->length(), arity_restriction, start_position, 921 CheckArityRestrictions(params->length(), arity_restriction, start_position,
931 formals_end_position, ok); 922 formals_end_position, ok);
932 if (!*ok) return Expression::Default(); 923 if (!*ok) return Expression::Default();
933 924
934 // See Parser::ParseFunctionLiteral for more information about lazy parsing 925 // See Parser::ParseFunctionLiteral for more information about lazy parsing
935 // and lazy compilation. 926 // and lazy compilation.
936 bool is_lazily_parsed = 927 bool is_lazily_parsed =
937 (outer_is_script_scope && allow_lazy() && !parenthesized_function_); 928 (outer_is_script_scope && allow_lazy() && !parenthesized_function_);
938 parenthesized_function_ = false; 929 parenthesized_function_ = false;
939 930
940 Expect(Token::LBRACE, CHECK_OK); 931 Expect(Token::LBRACE, CHECK_OK);
941 if (is_lazily_parsed) { 932 if (is_lazily_parsed) {
942 ParseLazyFunctionLiteralBody(CHECK_OK); 933 ParseLazyFunctionLiteralBody(CHECK_OK);
943 } else { 934 } else {
944 ParseStatementList(Token::RBRACE, CHECK_OK); 935 ParseStatementList(Token::RBRACE, CHECK_OK);
945 } 936 }
946 Expect(Token::RBRACE, CHECK_OK); 937 Expect(Token::RBRACE, CHECK_OK);
947 938
948 // Validate name and parameter names. We can do this only after parsing the 939 // Validate name and parameter names. We can do this only after parsing the
949 // function, since the function can declare itself strict. 940 // function, since the function can declare itself strict.
950 CheckFunctionName(language_mode(), kind, function_name, 941 CheckFunctionName(language_mode(), kind, function_name,
951 name_is_strict_reserved, function_name_location, CHECK_OK); 942 name_is_strict_reserved, function_name_location, CHECK_OK);
952 const bool use_strict_params = is_rest || IsConciseMethod(kind); 943 const bool use_strict_params = is_rest || IsConciseMethod(kind);
953 CheckFunctionParameterNames(language_mode(), use_strict_params, eval_args_loc, 944 CheckFunctionParameterNames(language_mode(), use_strict_params, error_locs,
954 undefined_loc, dupe_loc, reserved_loc, CHECK_OK); 945 CHECK_OK);
955 946
956 if (is_strict(language_mode())) { 947 if (is_strict(language_mode())) {
957 int end_position = scanner()->location().end_pos; 948 int end_position = scanner()->location().end_pos;
958 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 949 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
959 } 950 }
960 951
961 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { 952 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
962 if (!function_state.super_call_location().IsValid()) { 953 if (!function_state.super_call_location().IsValid()) {
963 ReportMessageAt(function_name_location, "strong_super_call_missing", 954 ReportMessageAt(function_name_location, "strong_super_call_missing",
964 kReferenceError); 955 kReferenceError);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 1045
1055 DCHECK(!spread_pos.IsValid()); 1046 DCHECK(!spread_pos.IsValid());
1056 1047
1057 return Expression::Default(); 1048 return Expression::Default();
1058 } 1049 }
1059 1050
1060 #undef CHECK_OK 1051 #undef CHECK_OK
1061 1052
1062 1053
1063 } } // v8::internal 1054 } } // v8::internal
OLDNEW
« src/preparser.h ('K') | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698