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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 if (directive_prologue && peek() != Token::STRING) { | 225 if (directive_prologue && peek() != Token::STRING) { |
226 directive_prologue = false; | 226 directive_prologue = false; |
227 } | 227 } |
228 bool starts_with_identifier = peek() == Token::IDENTIFIER; | 228 bool starts_with_identifier = peek() == Token::IDENTIFIER; |
229 Scanner::Location token_loc = scanner()->peek_location(); | 229 Scanner::Location token_loc = scanner()->peek_location(); |
230 Scanner::Location old_this_loc = function_state_->this_location(); | 230 Scanner::Location old_this_loc = function_state_->this_location(); |
231 Scanner::Location old_super_loc = function_state_->super_location(); | 231 Scanner::Location old_super_loc = function_state_->super_location(); |
232 Statement statement = ParseStatementListItem(ok); | 232 Statement statement = ParseStatementListItem(ok); |
233 if (!*ok) return; | 233 if (!*ok) return; |
234 | 234 |
235 if (is_strong(language_mode()) && | 235 if (is_strong(language_mode()) && scope_->is_function_scope() && |
236 scope_->is_function_scope() && | 236 IsClassConstructor(function_state_->kind())) { |
237 i::IsConstructor(function_state_->kind())) { | |
238 Scanner::Location this_loc = function_state_->this_location(); | 237 Scanner::Location this_loc = function_state_->this_location(); |
239 Scanner::Location super_loc = function_state_->super_location(); | 238 Scanner::Location super_loc = function_state_->super_location(); |
240 if (this_loc.beg_pos != old_this_loc.beg_pos && | 239 if (this_loc.beg_pos != old_this_loc.beg_pos && |
241 this_loc.beg_pos != token_loc.beg_pos) { | 240 this_loc.beg_pos != token_loc.beg_pos) { |
242 ReportMessageAt(this_loc, MessageTemplate::kStrongConstructorThis); | 241 ReportMessageAt(this_loc, MessageTemplate::kStrongConstructorThis); |
243 *ok = false; | 242 *ok = false; |
244 return; | 243 return; |
245 } | 244 } |
246 if (super_loc.beg_pos != old_super_loc.beg_pos && | 245 if (super_loc.beg_pos != old_super_loc.beg_pos && |
247 super_loc.beg_pos != token_loc.beg_pos) { | 246 super_loc.beg_pos != token_loc.beg_pos) { |
248 ReportMessageAt(super_loc, MessageTemplate::kStrongConstructorSuper); | 247 ReportMessageAt(super_loc, MessageTemplate::kStrongConstructorSuper); |
249 *ok = false; | 248 *ok = false; |
250 return; | 249 return; |
251 } | 250 } |
252 } | 251 } |
253 | 252 |
254 if (directive_prologue) { | 253 if (directive_prologue) { |
255 bool use_strict_found = statement.IsUseStrictLiteral(); | 254 bool use_strict_found = statement.IsUseStrictLiteral(); |
256 bool use_strong_found = | 255 bool use_strong_found = |
257 statement.IsUseStrongLiteral() && allow_strong_mode(); | 256 statement.IsUseStrongLiteral() && allow_strong_mode(); |
258 | 257 |
259 if (use_strict_found) { | 258 if (use_strict_found) { |
260 scope_->SetLanguageMode( | 259 scope_->SetLanguageMode( |
261 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); | 260 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); |
262 } else if (use_strong_found) { | 261 } else if (use_strong_found) { |
263 scope_->SetLanguageMode(static_cast<LanguageMode>( | 262 scope_->SetLanguageMode(static_cast<LanguageMode>( |
264 scope_->language_mode() | STRONG)); | 263 scope_->language_mode() | STRONG)); |
265 if (i::IsConstructor(function_state_->kind())) { | 264 if (IsClassConstructor(function_state_->kind())) { |
266 // "use strong" cannot occur in a class constructor body, to avoid | 265 // "use strong" cannot occur in a class constructor body, to avoid |
267 // unintuitive strong class object semantics. | 266 // unintuitive strong class object semantics. |
268 PreParserTraits::ReportMessageAt( | 267 PreParserTraits::ReportMessageAt( |
269 token_loc, MessageTemplate::kStrongConstructorDirective); | 268 token_loc, MessageTemplate::kStrongConstructorDirective); |
270 *ok = false; | 269 *ok = false; |
271 return; | 270 return; |
272 } | 271 } |
273 } else if (!statement.IsStringLiteral()) { | 272 } else if (!statement.IsStringLiteral()) { |
274 directive_prologue = false; | 273 directive_prologue = false; |
275 } | 274 } |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 case Token::CLASS: | 631 case Token::CLASS: |
633 ReportUnexpectedToken(Next()); | 632 ReportUnexpectedToken(Next()); |
634 *ok = false; | 633 *ok = false; |
635 return Statement::Default(); | 634 return Statement::Default(); |
636 | 635 |
637 case Token::THIS: | 636 case Token::THIS: |
638 if (!FLAG_strong_this) break; | 637 if (!FLAG_strong_this) break; |
639 // Fall through. | 638 // Fall through. |
640 case Token::SUPER: | 639 case Token::SUPER: |
641 if (is_strong(language_mode()) && | 640 if (is_strong(language_mode()) && |
642 i::IsConstructor(function_state_->kind())) { | 641 IsClassConstructor(function_state_->kind())) { |
643 bool is_this = peek() == Token::THIS; | 642 bool is_this = peek() == Token::THIS; |
644 Expression expr = Expression::Default(); | 643 Expression expr = Expression::Default(); |
645 ExpressionClassifier classifier; | 644 ExpressionClassifier classifier; |
646 if (is_this) { | 645 if (is_this) { |
647 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK); | 646 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK); |
648 } else { | 647 } else { |
649 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK); | 648 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK); |
650 } | 649 } |
651 ValidateExpression(&classifier, CHECK_OK); | 650 ValidateExpression(&classifier, CHECK_OK); |
652 switch (peek()) { | 651 switch (peek()) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 // contains a return statement that is not within the body of a | 782 // contains a return statement that is not within the body of a |
784 // function. See ECMA-262, section 12.9, page 67. | 783 // function. See ECMA-262, section 12.9, page 67. |
785 // This is not handled during preparsing. | 784 // This is not handled during preparsing. |
786 | 785 |
787 Token::Value tok = peek(); | 786 Token::Value tok = peek(); |
788 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 787 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
789 tok != Token::SEMICOLON && | 788 tok != Token::SEMICOLON && |
790 tok != Token::RBRACE && | 789 tok != Token::RBRACE && |
791 tok != Token::EOS) { | 790 tok != Token::EOS) { |
792 if (is_strong(language_mode()) && | 791 if (is_strong(language_mode()) && |
793 i::IsConstructor(function_state_->kind())) { | 792 IsClassConstructor(function_state_->kind())) { |
794 int pos = peek_position(); | 793 int pos = peek_position(); |
795 ReportMessageAt(Scanner::Location(pos, pos + 1), | 794 ReportMessageAt(Scanner::Location(pos, pos + 1), |
796 MessageTemplate::kStrongConstructorReturnValue); | 795 MessageTemplate::kStrongConstructorReturnValue); |
797 *ok = false; | 796 *ok = false; |
798 return Statement::Default(); | 797 return Statement::Default(); |
799 } | 798 } |
800 ParseExpression(true, CHECK_OK); | 799 ParseExpression(true, CHECK_OK); |
801 } | 800 } |
802 ExpectSemicolon(CHECK_OK); | 801 ExpectSemicolon(CHECK_OK); |
803 return Statement::Jump(); | 802 return Statement::Jump(); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 | 1231 |
1233 DCHECK(!spread_pos.IsValid()); | 1232 DCHECK(!spread_pos.IsValid()); |
1234 | 1233 |
1235 return Expression::Default(); | 1234 return Expression::Default(); |
1236 } | 1235 } |
1237 | 1236 |
1238 #undef CHECK_OK | 1237 #undef CHECK_OK |
1239 | 1238 |
1240 | 1239 |
1241 } } // v8::internal | 1240 } } // v8::internal |
OLD | NEW |