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

Side by Side Diff: src/preparser.cc

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