OLD | NEW |
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 void PreParser::ParseStatementList(int end_token, bool* ok) { | 187 void PreParser::ParseStatementList(int end_token, bool* ok) { |
188 // SourceElements :: | 188 // SourceElements :: |
189 // (Statement)* <end_token> | 189 // (Statement)* <end_token> |
190 | 190 |
191 bool directive_prologue = true; | 191 bool directive_prologue = true; |
192 while (peek() != end_token) { | 192 while (peek() != end_token) { |
193 if (directive_prologue && peek() != Token::STRING) { | 193 if (directive_prologue && peek() != Token::STRING) { |
194 directive_prologue = false; | 194 directive_prologue = false; |
195 } | 195 } |
196 Token::Value token = peek(); | 196 Scanner::Location token_loc = scanner()->peek_location(); |
197 Scanner::Location old_super_loc = function_state_->super_call_location(); | 197 Scanner::Location old_this_loc = function_state_->this_location(); |
| 198 Scanner::Location old_super_loc = function_state_->super_location(); |
198 Statement statement = ParseStatementListItem(ok); | 199 Statement statement = ParseStatementListItem(ok); |
199 if (!*ok) return; | 200 if (!*ok) return; |
200 Scanner::Location super_loc = function_state_->super_call_location(); | 201 |
201 if (is_strong(language_mode()) && | 202 if (is_strong(language_mode()) && |
202 i::IsConstructor(function_state_->kind()) && | 203 scope_->is_function_scope() && |
203 !old_super_loc.IsValid() && super_loc.IsValid() && | 204 i::IsConstructor(function_state_->kind())) { |
204 token != Token::SUPER) { | 205 Scanner::Location this_loc = function_state_->this_location(); |
205 ReportMessageAt(super_loc, "strong_super_call_nested"); | 206 Scanner::Location super_loc = function_state_->super_location(); |
206 *ok = false; | 207 if (this_loc.beg_pos != old_this_loc.beg_pos && |
207 return; | 208 this_loc.beg_pos != token_loc.beg_pos) { |
| 209 ReportMessageAt(this_loc, "strong_constructor_this"); |
| 210 *ok = false; |
| 211 return; |
| 212 } |
| 213 if (super_loc.beg_pos != old_super_loc.beg_pos && |
| 214 super_loc.beg_pos != token_loc.beg_pos) { |
| 215 ReportMessageAt(super_loc, "strong_constructor_super"); |
| 216 *ok = false; |
| 217 return; |
| 218 } |
208 } | 219 } |
| 220 |
209 if (directive_prologue) { | 221 if (directive_prologue) { |
210 if (statement.IsUseStrictLiteral()) { | 222 if (statement.IsUseStrictLiteral()) { |
211 scope_->SetLanguageMode( | 223 scope_->SetLanguageMode( |
212 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); | 224 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
213 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { | 225 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { |
214 scope_->SetLanguageMode(static_cast<LanguageMode>( | 226 scope_->SetLanguageMode(static_cast<LanguageMode>( |
215 scope_->language_mode() | STRICT_BIT | STRONG_BIT)); | 227 scope_->language_mode() | STRICT_BIT | STRONG_BIT)); |
216 } else if (!statement.IsStringLiteral()) { | 228 } else if (!statement.IsStringLiteral()) { |
217 directive_prologue = false; | 229 directive_prologue = false; |
218 } | 230 } |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 | 520 |
509 switch (peek()) { | 521 switch (peek()) { |
510 case Token::FUNCTION: | 522 case Token::FUNCTION: |
511 case Token::LBRACE: | 523 case Token::LBRACE: |
512 UNREACHABLE(); // Always handled by the callers. | 524 UNREACHABLE(); // Always handled by the callers. |
513 case Token::CLASS: | 525 case Token::CLASS: |
514 ReportUnexpectedToken(Next()); | 526 ReportUnexpectedToken(Next()); |
515 *ok = false; | 527 *ok = false; |
516 return Statement::Default(); | 528 return Statement::Default(); |
517 | 529 |
| 530 case Token::THIS: |
| 531 case Token::SUPER: |
| 532 if (is_strong(language_mode()) && |
| 533 i::IsConstructor(function_state_->kind())) { |
| 534 bool is_this = peek() == Token::THIS; |
| 535 Expression expr = Expression::Default(); |
| 536 if (is_this) { |
| 537 expr = ParseStrongInitializationExpression(CHECK_OK); |
| 538 } else { |
| 539 expr = ParseStrongSuperCallExpression(CHECK_OK); |
| 540 } |
| 541 switch (peek()) { |
| 542 case Token::SEMICOLON: |
| 543 Consume(Token::SEMICOLON); |
| 544 break; |
| 545 case Token::RBRACE: |
| 546 case Token::EOS: |
| 547 break; |
| 548 default: |
| 549 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { |
| 550 ReportMessageAt(function_state_->this_location(), |
| 551 is_this ? "strong_constructor_this" |
| 552 : "strong_constructor_super"); |
| 553 *ok = false; |
| 554 return Statement::Default(); |
| 555 } |
| 556 } |
| 557 return Statement::ExpressionStatement(expr); |
| 558 } |
| 559 break; |
| 560 |
518 // TODO(arv): Handle `let [` | 561 // TODO(arv): Handle `let [` |
519 // https://code.google.com/p/v8/issues/detail?id=3847 | 562 // https://code.google.com/p/v8/issues/detail?id=3847 |
520 | 563 |
521 default: | 564 default: |
522 break; | 565 break; |
523 } | 566 } |
524 | 567 |
525 bool starts_with_identifier = peek_any_identifier(); | 568 bool starts_with_identifier = peek_any_identifier(); |
526 Expression expr = ParseExpression(true, CHECK_OK); | 569 Expression expr = ParseExpression(true, CHECK_OK); |
527 // Even if the expression starts with an identifier, it is not necessarily an | 570 // Even if the expression starts with an identifier, it is not necessarily an |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 CheckFunctionParameterNames(language_mode(), use_strict_params, | 995 CheckFunctionParameterNames(language_mode(), use_strict_params, |
953 eval_args_error_loc, dupe_error_loc, | 996 eval_args_error_loc, dupe_error_loc, |
954 reserved_error_loc, CHECK_OK); | 997 reserved_error_loc, CHECK_OK); |
955 | 998 |
956 if (is_strict(language_mode())) { | 999 if (is_strict(language_mode())) { |
957 int end_position = scanner()->location().end_pos; | 1000 int end_position = scanner()->location().end_pos; |
958 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 1001 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
959 } | 1002 } |
960 | 1003 |
961 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { | 1004 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { |
962 if (!function_state.super_call_location().IsValid()) { | 1005 if (!function_state.super_location().IsValid()) { |
963 ReportMessageAt(function_name_location, "strong_super_call_missing", | 1006 ReportMessageAt(function_name_location, "strong_super_call_missing", |
964 kReferenceError); | 1007 kReferenceError); |
965 *ok = false; | 1008 *ok = false; |
966 return Expression::Default(); | 1009 return Expression::Default(); |
967 } | 1010 } |
968 } | 1011 } |
969 | 1012 |
970 return Expression::Default(); | 1013 return Expression::Default(); |
971 } | 1014 } |
972 | 1015 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 1088 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
1046 ParseArguments(ok); | 1089 ParseArguments(ok); |
1047 | 1090 |
1048 return Expression::Default(); | 1091 return Expression::Default(); |
1049 } | 1092 } |
1050 | 1093 |
1051 #undef CHECK_OK | 1094 #undef CHECK_OK |
1052 | 1095 |
1053 | 1096 |
1054 } } // v8::internal | 1097 } } // v8::internal |
OLD | NEW |