OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_PREPARSER_H | 28 #ifndef V8_PREPARSER_H |
29 #define V8_PREPARSER_H | 29 #define V8_PREPARSER_H |
30 | 30 |
31 #include "unicode.h" | 31 #include "unicode.h" |
| 32 #include "utils.h" |
32 | 33 |
33 namespace v8 { | 34 namespace v8 { |
34 namespace preparser { | 35 namespace preparser { |
35 | 36 |
36 // Preparsing checks a JavaScript program and emits preparse-data that helps | 37 // Preparsing checks a JavaScript program and emits preparse-data that helps |
37 // a later parsing to be faster. | 38 // a later parsing to be faster. |
38 // See preparser-data.h for the data. | 39 // See preparser-data.h for the data. |
39 | 40 |
40 // The PreParser checks that the syntax follows the grammar for JavaScript, | 41 // The PreParser checks that the syntax follows the grammar for JavaScript, |
41 // and collects some information about the program along the way. | 42 // and collects some information about the program along the way. |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 | 744 |
744 // In preparsing, allow any number of catch/finally blocks, including zero | 745 // In preparsing, allow any number of catch/finally blocks, including zero |
745 // of both. | 746 // of both. |
746 | 747 |
747 Expect(i::Token::TRY, CHECK_OK); | 748 Expect(i::Token::TRY, CHECK_OK); |
748 | 749 |
749 ParseBlock(CHECK_OK); | 750 ParseBlock(CHECK_OK); |
750 | 751 |
751 bool catch_or_finally_seen = false; | 752 bool catch_or_finally_seen = false; |
752 if (peek() == i::Token::CATCH) { | 753 if (peek() == i::Token::CATCH) { |
753 Expect(i::Token::CATCH, CHECK_OK); | 754 Consume(i::Token::CATCH); |
754 Expect(i::Token::LPAREN, CHECK_OK); | 755 Expect(i::Token::LPAREN, CHECK_OK); |
755 ParseIdentifier(CHECK_OK); | 756 ParseIdentifier(CHECK_OK); |
756 Expect(i::Token::RPAREN, CHECK_OK); | 757 Expect(i::Token::RPAREN, CHECK_OK); |
| 758 scope_->EnterWith(); |
| 759 ParseBlock(ok); |
| 760 scope_->LeaveWith(); |
| 761 if (!*ok) return kUnknownStatement; |
| 762 catch_or_finally_seen = true; |
| 763 } |
| 764 if (peek() == i::Token::FINALLY) { |
| 765 Consume(i::Token::FINALLY); |
757 ParseBlock(CHECK_OK); | 766 ParseBlock(CHECK_OK); |
758 catch_or_finally_seen = true; | 767 catch_or_finally_seen = true; |
759 } | 768 } |
760 if (peek() == i::Token::FINALLY) { | |
761 Expect(i::Token::FINALLY, CHECK_OK); | |
762 ParseBlock(CHECK_OK); | |
763 catch_or_finally_seen = true; | |
764 } | |
765 if (!catch_or_finally_seen) { | 769 if (!catch_or_finally_seen) { |
766 *ok = false; | 770 *ok = false; |
767 } | 771 } |
768 return kUnknownStatement; | 772 return kUnknownStatement; |
769 } | 773 } |
770 | 774 |
771 | 775 |
772 template <typename Scanner, typename Log> | 776 template <typename Scanner, typename Log> |
773 Statement PreParser<Scanner, Log>::ParseDebuggerStatement(bool* ok) { | 777 Statement PreParser<Scanner, Log>::ParseDebuggerStatement(bool* ok) { |
774 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser | 778 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 int literal_position = scanner_->location().beg_pos; | 1367 int literal_position = scanner_->location().beg_pos; |
1364 log_->LogSymbol(literal_position, literal_chars, literal_length); | 1368 log_->LogSymbol(literal_position, literal_chars, literal_length); |
1365 | 1369 |
1366 return kUnknownExpression; | 1370 return kUnknownExpression; |
1367 } | 1371 } |
1368 | 1372 |
1369 | 1373 |
1370 template <typename Scanner, typename Log> | 1374 template <typename Scanner, typename Log> |
1371 Identifier PreParser<Scanner, Log>::ParseIdentifier(bool* ok) { | 1375 Identifier PreParser<Scanner, Log>::ParseIdentifier(bool* ok) { |
1372 Expect(i::Token::IDENTIFIER, ok); | 1376 Expect(i::Token::IDENTIFIER, ok); |
| 1377 if (!*ok) return kUnknownIdentifier; |
1373 return GetIdentifierSymbol(); | 1378 return GetIdentifierSymbol(); |
1374 } | 1379 } |
1375 | 1380 |
1376 | 1381 |
1377 template <typename Scanner, typename Log> | 1382 template <typename Scanner, typename Log> |
1378 Identifier PreParser<Scanner, Log>::ParseIdentifierName(bool* ok) { | 1383 Identifier PreParser<Scanner, Log>::ParseIdentifierName(bool* ok) { |
1379 i::Token::Value next = Next(); | 1384 i::Token::Value next = Next(); |
1380 if (i::Token::IsKeyword(next)) { | 1385 if (i::Token::IsKeyword(next)) { |
1381 int pos = scanner_->location().beg_pos; | 1386 int pos = scanner_->location().beg_pos; |
1382 const char* keyword = i::Token::String(next); | 1387 const char* keyword = i::Token::String(next); |
1383 log_->LogSymbol(pos, keyword, strlen(keyword)); | 1388 log_->LogSymbol(pos, keyword, i::StrLength(keyword)); |
1384 return kUnknownExpression; | 1389 return kUnknownExpression; |
1385 } | 1390 } |
1386 if (next == i::Token::IDENTIFIER) { | 1391 if (next == i::Token::IDENTIFIER) { |
1387 return GetIdentifierSymbol(); | 1392 return GetIdentifierSymbol(); |
1388 } | 1393 } |
1389 *ok = false; | 1394 *ok = false; |
1390 return kUnknownIdentifier; | 1395 return kUnknownIdentifier; |
1391 } | 1396 } |
1392 | 1397 |
1393 | 1398 |
(...skipping 11 matching lines...) Expand all Loading... |
1405 *is_get = strncmp(token, "get", 3) == 0; | 1410 *is_get = strncmp(token, "get", 3) == 0; |
1406 *is_set = !*is_get && strncmp(token, "set", 3) == 0; | 1411 *is_set = !*is_get && strncmp(token, "set", 3) == 0; |
1407 } | 1412 } |
1408 return GetIdentifierSymbol(); | 1413 return GetIdentifierSymbol(); |
1409 } | 1414 } |
1410 | 1415 |
1411 #undef CHECK_OK | 1416 #undef CHECK_OK |
1412 } } // v8::preparser | 1417 } } // v8::preparser |
1413 | 1418 |
1414 #endif // V8_PREPARSER_H | 1419 #endif // V8_PREPARSER_H |
OLD | NEW |