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

Side by Side Diff: src/preparser.cc

Issue 1060883004: [strong] Implement static restrictions on binding 'undefined' in arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: linebreak 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
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | 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 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // FormalParameterList :: 911 // FormalParameterList ::
912 // '(' (Identifier)*[','] ')' 912 // '(' (Identifier)*[','] ')'
913 Expect(Token::LPAREN, CHECK_OK); 913 Expect(Token::LPAREN, CHECK_OK);
914 int start_position = position(); 914 int start_position = position();
915 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 915 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
916 // We don't yet know if the function will be strict, so we cannot yet produce 916 // We don't yet know if the function will be strict, so we cannot yet produce
917 // errors for parameter names or duplicates. However, we remember the 917 // errors for parameter names or duplicates. However, we remember the
918 // locations of these errors if they occur and produce the errors later. 918 // locations of these errors if they occur and produce the errors later.
919 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); 919 Scanner::Location eval_args_loc = Scanner::Location::invalid();
920 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 920 Scanner::Location dupe_loc = Scanner::Location::invalid();
921 Scanner::Location reserved_error_loc = Scanner::Location::invalid(); 921 Scanner::Location reserved_loc = Scanner::Location::invalid();
922 922
923 // Similarly for strong mode. 923 // Similarly for strong mode.
924 Scanner::Location undefined_error_loc = Scanner::Location::invalid(); 924 Scanner::Location undefined_loc = Scanner::Location::invalid();
925 925
926 bool is_rest = false; 926 bool is_rest = false;
927 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || 927 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
928 (peek() == Token::RPAREN && 928 (peek() == Token::RPAREN &&
929 arity_restriction != FunctionLiteral::SETTER_ARITY); 929 arity_restriction != FunctionLiteral::SETTER_ARITY);
930 while (!done) { 930 while (!done) {
931 bool is_strict_reserved = false; 931 bool is_strict_reserved = false;
932 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); 932 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params();
933 if (is_rest) { 933 if (is_rest) {
934 Consume(Token::ELLIPSIS); 934 Consume(Token::ELLIPSIS);
935 } 935 }
936 936
937 Identifier param_name = 937 Identifier param_name =
938 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 938 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
939 if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) { 939 if (!eval_args_loc.IsValid() && param_name.IsEvalOrArguments()) {
940 eval_args_error_loc = scanner()->location(); 940 eval_args_loc = scanner()->location();
941 } 941 }
942 if (!undefined_error_loc.IsValid() && param_name.IsUndefined()) { 942 if (!undefined_loc.IsValid() && param_name.IsUndefined()) {
943 undefined_error_loc = scanner()->location(); 943 undefined_loc = scanner()->location();
944 } 944 }
945 if (!reserved_error_loc.IsValid() && is_strict_reserved) { 945 if (!reserved_loc.IsValid() && is_strict_reserved) {
946 reserved_error_loc = scanner()->location(); 946 reserved_loc = scanner()->location();
947 } 947 }
948 948
949 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1); 949 int prev_value = scanner()->FindSymbol(&duplicate_finder, 1);
950 950
951 if (!dupe_error_loc.IsValid() && prev_value != 0) { 951 if (!dupe_loc.IsValid() && prev_value != 0) {
952 dupe_error_loc = scanner()->location(); 952 dupe_loc = scanner()->location();
953 } 953 }
954 954
955 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; 955 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
956 done = (peek() == Token::RPAREN); 956 done = (peek() == Token::RPAREN);
957 if (!done) { 957 if (!done) {
958 if (is_rest) { 958 if (is_rest) {
959 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); 959 ReportMessageAt(scanner()->peek_location(), "param_after_rest");
960 *ok = false; 960 *ok = false;
961 return Expression::Default(); 961 return Expression::Default();
962 } 962 }
(...skipping 14 matching lines...) Expand all
977 } else { 977 } else {
978 ParseStatementList(Token::RBRACE, CHECK_OK); 978 ParseStatementList(Token::RBRACE, CHECK_OK);
979 } 979 }
980 Expect(Token::RBRACE, CHECK_OK); 980 Expect(Token::RBRACE, CHECK_OK);
981 981
982 // Validate name and parameter names. We can do this only after parsing the 982 // Validate name and parameter names. We can do this only after parsing the
983 // function, since the function can declare itself strict. 983 // function, since the function can declare itself strict.
984 CheckFunctionName(language_mode(), kind, function_name, 984 CheckFunctionName(language_mode(), kind, function_name,
985 name_is_strict_reserved, function_name_location, CHECK_OK); 985 name_is_strict_reserved, function_name_location, CHECK_OK);
986 const bool use_strict_params = is_rest || IsConciseMethod(kind); 986 const bool use_strict_params = is_rest || IsConciseMethod(kind);
987 CheckFunctionParameterNames(language_mode(), use_strict_params, 987 CheckFunctionParameterNames(language_mode(), use_strict_params, eval_args_loc,
988 eval_args_error_loc, undefined_error_loc, 988 undefined_loc, dupe_loc, reserved_loc, CHECK_OK);
989 dupe_error_loc, reserved_error_loc, CHECK_OK);
990 989
991 if (is_strict(language_mode())) { 990 if (is_strict(language_mode())) {
992 int end_position = scanner()->location().end_pos; 991 int end_position = scanner()->location().end_pos;
993 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 992 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
994 } 993 }
995 994
996 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { 995 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
997 if (!function_state.super_call_location().IsValid()) { 996 if (!function_state.super_call_location().IsValid()) {
998 ReportMessageAt(function_name_location, "strong_super_call_missing", 997 ReportMessageAt(function_name_location, "strong_super_call_missing",
999 kReferenceError); 998 kReferenceError);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1088
1090 DCHECK(!spread_pos.IsValid()); 1089 DCHECK(!spread_pos.IsValid());
1091 1090
1092 return Expression::Default(); 1091 return Expression::Default();
1093 } 1092 }
1094 1093
1095 #undef CHECK_OK 1094 #undef CHECK_OK
1096 1095
1097 1096
1098 } } // v8::internal 1097 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698