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 885243002: Implement parsing of ES6 Rest Parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « src/preparser.h ('k') | src/scanner.cc » ('j') | src/scanner.cc » ('J')
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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 Expect(Token::LPAREN, CHECK_OK); 871 Expect(Token::LPAREN, CHECK_OK);
872 int start_position = position(); 872 int start_position = position();
873 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 873 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
874 // We don't yet know if the function will be strict, so we cannot yet produce 874 // We don't yet know if the function will be strict, so we cannot yet produce
875 // errors for parameter names or duplicates. However, we remember the 875 // errors for parameter names or duplicates. However, we remember the
876 // locations of these errors if they occur and produce the errors later. 876 // locations of these errors if they occur and produce the errors later.
877 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); 877 Scanner::Location eval_args_error_loc = Scanner::Location::invalid();
878 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 878 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
879 Scanner::Location reserved_error_loc = Scanner::Location::invalid(); 879 Scanner::Location reserved_error_loc = Scanner::Location::invalid();
880 880
881 bool is_rest = false;
881 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || 882 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
882 (peek() == Token::RPAREN && 883 (peek() == Token::RPAREN &&
883 arity_restriction != FunctionLiteral::SETTER_ARITY); 884 arity_restriction != FunctionLiteral::SETTER_ARITY);
884 while (!done) { 885 while (!done) {
885 bool is_strict_reserved = false; 886 bool is_strict_reserved = false;
887 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params();
888 if (is_rest) {
889 Consume(Token::ELLIPSIS);
890 }
891
886 Identifier param_name = 892 Identifier param_name =
887 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 893 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
888 if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) { 894 if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) {
889 eval_args_error_loc = scanner()->location(); 895 eval_args_error_loc = scanner()->location();
890 } 896 }
891 if (!reserved_error_loc.IsValid() && is_strict_reserved) { 897 if (!reserved_error_loc.IsValid() && is_strict_reserved) {
892 reserved_error_loc = scanner()->location(); 898 reserved_error_loc = scanner()->location();
893 } 899 }
894 900
895 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1); 901 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1);
896 902
897 if (!dupe_error_loc.IsValid() && prev_value != 0) { 903 if (!dupe_error_loc.IsValid() && prev_value != 0) {
898 dupe_error_loc = scanner()->location(); 904 dupe_error_loc = scanner()->location();
899 } 905 }
900 906
901 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; 907 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
902 done = (peek() == Token::RPAREN); 908 done = (peek() == Token::RPAREN);
903 if (!done) Expect(Token::COMMA, CHECK_OK); 909 if (!done) {
910 if (is_rest) {
911 ReportMessageAt(scanner()->peek_location(), "param_after_rest");
912 *ok = false;
913 return Expression::Default();
914 }
915 Expect(Token::COMMA, CHECK_OK);
916 }
904 } 917 }
905 Expect(Token::RPAREN, CHECK_OK); 918 Expect(Token::RPAREN, CHECK_OK);
906 919
907 // See Parser::ParseFunctionLiteral for more information about lazy parsing 920 // See Parser::ParseFunctionLiteral for more information about lazy parsing
908 // and lazy compilation. 921 // and lazy compilation.
909 bool is_lazily_parsed = (outer_scope_type == SCRIPT_SCOPE && allow_lazy() && 922 bool is_lazily_parsed = (outer_scope_type == SCRIPT_SCOPE && allow_lazy() &&
910 !parenthesized_function_); 923 !parenthesized_function_);
911 parenthesized_function_ = false; 924 parenthesized_function_ = false;
912 925
913 Expect(Token::LBRACE, CHECK_OK); 926 Expect(Token::LBRACE, CHECK_OK);
914 if (is_lazily_parsed) { 927 if (is_lazily_parsed) {
915 ParseLazyFunctionLiteralBody(CHECK_OK); 928 ParseLazyFunctionLiteralBody(CHECK_OK);
916 } else { 929 } else {
917 ParseSourceElements(Token::RBRACE, ok); 930 ParseSourceElements(Token::RBRACE, ok);
918 } 931 }
919 Expect(Token::RBRACE, CHECK_OK); 932 Expect(Token::RBRACE, CHECK_OK);
920 933
921 // Validate strict mode. We can do this only after parsing the function, 934 // Validate strict mode. We can do this only after parsing the function,
922 // since the function can declare itself strict. 935 // since the function can declare itself strict.
923 // Concise methods use StrictFormalParameters. 936 // Concise methods use StrictFormalParameters.
924 if (strict_mode() == STRICT || IsConciseMethod(kind)) { 937 if (strict_mode() == STRICT || IsConciseMethod(kind) || is_rest) {
925 if (function_name.IsEvalOrArguments()) { 938 if (function_name.IsEvalOrArguments()) {
926 ReportMessageAt(function_name_location, "strict_eval_arguments"); 939 ReportMessageAt(function_name_location, "strict_eval_arguments");
927 *ok = false; 940 *ok = false;
928 return Expression::Default(); 941 return Expression::Default();
929 } 942 }
930 if (name_is_strict_reserved) { 943 if (name_is_strict_reserved) {
931 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); 944 ReportMessageAt(function_name_location, "unexpected_strict_reserved");
932 *ok = false; 945 *ok = false;
933 return Expression::Default(); 946 return Expression::Default();
934 } 947 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1040 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1028 ParseArguments(ok); 1041 ParseArguments(ok);
1029 1042
1030 return Expression::Default(); 1043 return Expression::Default();
1031 } 1044 }
1032 1045
1033 #undef CHECK_OK 1046 #undef CHECK_OK
1034 1047
1035 1048
1036 } } // v8::internal 1049 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/scanner.cc » ('j') | src/scanner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698