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

Side by Side Diff: src/preparser.cc

Issue 149913006: Traitify ParserBase and move functions there. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code review (mstarzinger) Created 6 years, 10 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 | Annotate | Revision Log
« 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // Usually defined in math.h, but not in MSVC until VS2013+. 48 // Usually defined in math.h, but not in MSVC until VS2013+.
49 // Abstracted to work 49 // Abstracted to work
50 int isfinite(double value); 50 int isfinite(double value);
51 51
52 } // namespace std 52 } // namespace std
53 #endif 53 #endif
54 54
55 namespace v8 { 55 namespace v8 {
56 namespace internal { 56 namespace internal {
57 57
58 bool PreParserTraits::is_classic_mode() const {
59 return pre_parser_->scope_->language_mode() == CLASSIC_MODE;
60 }
61
62
63 bool PreParserTraits::is_generator() const {
64 return pre_parser_->scope_->is_generator();
65 }
66
67
68 void PreParserTraits::ReportMessageAt(Scanner::Location location,
69 const char* message,
70 Vector<const char*> args) {
71 ReportMessageAt(location.beg_pos,
72 location.end_pos,
73 message,
74 args.length() > 0 ? args[0] : NULL);
75 }
76
77
78 void PreParserTraits::ReportMessageAt(Scanner::Location location,
79 const char* type,
80 const char* name_opt) {
81 pre_parser_->log_
82 ->LogMessage(location.beg_pos, location.end_pos, type, name_opt);
83 }
84
85
86 void PreParserTraits::ReportMessageAt(int start_pos,
87 int end_pos,
88 const char* type,
89 const char* name_opt) {
90 pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt);
91 }
92
93
94 PreParserIdentifier PreParserTraits::GetSymbol() {
95 Scanner* scanner = pre_parser_->scanner();
96 pre_parser_->LogSymbol();
97 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) {
98 return PreParserIdentifier::FutureReserved();
99 } else if (scanner->current_token() ==
100 Token::FUTURE_STRICT_RESERVED_WORD) {
101 return PreParserIdentifier::FutureStrictReserved();
102 } else if (scanner->current_token() == Token::YIELD) {
103 return PreParserIdentifier::Yield();
104 }
105 if (scanner->is_literal_ascii()) {
106 // Detect strict-mode poison words.
107 if (scanner->literal_length() == 4 &&
108 !strncmp(scanner->literal_ascii_string().start(), "eval", 4)) {
109 return PreParserIdentifier::Eval();
110 }
111 if (scanner->literal_length() == 9 &&
112 !strncmp(scanner->literal_ascii_string().start(), "arguments", 9)) {
113 return PreParserIdentifier::Arguments();
114 }
115 }
116 return PreParserIdentifier::Default();
117 }
118
119
58 PreParser::PreParseResult PreParser::PreParseLazyFunction( 120 PreParser::PreParseResult PreParser::PreParseLazyFunction(
59 LanguageMode mode, bool is_generator, ParserRecorder* log) { 121 LanguageMode mode, bool is_generator, ParserRecorder* log) {
60 log_ = log; 122 log_ = log;
61 // Lazy functions always have trivial outer scopes (no with/catch scopes). 123 // Lazy functions always have trivial outer scopes (no with/catch scopes).
62 Scope top_scope(&scope_, kTopLevelScope); 124 Scope top_scope(&scope_, kTopLevelScope);
63 set_language_mode(mode); 125 set_language_mode(mode);
64 Scope function_scope(&scope_, kFunctionScope); 126 Scope function_scope(&scope_, kFunctionScope);
65 function_scope.set_is_generator(is_generator); 127 function_scope.set_is_generator(is_generator);
66 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); 128 ASSERT_EQ(Token::LBRACE, scanner()->current_token());
67 bool ok = true; 129 bool ok = true;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 return ParseThrowStatement(ok); 290 return ParseThrowStatement(ok);
229 291
230 case Token::TRY: 292 case Token::TRY:
231 return ParseTryStatement(ok); 293 return ParseTryStatement(ok);
232 294
233 case Token::FUNCTION: { 295 case Token::FUNCTION: {
234 Scanner::Location start_location = scanner()->peek_location(); 296 Scanner::Location start_location = scanner()->peek_location();
235 Statement statement = ParseFunctionDeclaration(CHECK_OK); 297 Statement statement = ParseFunctionDeclaration(CHECK_OK);
236 Scanner::Location end_location = scanner()->location(); 298 Scanner::Location end_location = scanner()->location();
237 if (!scope_->is_classic_mode()) { 299 if (!scope_->is_classic_mode()) {
238 ReportMessageAt(start_location.beg_pos, end_location.end_pos, 300 PreParserTraits::ReportMessageAt(start_location.beg_pos,
239 "strict_function", NULL); 301 end_location.end_pos,
302 "strict_function",
303 NULL);
240 *ok = false; 304 *ok = false;
241 return Statement::Default(); 305 return Statement::Default();
242 } else { 306 } else {
243 return statement; 307 return statement;
244 } 308 }
245 } 309 }
246 310
247 case Token::DEBUGGER: 311 case Token::DEBUGGER:
248 return ParseDebuggerStatement(ok); 312 return ParseDebuggerStatement(ok);
249 313
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // 409 //
346 // However disallowing const in classic mode will break compatibility with 410 // However disallowing const in classic mode will break compatibility with
347 // existing pages. Therefore we keep allowing const with the old 411 // existing pages. Therefore we keep allowing const with the old
348 // non-harmony semantics in classic mode. 412 // non-harmony semantics in classic mode.
349 Consume(Token::CONST); 413 Consume(Token::CONST);
350 switch (language_mode()) { 414 switch (language_mode()) {
351 case CLASSIC_MODE: 415 case CLASSIC_MODE:
352 break; 416 break;
353 case STRICT_MODE: { 417 case STRICT_MODE: {
354 Scanner::Location location = scanner()->peek_location(); 418 Scanner::Location location = scanner()->peek_location();
355 ReportMessageAt(location, "strict_const", NULL); 419 ReportMessageAt(location, "strict_const");
356 *ok = false; 420 *ok = false;
357 return Statement::Default(); 421 return Statement::Default();
358 } 422 }
359 case EXTENDED_MODE: 423 case EXTENDED_MODE:
360 if (var_context != kSourceElement && 424 if (var_context != kSourceElement &&
361 var_context != kForStatement) { 425 var_context != kForStatement) {
362 Scanner::Location location = scanner()->peek_location(); 426 ReportMessageAt(scanner()->peek_location(), "unprotected_const");
363 ReportMessageAt(location.beg_pos, location.end_pos,
364 "unprotected_const", NULL);
365 *ok = false; 427 *ok = false;
366 return Statement::Default(); 428 return Statement::Default();
367 } 429 }
368 require_initializer = true; 430 require_initializer = true;
369 break; 431 break;
370 } 432 }
371 } else if (peek() == Token::LET) { 433 } else if (peek() == Token::LET) {
372 // ES6 Draft Rev4 section 12.2.1: 434 // ES6 Draft Rev4 section 12.2.1:
373 // 435 //
374 // LetDeclaration : let LetBindingList ; 436 // LetDeclaration : let LetBindingList ;
375 // 437 //
376 // * It is a Syntax Error if the code that matches this production is not 438 // * It is a Syntax Error if the code that matches this production is not
377 // contained in extended code. 439 // contained in extended code.
378 if (!is_extended_mode()) { 440 if (!is_extended_mode()) {
379 Scanner::Location location = scanner()->peek_location(); 441 ReportMessageAt(scanner()->peek_location(), "illegal_let");
380 ReportMessageAt(location.beg_pos, location.end_pos,
381 "illegal_let", NULL);
382 *ok = false; 442 *ok = false;
383 return Statement::Default(); 443 return Statement::Default();
384 } 444 }
385 Consume(Token::LET); 445 Consume(Token::LET);
386 if (var_context != kSourceElement && 446 if (var_context != kSourceElement &&
387 var_context != kForStatement) { 447 var_context != kForStatement) {
388 Scanner::Location location = scanner()->peek_location(); 448 ReportMessageAt(scanner()->peek_location(), "unprotected_let");
389 ReportMessageAt(location.beg_pos, location.end_pos,
390 "unprotected_let", NULL);
391 *ok = false; 449 *ok = false;
392 return Statement::Default(); 450 return Statement::Default();
393 } 451 }
394 } else { 452 } else {
395 *ok = false; 453 *ok = false;
396 return Statement::Default(); 454 return Statement::Default();
397 } 455 }
398 456
399 // The scope of a var/const declared variable anywhere inside a function 457 // The scope of a var/const declared variable anywhere inside a function
400 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope 458 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 ExpectSemicolon(CHECK_OK); 582 ExpectSemicolon(CHECK_OK);
525 return Statement::Default(); 583 return Statement::Default();
526 } 584 }
527 585
528 586
529 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { 587 PreParser::Statement PreParser::ParseWithStatement(bool* ok) {
530 // WithStatement :: 588 // WithStatement ::
531 // 'with' '(' Expression ')' Statement 589 // 'with' '(' Expression ')' Statement
532 Expect(Token::WITH, CHECK_OK); 590 Expect(Token::WITH, CHECK_OK);
533 if (!scope_->is_classic_mode()) { 591 if (!scope_->is_classic_mode()) {
534 Scanner::Location location = scanner()->location(); 592 ReportMessageAt(scanner()->location(), "strict_mode_with");
535 ReportMessageAt(location, "strict_mode_with", NULL);
536 *ok = false; 593 *ok = false;
537 return Statement::Default(); 594 return Statement::Default();
538 } 595 }
539 Expect(Token::LPAREN, CHECK_OK); 596 Expect(Token::LPAREN, CHECK_OK);
540 ParseExpression(true, CHECK_OK); 597 ParseExpression(true, CHECK_OK);
541 Expect(Token::RPAREN, CHECK_OK); 598 Expect(Token::RPAREN, CHECK_OK);
542 599
543 Scope::InsideWith iw(scope_); 600 Scope::InsideWith iw(scope_);
544 ParseStatement(CHECK_OK); 601 ParseStatement(CHECK_OK);
545 return Statement::Default(); 602 return Statement::Default();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 return Statement::Default(); 726 return Statement::Default();
670 } 727 }
671 728
672 729
673 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { 730 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) {
674 // ThrowStatement :: 731 // ThrowStatement ::
675 // 'throw' [no line terminator] Expression ';' 732 // 'throw' [no line terminator] Expression ';'
676 733
677 Expect(Token::THROW, CHECK_OK); 734 Expect(Token::THROW, CHECK_OK);
678 if (scanner()->HasAnyLineTerminatorBeforeNext()) { 735 if (scanner()->HasAnyLineTerminatorBeforeNext()) {
679 Scanner::Location pos = scanner()->location(); 736 ReportMessageAt(scanner()->location(), "newline_after_throw");
680 ReportMessageAt(pos, "newline_after_throw", NULL);
681 *ok = false; 737 *ok = false;
682 return Statement::Default(); 738 return Statement::Default();
683 } 739 }
684 ParseExpression(true, CHECK_OK); 740 ParseExpression(true, CHECK_OK);
685 ExpectSemicolon(ok); 741 ExpectSemicolon(ok);
686 return Statement::Default(); 742 return Statement::Default();
687 } 743 }
688 744
689 745
690 PreParser::Statement PreParser::ParseTryStatement(bool* ok) { 746 PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
691 // TryStatement :: 747 // TryStatement ::
692 // 'try' Block Catch 748 // 'try' Block Catch
693 // 'try' Block Finally 749 // 'try' Block Finally
694 // 'try' Block Catch Finally 750 // 'try' Block Catch Finally
695 // 751 //
696 // Catch :: 752 // Catch ::
697 // 'catch' '(' Identifier ')' Block 753 // 'catch' '(' Identifier ')' Block
698 // 754 //
699 // Finally :: 755 // Finally ::
700 // 'finally' Block 756 // 'finally' Block
701 757
702 Expect(Token::TRY, CHECK_OK); 758 Expect(Token::TRY, CHECK_OK);
703 759
704 ParseBlock(CHECK_OK); 760 ParseBlock(CHECK_OK);
705 761
706 Token::Value tok = peek(); 762 Token::Value tok = peek();
707 if (tok != Token::CATCH && tok != Token::FINALLY) { 763 if (tok != Token::CATCH && tok != Token::FINALLY) {
708 ReportMessageAt(scanner()->location(), "no_catch_or_finally", NULL); 764 ReportMessageAt(scanner()->location(), "no_catch_or_finally");
709 *ok = false; 765 *ok = false;
710 return Statement::Default(); 766 return Statement::Default();
711 } 767 }
712 if (tok == Token::CATCH) { 768 if (tok == Token::CATCH) {
713 Consume(Token::CATCH); 769 Consume(Token::CATCH);
714 Expect(Token::LPAREN, CHECK_OK); 770 Expect(Token::LPAREN, CHECK_OK);
715 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); 771 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
716 Expect(Token::RPAREN, CHECK_OK); 772 Expect(Token::RPAREN, CHECK_OK);
717 { Scope::InsideWith iw(scope_); 773 { Scope::InsideWith iw(scope_);
718 ParseBlock(CHECK_OK); 774 ParseBlock(CHECK_OK);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 837
782 if (!Token::IsAssignmentOp(peek())) { 838 if (!Token::IsAssignmentOp(peek())) {
783 // Parsed conditional expression only (no assignment). 839 // Parsed conditional expression only (no assignment).
784 return expression; 840 return expression;
785 } 841 }
786 842
787 if (!scope_->is_classic_mode() && 843 if (!scope_->is_classic_mode() &&
788 expression.IsIdentifier() && 844 expression.IsIdentifier() &&
789 expression.AsIdentifier().IsEvalOrArguments()) { 845 expression.AsIdentifier().IsEvalOrArguments()) {
790 Scanner::Location after = scanner()->location(); 846 Scanner::Location after = scanner()->location();
791 ReportMessageAt(before.beg_pos, after.end_pos, 847 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
792 "strict_eval_arguments", NULL); 848 "strict_eval_arguments", NULL);
793 *ok = false; 849 *ok = false;
794 return Expression::Default(); 850 return Expression::Default();
795 } 851 }
796 852
797 Token::Value op = Next(); // Get assignment operator. 853 Token::Value op = Next(); // Get assignment operator.
798 ParseAssignmentExpression(accept_IN, CHECK_OK); 854 ParseAssignmentExpression(accept_IN, CHECK_OK);
799 855
800 if ((op == Token::ASSIGN) && expression.IsThisProperty()) { 856 if ((op == Token::ASSIGN) && expression.IsThisProperty()) {
801 scope_->AddProperty(); 857 scope_->AddProperty();
802 } 858 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 ParseUnaryExpression(ok); 931 ParseUnaryExpression(ok);
876 return Expression::Default(); 932 return Expression::Default();
877 } else if (Token::IsCountOp(op)) { 933 } else if (Token::IsCountOp(op)) {
878 op = Next(); 934 op = Next();
879 Scanner::Location before = scanner()->peek_location(); 935 Scanner::Location before = scanner()->peek_location();
880 Expression expression = ParseUnaryExpression(CHECK_OK); 936 Expression expression = ParseUnaryExpression(CHECK_OK);
881 if (!scope_->is_classic_mode() && 937 if (!scope_->is_classic_mode() &&
882 expression.IsIdentifier() && 938 expression.IsIdentifier() &&
883 expression.AsIdentifier().IsEvalOrArguments()) { 939 expression.AsIdentifier().IsEvalOrArguments()) {
884 Scanner::Location after = scanner()->location(); 940 Scanner::Location after = scanner()->location();
885 ReportMessageAt(before.beg_pos, after.end_pos, 941 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
886 "strict_eval_arguments", NULL); 942 "strict_eval_arguments", NULL);
887 *ok = false; 943 *ok = false;
888 } 944 }
889 return Expression::Default(); 945 return Expression::Default();
890 } else { 946 } else {
891 return ParsePostfixExpression(ok); 947 return ParsePostfixExpression(ok);
892 } 948 }
893 } 949 }
894 950
895 951
896 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { 952 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) {
897 // PostfixExpression :: 953 // PostfixExpression ::
898 // LeftHandSideExpression ('++' | '--')? 954 // LeftHandSideExpression ('++' | '--')?
899 955
900 Scanner::Location before = scanner()->peek_location(); 956 Scanner::Location before = scanner()->peek_location();
901 Expression expression = ParseLeftHandSideExpression(CHECK_OK); 957 Expression expression = ParseLeftHandSideExpression(CHECK_OK);
902 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 958 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
903 Token::IsCountOp(peek())) { 959 Token::IsCountOp(peek())) {
904 if (!scope_->is_classic_mode() && 960 if (!scope_->is_classic_mode() &&
905 expression.IsIdentifier() && 961 expression.IsIdentifier() &&
906 expression.AsIdentifier().IsEvalOrArguments()) { 962 expression.AsIdentifier().IsEvalOrArguments()) {
907 Scanner::Location after = scanner()->location(); 963 Scanner::Location after = scanner()->location();
908 ReportMessageAt(before.beg_pos, after.end_pos, 964 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos,
909 "strict_eval_arguments", NULL); 965 "strict_eval_arguments", NULL);
910 *ok = false; 966 *ok = false;
911 return Expression::Default(); 967 return Expression::Default();
912 } 968 }
913 Next(); 969 Next();
914 return Expression::Default(); 970 return Expression::Default();
915 } 971 }
916 return expression; 972 return expression;
917 } 973 }
918 974
919 975
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 1298
1243 scope_->NextMaterializedLiteralIndex(); 1299 scope_->NextMaterializedLiteralIndex();
1244 return Expression::Default(); 1300 return Expression::Default();
1245 } 1301 }
1246 1302
1247 1303
1248 PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal, 1304 PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal,
1249 bool* ok) { 1305 bool* ok) {
1250 if (!scanner()->ScanRegExpPattern(seen_equal)) { 1306 if (!scanner()->ScanRegExpPattern(seen_equal)) {
1251 Next(); 1307 Next();
1252 ReportMessageAt(scanner()->location(), "unterminated_regexp", NULL); 1308 ReportMessageAt(scanner()->location(), "unterminated_regexp");
1253 *ok = false; 1309 *ok = false;
1254 return Expression::Default(); 1310 return Expression::Default();
1255 } 1311 }
1256 1312
1257 scope_->NextMaterializedLiteralIndex(); 1313 scope_->NextMaterializedLiteralIndex();
1258 1314
1259 if (!scanner()->ScanRegExpFlags()) { 1315 if (!scanner()->ScanRegExpFlags()) {
1260 Next(); 1316 Next();
1261 ReportMessageAt(scanner()->location(), "invalid_regexp_flags", NULL); 1317 ReportMessageAt(scanner()->location(), "invalid_regexp_flags");
1262 *ok = false; 1318 *ok = false;
1263 return Expression::Default(); 1319 return Expression::Default();
1264 } 1320 }
1265 Next(); 1321 Next();
1266 return Expression::Default(); 1322 return Expression::Default();
1267 } 1323 }
1268 1324
1269 1325
1270 PreParser::Arguments PreParser::ParseArguments(bool* ok) { 1326 PreParser::Arguments PreParser::ParseArguments(bool* ok) {
1271 // Arguments :: 1327 // Arguments ::
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 ParseLazyFunctionLiteralBody(CHECK_OK); 1415 ParseLazyFunctionLiteralBody(CHECK_OK);
1360 } else { 1416 } else {
1361 ParseSourceElements(Token::RBRACE, ok); 1417 ParseSourceElements(Token::RBRACE, ok);
1362 } 1418 }
1363 Expect(Token::RBRACE, CHECK_OK); 1419 Expect(Token::RBRACE, CHECK_OK);
1364 1420
1365 // Validate strict mode. We can do this only after parsing the function, 1421 // Validate strict mode. We can do this only after parsing the function,
1366 // since the function can declare itself strict. 1422 // since the function can declare itself strict.
1367 if (!scope_->is_classic_mode()) { 1423 if (!scope_->is_classic_mode()) {
1368 if (function_name.IsEvalOrArguments()) { 1424 if (function_name.IsEvalOrArguments()) {
1369 ReportMessageAt(function_name_location, "strict_eval_arguments", NULL); 1425 ReportMessageAt(function_name_location, "strict_eval_arguments");
1370 *ok = false; 1426 *ok = false;
1371 return Expression::Default(); 1427 return Expression::Default();
1372 } 1428 }
1373 if (name_is_strict_reserved) { 1429 if (name_is_strict_reserved) {
1374 ReportMessageAt( 1430 ReportMessageAt(function_name_location, "unexpected_strict_reserved");
1375 function_name_location, "unexpected_strict_reserved", NULL);
1376 *ok = false; 1431 *ok = false;
1377 return Expression::Default(); 1432 return Expression::Default();
1378 } 1433 }
1379 if (eval_args_error_loc.IsValid()) { 1434 if (eval_args_error_loc.IsValid()) {
1380 ReportMessageAt(eval_args_error_loc, "strict_eval_arguments", 1435 ReportMessageAt(eval_args_error_loc, "strict_eval_arguments");
1381 Vector<const char*>::empty());
1382 *ok = false; 1436 *ok = false;
1383 return Expression::Default(); 1437 return Expression::Default();
1384 } 1438 }
1385 if (dupe_error_loc.IsValid()) { 1439 if (dupe_error_loc.IsValid()) {
1386 ReportMessageAt(dupe_error_loc, "strict_param_dupe", 1440 ReportMessageAt(dupe_error_loc, "strict_param_dupe");
1387 Vector<const char*>::empty());
1388 *ok = false; 1441 *ok = false;
1389 return Expression::Default(); 1442 return Expression::Default();
1390 } 1443 }
1391 if (reserved_error_loc.IsValid()) { 1444 if (reserved_error_loc.IsValid()) {
1392 ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved", 1445 ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved");
1393 Vector<const char*>::empty());
1394 *ok = false; 1446 *ok = false;
1395 return Expression::Default(); 1447 return Expression::Default();
1396 } 1448 }
1397 1449
1398 int end_position = scanner()->location().end_pos; 1450 int end_position = scanner()->location().end_pos;
1399 CheckOctalLiteral(start_position, end_position, CHECK_OK); 1451 CheckOctalLiteral(start_position, end_position, CHECK_OK);
1400 return Expression::StrictFunction(); 1452 return Expression::StrictFunction();
1401 } 1453 }
1402 1454
1403 return Expression::Default(); 1455 return Expression::Default();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 scanner()->literal_length() == kUseStrictLength && 1509 scanner()->literal_length() == kUseStrictLength &&
1458 !scanner()->literal_contains_escapes() && 1510 !scanner()->literal_contains_escapes() &&
1459 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, 1511 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars,
1460 kUseStrictLength)) { 1512 kUseStrictLength)) {
1461 return Expression::UseStrictStringLiteral(); 1513 return Expression::UseStrictStringLiteral();
1462 } 1514 }
1463 return Expression::StringLiteral(); 1515 return Expression::StringLiteral();
1464 } 1516 }
1465 1517
1466 1518
1467 PreParser::Identifier PreParser::GetIdentifierSymbol() {
1468 LogSymbol();
1469 if (scanner()->current_token() == Token::FUTURE_RESERVED_WORD) {
1470 return Identifier::FutureReserved();
1471 } else if (scanner()->current_token() ==
1472 Token::FUTURE_STRICT_RESERVED_WORD) {
1473 return Identifier::FutureStrictReserved();
1474 } else if (scanner()->current_token() == Token::YIELD) {
1475 return Identifier::Yield();
1476 }
1477 if (scanner()->is_literal_ascii()) {
1478 // Detect strict-mode poison words.
1479 if (scanner()->literal_length() == 4 &&
1480 !strncmp(scanner()->literal_ascii_string().start(), "eval", 4)) {
1481 return Identifier::Eval();
1482 }
1483 if (scanner()->literal_length() == 9 &&
1484 !strncmp(scanner()->literal_ascii_string().start(), "arguments", 9)) {
1485 return Identifier::Arguments();
1486 }
1487 }
1488 return Identifier::Default();
1489 }
1490
1491
1492 // Parses an identifier that is valid for the current scope, in particular it
1493 // fails on strict mode future reserved keywords in a strict scope. If
1494 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
1495 // "arguments" as identifier even in strict mode (this is needed in cases like
1496 // "var foo = eval;").
1497 PreParser::Identifier PreParser::ParseIdentifier(
1498 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments,
1499 bool* ok) {
1500 Token::Value next = Next();
1501 if (next == Token::IDENTIFIER) {
1502 PreParser::Identifier name = GetIdentifierSymbol();
1503 if (allow_eval_or_arguments == kDontAllowEvalOrArguments &&
1504 !scope_->is_classic_mode() && name.IsEvalOrArguments()) {
1505 ReportMessageAt(scanner()->location(), "strict_eval_arguments", NULL);
1506 *ok = false;
1507 }
1508 return name;
1509 } else if (scope_->is_classic_mode() &&
1510 (next == Token::FUTURE_STRICT_RESERVED_WORD ||
1511 (next == Token::YIELD && !scope_->is_generator()))) {
1512 return GetIdentifierSymbol();
1513 } else {
1514 ReportUnexpectedToken(next);
1515 *ok = false;
1516 return Identifier::Default();
1517 }
1518 }
1519
1520
1521 // Parses and identifier or a strict mode future reserved word, and indicate
1522 // whether it is strict mode future reserved.
1523 PreParser::Identifier PreParser::ParseIdentifierOrStrictReservedWord(
1524 bool* is_strict_reserved, bool* ok) {
1525 Token::Value next = Next();
1526 if (next == Token::IDENTIFIER) {
1527 *is_strict_reserved = false;
1528 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD ||
1529 (next == Token::YIELD && !scope_->is_generator())) {
1530 *is_strict_reserved = true;
1531 } else {
1532 ReportUnexpectedToken(next);
1533 *ok = false;
1534 return Identifier::Default();
1535 }
1536 return GetIdentifierSymbol();
1537 }
1538
1539
1540 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) {
1541 Token::Value next = Next();
1542 if (next != Token::IDENTIFIER &&
1543 next != Token::FUTURE_RESERVED_WORD &&
1544 next != Token::FUTURE_STRICT_RESERVED_WORD &&
1545 !Token::IsKeyword(next)) {
1546 ReportUnexpectedToken(next);
1547 *ok = false;
1548 return Identifier::Default();
1549 }
1550 return GetIdentifierSymbol();
1551 }
1552
1553 #undef CHECK_OK
1554
1555
1556 // This function reads an identifier and determines whether or not it
1557 // is 'get' or 'set'.
1558 PreParser::Identifier PreParser::ParseIdentifierNameOrGetOrSet(bool* is_get,
1559 bool* is_set,
1560 bool* ok) {
1561 Identifier result = ParseIdentifierName(ok);
1562 if (!*ok) return Identifier::Default();
1563 if (scanner()->is_literal_ascii() &&
1564 scanner()->literal_length() == 3) {
1565 const char* token = scanner()->literal_ascii_string().start();
1566 *is_get = strncmp(token, "get", 3) == 0;
1567 *is_set = !*is_get && strncmp(token, "set", 3) == 0;
1568 }
1569 return result;
1570 }
1571
1572
1573 void PreParser::ObjectLiteralChecker::CheckProperty(Token::Value property,
1574 PropertyKind type,
1575 bool* ok) {
1576 int old;
1577 if (property == Token::NUMBER) {
1578 old = finder_.AddNumber(scanner()->literal_ascii_string(), type);
1579 } else if (scanner()->is_literal_ascii()) {
1580 old = finder_.AddAsciiSymbol(scanner()->literal_ascii_string(), type);
1581 } else {
1582 old = finder_.AddUtf16Symbol(scanner()->literal_utf16_string(), type);
1583 }
1584 PropertyKind old_type = static_cast<PropertyKind>(old);
1585 if (HasConflict(old_type, type)) {
1586 if (IsDataDataConflict(old_type, type)) {
1587 // Both are data properties.
1588 if (language_mode_ == CLASSIC_MODE) return;
1589 parser()->ReportMessageAt(scanner()->location(),
1590 "strict_duplicate_property");
1591 } else if (IsDataAccessorConflict(old_type, type)) {
1592 // Both a data and an accessor property with the same name.
1593 parser()->ReportMessageAt(scanner()->location(),
1594 "accessor_data_property");
1595 } else {
1596 ASSERT(IsAccessorAccessorConflict(old_type, type));
1597 // Both accessors of the same type.
1598 parser()->ReportMessageAt(scanner()->location(),
1599 "accessor_get_set");
1600 }
1601 *ok = false;
1602 }
1603 }
1604
1605 } } // v8::internal 1519 } } // 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