OLD | NEW |
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 Loading... |
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_->function_state_->is_generator(); | |
65 } | |
66 | |
67 | |
68 int PreParserTraits::NextMaterializedLiteralIndex() { | |
69 return pre_parser_->function_state_->NextMaterializedLiteralIndex(); | |
70 } | |
71 | |
72 | |
73 void PreParserTraits::ReportMessageAt(Scanner::Location location, | 58 void PreParserTraits::ReportMessageAt(Scanner::Location location, |
74 const char* message, | 59 const char* message, |
75 Vector<const char*> args) { | 60 Vector<const char*> args) { |
76 ReportMessageAt(location.beg_pos, | 61 ReportMessageAt(location.beg_pos, |
77 location.end_pos, | 62 location.end_pos, |
78 message, | 63 message, |
79 args.length() > 0 ? args[0] : NULL); | 64 args.length() > 0 ? args[0] : NULL); |
80 } | 65 } |
81 | 66 |
82 | 67 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 104 } |
120 } | 105 } |
121 return PreParserIdentifier::Default(); | 106 return PreParserIdentifier::Default(); |
122 } | 107 } |
123 | 108 |
124 | 109 |
125 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 110 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
126 LanguageMode mode, bool is_generator, ParserRecorder* log) { | 111 LanguageMode mode, bool is_generator, ParserRecorder* log) { |
127 log_ = log; | 112 log_ = log; |
128 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 113 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
129 FunctionState top_scope(&function_state_, &scope_, GLOBAL_SCOPE); | 114 PreParserScope top_scope(scope_, GLOBAL_SCOPE); |
| 115 FunctionState top_state(&function_state_, &scope_, &top_scope); |
130 scope_->SetLanguageMode(mode); | 116 scope_->SetLanguageMode(mode); |
131 FunctionState function_scope(&function_state_, &scope_, FUNCTION_SCOPE); | 117 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
132 function_scope.set_is_generator(is_generator); | 118 FunctionState function_state(&function_state_, &scope_, &function_scope); |
| 119 function_state.set_is_generator(is_generator); |
133 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); | 120 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); |
134 bool ok = true; | 121 bool ok = true; |
135 int start_position = peek_position(); | 122 int start_position = peek_position(); |
136 ParseLazyFunctionLiteralBody(&ok); | 123 ParseLazyFunctionLiteralBody(&ok); |
137 if (stack_overflow()) return kPreParseStackOverflow; | 124 if (stack_overflow()) return kPreParseStackOverflow; |
138 if (!ok) { | 125 if (!ok) { |
139 ReportUnexpectedToken(scanner()->current_token()); | 126 ReportUnexpectedToken(scanner()->current_token()); |
140 } else { | 127 } else { |
141 ASSERT_EQ(Token::RBRACE, scanner()->peek()); | 128 ASSERT_EQ(Token::RBRACE, scanner()->peek()); |
142 if (!scope_->is_classic_mode()) { | 129 if (!scope_->is_classic_mode()) { |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 Expect(Token::WITH, CHECK_OK); | 582 Expect(Token::WITH, CHECK_OK); |
596 if (!scope_->is_classic_mode()) { | 583 if (!scope_->is_classic_mode()) { |
597 ReportMessageAt(scanner()->location(), "strict_mode_with"); | 584 ReportMessageAt(scanner()->location(), "strict_mode_with"); |
598 *ok = false; | 585 *ok = false; |
599 return Statement::Default(); | 586 return Statement::Default(); |
600 } | 587 } |
601 Expect(Token::LPAREN, CHECK_OK); | 588 Expect(Token::LPAREN, CHECK_OK); |
602 ParseExpression(true, CHECK_OK); | 589 ParseExpression(true, CHECK_OK); |
603 Expect(Token::RPAREN, CHECK_OK); | 590 Expect(Token::RPAREN, CHECK_OK); |
604 | 591 |
605 BlockState block_state(&scope_, WITH_SCOPE); | 592 PreParserScope with_scope(scope_, WITH_SCOPE); |
| 593 BlockState block_state(&scope_, &with_scope); |
606 ParseStatement(CHECK_OK); | 594 ParseStatement(CHECK_OK); |
607 return Statement::Default(); | 595 return Statement::Default(); |
608 } | 596 } |
609 | 597 |
610 | 598 |
611 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { | 599 PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) { |
612 // SwitchStatement :: | 600 // SwitchStatement :: |
613 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 601 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
614 | 602 |
615 Expect(Token::SWITCH, CHECK_OK); | 603 Expect(Token::SWITCH, CHECK_OK); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 ReportMessageAt(scanner()->location(), "no_catch_or_finally"); | 757 ReportMessageAt(scanner()->location(), "no_catch_or_finally"); |
770 *ok = false; | 758 *ok = false; |
771 return Statement::Default(); | 759 return Statement::Default(); |
772 } | 760 } |
773 if (tok == Token::CATCH) { | 761 if (tok == Token::CATCH) { |
774 Consume(Token::CATCH); | 762 Consume(Token::CATCH); |
775 Expect(Token::LPAREN, CHECK_OK); | 763 Expect(Token::LPAREN, CHECK_OK); |
776 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 764 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
777 Expect(Token::RPAREN, CHECK_OK); | 765 Expect(Token::RPAREN, CHECK_OK); |
778 { | 766 { |
779 BlockState block_state(&scope_, WITH_SCOPE); | 767 PreParserScope with_scope(scope_, WITH_SCOPE); |
| 768 BlockState block_state(&scope_, &with_scope); |
780 ParseBlock(CHECK_OK); | 769 ParseBlock(CHECK_OK); |
781 } | 770 } |
782 tok = peek(); | 771 tok = peek(); |
783 } | 772 } |
784 if (tok == Token::FINALLY) { | 773 if (tok == Token::FINALLY) { |
785 Consume(Token::FINALLY); | 774 Consume(Token::FINALLY); |
786 ParseBlock(CHECK_OK); | 775 ParseBlock(CHECK_OK); |
787 } | 776 } |
788 return Statement::Default(); | 777 return Statement::Default(); |
789 } | 778 } |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 Scanner::Location function_name_location, | 1323 Scanner::Location function_name_location, |
1335 bool name_is_strict_reserved, | 1324 bool name_is_strict_reserved, |
1336 bool is_generator, | 1325 bool is_generator, |
1337 bool* ok) { | 1326 bool* ok) { |
1338 // Function :: | 1327 // Function :: |
1339 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 1328 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
1340 | 1329 |
1341 // Parse function body. | 1330 // Parse function body. |
1342 ScopeType outer_scope_type = scope_->type(); | 1331 ScopeType outer_scope_type = scope_->type(); |
1343 bool inside_with = scope_->inside_with(); | 1332 bool inside_with = scope_->inside_with(); |
1344 FunctionState function_scope(&function_state_, &scope_, FUNCTION_SCOPE); | 1333 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
1345 function_scope.set_is_generator(is_generator); | 1334 FunctionState function_state(&function_state_, &scope_, &function_scope); |
| 1335 function_state.set_is_generator(is_generator); |
1346 // FormalParameterList :: | 1336 // FormalParameterList :: |
1347 // '(' (Identifier)*[','] ')' | 1337 // '(' (Identifier)*[','] ')' |
1348 Expect(Token::LPAREN, CHECK_OK); | 1338 Expect(Token::LPAREN, CHECK_OK); |
1349 int start_position = position(); | 1339 int start_position = position(); |
1350 bool done = (peek() == Token::RPAREN); | 1340 bool done = (peek() == Token::RPAREN); |
1351 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 1341 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
1352 // We don't yet know if the function will be strict, so we cannot yet produce | 1342 // We don't yet know if the function will be strict, so we cannot yet produce |
1353 // errors for parameter names or duplicates. However, we remember the | 1343 // errors for parameter names or duplicates. However, we remember the |
1354 // locations of these errors if they occur and produce the errors later. | 1344 // locations of these errors if they occur and produce the errors later. |
1355 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); | 1345 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 log_->PauseRecording(); | 1435 log_->PauseRecording(); |
1446 ParseSourceElements(Token::RBRACE, ok); | 1436 ParseSourceElements(Token::RBRACE, ok); |
1447 log_->ResumeRecording(); | 1437 log_->ResumeRecording(); |
1448 if (!*ok) return; | 1438 if (!*ok) return; |
1449 | 1439 |
1450 // Position right after terminal '}'. | 1440 // Position right after terminal '}'. |
1451 ASSERT_EQ(Token::RBRACE, scanner()->peek()); | 1441 ASSERT_EQ(Token::RBRACE, scanner()->peek()); |
1452 int body_end = scanner()->peek_location().end_pos; | 1442 int body_end = scanner()->peek_location().end_pos; |
1453 log_->LogFunction(body_start, body_end, | 1443 log_->LogFunction(body_start, body_end, |
1454 function_state_->materialized_literal_count(), | 1444 function_state_->materialized_literal_count(), |
1455 function_state_->expected_properties(), | 1445 function_state_->expected_property_count(), |
1456 scope_->language_mode()); | 1446 scope_->language_mode()); |
1457 } | 1447 } |
1458 | 1448 |
1459 | 1449 |
1460 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { | 1450 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { |
1461 // CallRuntime :: | 1451 // CallRuntime :: |
1462 // '%' Identifier Arguments | 1452 // '%' Identifier Arguments |
1463 Expect(Token::MOD, CHECK_OK); | 1453 Expect(Token::MOD, CHECK_OK); |
1464 if (!allow_natives_syntax()) { | 1454 if (!allow_natives_syntax()) { |
1465 *ok = false; | 1455 *ok = false; |
(...skipping 28 matching lines...) Expand all Loading... |
1494 !scanner()->literal_contains_escapes() && | 1484 !scanner()->literal_contains_escapes() && |
1495 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, | 1485 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, |
1496 kUseStrictLength)) { | 1486 kUseStrictLength)) { |
1497 return Expression::UseStrictStringLiteral(); | 1487 return Expression::UseStrictStringLiteral(); |
1498 } | 1488 } |
1499 return Expression::StringLiteral(); | 1489 return Expression::StringLiteral(); |
1500 } | 1490 } |
1501 | 1491 |
1502 | 1492 |
1503 } } // v8::internal | 1493 } } // v8::internal |
OLD | NEW |