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

Side by Side Diff: src/preparser.cc

Issue 1105453002: Revert of [strong] checking of this & super in constructors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@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
« 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 int start_position = peek_position(); 116 int start_position = peek_position();
117 ParseLazyFunctionLiteralBody(&ok); 117 ParseLazyFunctionLiteralBody(&ok);
118 if (stack_overflow()) return kPreParseStackOverflow; 118 if (stack_overflow()) return kPreParseStackOverflow;
119 if (!ok) { 119 if (!ok) {
120 ReportUnexpectedToken(scanner()->current_token()); 120 ReportUnexpectedToken(scanner()->current_token());
121 } else { 121 } else {
122 DCHECK_EQ(Token::RBRACE, scanner()->peek()); 122 DCHECK_EQ(Token::RBRACE, scanner()->peek());
123 if (is_strict(scope_->language_mode())) { 123 if (is_strict(scope_->language_mode())) {
124 int end_pos = scanner()->location().end_pos; 124 int end_pos = scanner()->location().end_pos;
125 CheckStrictOctalLiteral(start_position, end_pos, &ok); 125 CheckStrictOctalLiteral(start_position, end_pos, &ok);
126 if (!ok) return kPreParseSuccess;
127
128 if (is_strong(scope_->language_mode()) && IsSubclassConstructor(kind)) {
129 if (!function_state.super_location().IsValid()) {
130 ReportMessageAt(Scanner::Location(start_position, start_position + 1),
131 "strong_super_call_missing", kReferenceError);
132 return kPreParseSuccess;
133 }
134 }
135 } 126 }
136 } 127 }
137 return kPreParseSuccess; 128 return kPreParseSuccess;
138 } 129 }
139 130
140 131
141 PreParserExpression PreParserTraits::ParseClassLiteral( 132 PreParserExpression PreParserTraits::ParseClassLiteral(
142 PreParserIdentifier name, Scanner::Location class_name_location, 133 PreParserIdentifier name, Scanner::Location class_name_location,
143 bool name_is_strict_reserved, int pos, bool* ok) { 134 bool name_is_strict_reserved, int pos, bool* ok) {
144 return pre_parser_->ParseClassLiteral(name, class_name_location, 135 return pre_parser_->ParseClassLiteral(name, class_name_location,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 189
199 void PreParser::ParseStatementList(int end_token, bool* ok) { 190 void PreParser::ParseStatementList(int end_token, bool* ok) {
200 // SourceElements :: 191 // SourceElements ::
201 // (Statement)* <end_token> 192 // (Statement)* <end_token>
202 193
203 bool directive_prologue = true; 194 bool directive_prologue = true;
204 while (peek() != end_token) { 195 while (peek() != end_token) {
205 if (directive_prologue && peek() != Token::STRING) { 196 if (directive_prologue && peek() != Token::STRING) {
206 directive_prologue = false; 197 directive_prologue = false;
207 } 198 }
208 Scanner::Location token_loc = scanner()->peek_location(); 199 Token::Value token = peek();
209 Scanner::Location old_this_loc = function_state_->this_location(); 200 Scanner::Location old_super_loc = function_state_->super_call_location();
210 Scanner::Location old_super_loc = function_state_->super_location();
211 Statement statement = ParseStatementListItem(ok); 201 Statement statement = ParseStatementListItem(ok);
212 if (!*ok) return; 202 if (!*ok) return;
213 203 Scanner::Location super_loc = function_state_->super_call_location();
214 if (is_strong(language_mode()) && 204 if (is_strong(language_mode()) &&
215 scope_->is_function_scope() && 205 i::IsConstructor(function_state_->kind()) &&
216 i::IsConstructor(function_state_->kind())) { 206 !old_super_loc.IsValid() && super_loc.IsValid() &&
217 Scanner::Location this_loc = function_state_->this_location(); 207 token != Token::SUPER) {
218 Scanner::Location super_loc = function_state_->super_location(); 208 ReportMessageAt(super_loc, "strong_super_call_nested");
219 if (this_loc.beg_pos != old_this_loc.beg_pos && 209 *ok = false;
220 this_loc.beg_pos != token_loc.beg_pos) { 210 return;
221 ReportMessageAt(this_loc, "strong_constructor_this");
222 *ok = false;
223 return;
224 }
225 if (super_loc.beg_pos != old_super_loc.beg_pos &&
226 super_loc.beg_pos != token_loc.beg_pos) {
227 ReportMessageAt(super_loc, "strong_constructor_super");
228 *ok = false;
229 return;
230 }
231 } 211 }
232
233 if (directive_prologue) { 212 if (directive_prologue) {
234 if (statement.IsUseStrictLiteral()) { 213 if (statement.IsUseStrictLiteral()) {
235 scope_->SetLanguageMode( 214 scope_->SetLanguageMode(
236 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); 215 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT));
237 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { 216 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) {
238 scope_->SetLanguageMode(static_cast<LanguageMode>( 217 scope_->SetLanguageMode(static_cast<LanguageMode>(
239 scope_->language_mode() | STRICT_BIT | STRONG_BIT)); 218 scope_->language_mode() | STRICT_BIT | STRONG_BIT));
240 } else if (!statement.IsStringLiteral()) { 219 } else if (!statement.IsStringLiteral()) {
241 directive_prologue = false; 220 directive_prologue = false;
242 } 221 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 525
547 switch (peek()) { 526 switch (peek()) {
548 case Token::FUNCTION: 527 case Token::FUNCTION:
549 case Token::LBRACE: 528 case Token::LBRACE:
550 UNREACHABLE(); // Always handled by the callers. 529 UNREACHABLE(); // Always handled by the callers.
551 case Token::CLASS: 530 case Token::CLASS:
552 ReportUnexpectedToken(Next()); 531 ReportUnexpectedToken(Next());
553 *ok = false; 532 *ok = false;
554 return Statement::Default(); 533 return Statement::Default();
555 534
556 case Token::THIS:
557 case Token::SUPER:
558 if (is_strong(language_mode()) &&
559 i::IsConstructor(function_state_->kind())) {
560 bool is_this = peek() == Token::THIS;
561 Expression expr = Expression::Default();
562 if (is_this) {
563 expr = ParseStrongInitializationExpression(CHECK_OK);
564 } else {
565 expr = ParseStrongSuperCallExpression(CHECK_OK);
566 }
567 switch (peek()) {
568 case Token::SEMICOLON:
569 Consume(Token::SEMICOLON);
570 break;
571 case Token::RBRACE:
572 case Token::EOS:
573 break;
574 default:
575 if (!scanner()->HasAnyLineTerminatorBeforeNext()) {
576 ReportMessageAt(function_state_->this_location(),
577 is_this ? "strong_constructor_this"
578 : "strong_constructor_super");
579 *ok = false;
580 return Statement::Default();
581 }
582 }
583 return Statement::ExpressionStatement(expr);
584 }
585 break;
586
587 // TODO(arv): Handle `let [` 535 // TODO(arv): Handle `let [`
588 // https://code.google.com/p/v8/issues/detail?id=3847 536 // https://code.google.com/p/v8/issues/detail?id=3847
589 537
590 default: 538 default:
591 break; 539 break;
592 } 540 }
593 541
594 bool starts_with_identifier = peek_any_identifier(); 542 bool starts_with_identifier = peek_any_identifier();
595 Expression expr = ParseExpression(true, CHECK_OK); 543 Expression expr = ParseExpression(true, CHECK_OK);
596 // Even if the expression starts with an identifier, it is not necessarily an 544 // Even if the expression starts with an identifier, it is not necessarily an
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 const bool use_strict_params = is_rest || IsConciseMethod(kind); 965 const bool use_strict_params = is_rest || IsConciseMethod(kind);
1018 CheckFunctionParameterNames(language_mode(), use_strict_params, error_locs, 966 CheckFunctionParameterNames(language_mode(), use_strict_params, error_locs,
1019 CHECK_OK); 967 CHECK_OK);
1020 968
1021 if (is_strict(language_mode())) { 969 if (is_strict(language_mode())) {
1022 int end_position = scanner()->location().end_pos; 970 int end_position = scanner()->location().end_pos;
1023 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 971 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
1024 } 972 }
1025 973
1026 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { 974 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
1027 if (!function_state.super_location().IsValid()) { 975 if (!function_state.super_call_location().IsValid()) {
1028 ReportMessageAt(function_name_location, "strong_super_call_missing", 976 ReportMessageAt(function_name_location, "strong_super_call_missing",
1029 kReferenceError); 977 kReferenceError);
1030 *ok = false; 978 *ok = false;
1031 return Expression::Default(); 979 return Expression::Default();
1032 } 980 }
1033 } 981 }
1034 982
1035 return Expression::Default(); 983 return Expression::Default();
1036 } 984 }
1037 985
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 1067
1120 DCHECK(!spread_pos.IsValid()); 1068 DCHECK(!spread_pos.IsValid());
1121 1069
1122 return Expression::Default(); 1070 return Expression::Default();
1123 } 1071 }
1124 1072
1125 #undef CHECK_OK 1073 #undef CHECK_OK
1126 1074
1127 1075
1128 } } // v8::internal 1076 } } // 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