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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 function_state.set_is_generator(is_generator); | 150 function_state.set_is_generator(is_generator); |
151 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); | 151 ASSERT_EQ(Token::LBRACE, scanner()->current_token()); |
152 bool ok = true; | 152 bool ok = true; |
153 int start_position = peek_position(); | 153 int start_position = peek_position(); |
154 ParseLazyFunctionLiteralBody(&ok); | 154 ParseLazyFunctionLiteralBody(&ok); |
155 if (stack_overflow()) return kPreParseStackOverflow; | 155 if (stack_overflow()) return kPreParseStackOverflow; |
156 if (!ok) { | 156 if (!ok) { |
157 ReportUnexpectedToken(scanner()->current_token()); | 157 ReportUnexpectedToken(scanner()->current_token()); |
158 } else { | 158 } else { |
159 ASSERT_EQ(Token::RBRACE, scanner()->peek()); | 159 ASSERT_EQ(Token::RBRACE, scanner()->peek()); |
160 if (!scope_->is_classic_mode()) { | 160 if (!scope_->is_sloppy_mode()) { |
161 int end_pos = scanner()->location().end_pos; | 161 int end_pos = scanner()->location().end_pos; |
162 CheckOctalLiteral(start_position, end_pos, &ok); | 162 CheckOctalLiteral(start_position, end_pos, &ok); |
163 } | 163 } |
164 } | 164 } |
165 return kPreParseSuccess; | 165 return kPreParseSuccess; |
166 } | 166 } |
167 | 167 |
168 | 168 |
169 // Preparsing checks a JavaScript program and emits preparse-data that helps | 169 // Preparsing checks a JavaScript program and emits preparse-data that helps |
170 // a later parsing to be faster. | 170 // a later parsing to be faster. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 case Token::THROW: | 312 case Token::THROW: |
313 return ParseThrowStatement(ok); | 313 return ParseThrowStatement(ok); |
314 | 314 |
315 case Token::TRY: | 315 case Token::TRY: |
316 return ParseTryStatement(ok); | 316 return ParseTryStatement(ok); |
317 | 317 |
318 case Token::FUNCTION: { | 318 case Token::FUNCTION: { |
319 Scanner::Location start_location = scanner()->peek_location(); | 319 Scanner::Location start_location = scanner()->peek_location(); |
320 Statement statement = ParseFunctionDeclaration(CHECK_OK); | 320 Statement statement = ParseFunctionDeclaration(CHECK_OK); |
321 Scanner::Location end_location = scanner()->location(); | 321 Scanner::Location end_location = scanner()->location(); |
322 if (!scope_->is_classic_mode()) { | 322 if (!scope_->is_sloppy_mode()) { |
323 PreParserTraits::ReportMessageAt(start_location.beg_pos, | 323 PreParserTraits::ReportMessageAt(start_location.beg_pos, |
324 end_location.end_pos, | 324 end_location.end_pos, |
325 "strict_function", | 325 "strict_function", |
326 NULL); | 326 NULL); |
327 *ok = false; | 327 *ok = false; |
328 return Statement::Default(); | 328 return Statement::Default(); |
329 } else { | 329 } else { |
330 return statement; | 330 return statement; |
331 } | 331 } |
332 } | 332 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 if (peek() == Token::VAR) { | 423 if (peek() == Token::VAR) { |
424 Consume(Token::VAR); | 424 Consume(Token::VAR); |
425 } else if (peek() == Token::CONST) { | 425 } else if (peek() == Token::CONST) { |
426 // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads: | 426 // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads: |
427 // | 427 // |
428 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' | 428 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' |
429 // | 429 // |
430 // * It is a Syntax Error if the code that matches this production is not | 430 // * It is a Syntax Error if the code that matches this production is not |
431 // contained in extended code. | 431 // contained in extended code. |
432 // | 432 // |
433 // However disallowing const in classic mode will break compatibility with | 433 // However disallowing const in sloppy mode will break compatibility with |
434 // existing pages. Therefore we keep allowing const with the old | 434 // existing pages. Therefore we keep allowing const with the old |
435 // non-harmony semantics in classic mode. | 435 // non-harmony semantics in sloppy mode. |
436 Consume(Token::CONST); | 436 Consume(Token::CONST); |
437 switch (scope_->language_mode()) { | 437 switch (scope_->language_mode()) { |
438 case CLASSIC_MODE: | 438 case SLOPPY_MODE: |
439 break; | 439 break; |
440 case STRICT_MODE: { | 440 case STRICT_MODE: { |
441 Scanner::Location location = scanner()->peek_location(); | 441 Scanner::Location location = scanner()->peek_location(); |
442 ReportMessageAt(location, "strict_const"); | 442 ReportMessageAt(location, "strict_const"); |
443 *ok = false; | 443 *ok = false; |
444 return Statement::Default(); | 444 return Statement::Default(); |
445 } | 445 } |
446 case EXTENDED_MODE: | 446 case EXTENDED_MODE: |
447 if (var_context != kSourceElement && | 447 if (var_context != kSourceElement && |
448 var_context != kForStatement) { | 448 var_context != kForStatement) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 506 |
507 bool starts_with_identifier = peek_any_identifier(); | 507 bool starts_with_identifier = peek_any_identifier(); |
508 Expression expr = ParseExpression(true, CHECK_OK); | 508 Expression expr = ParseExpression(true, CHECK_OK); |
509 // Even if the expression starts with an identifier, it is not necessarily an | 509 // Even if the expression starts with an identifier, it is not necessarily an |
510 // identifier. For example, "foo + bar" starts with an identifier but is not | 510 // identifier. For example, "foo + bar" starts with an identifier but is not |
511 // an identifier. | 511 // an identifier. |
512 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { | 512 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { |
513 // Expression is a single identifier, and not, e.g., a parenthesized | 513 // Expression is a single identifier, and not, e.g., a parenthesized |
514 // identifier. | 514 // identifier. |
515 ASSERT(!expr.AsIdentifier().IsFutureReserved()); | 515 ASSERT(!expr.AsIdentifier().IsFutureReserved()); |
516 ASSERT(scope_->is_classic_mode() || | 516 ASSERT(scope_->is_sloppy_mode() || |
517 (!expr.AsIdentifier().IsFutureStrictReserved() && | 517 (!expr.AsIdentifier().IsFutureStrictReserved() && |
518 !expr.AsIdentifier().IsYield())); | 518 !expr.AsIdentifier().IsYield())); |
519 Consume(Token::COLON); | 519 Consume(Token::COLON); |
520 return ParseStatement(ok); | 520 return ParseStatement(ok); |
521 // Preparsing is disabled for extensions (because the extension details | 521 // Preparsing is disabled for extensions (because the extension details |
522 // aren't passed to lazily compiled functions), so we don't | 522 // aren't passed to lazily compiled functions), so we don't |
523 // accept "native function" in the preparser. | 523 // accept "native function" in the preparser. |
524 } | 524 } |
525 // Parsed expression statement. | 525 // Parsed expression statement. |
526 ExpectSemicolon(CHECK_OK); | 526 ExpectSemicolon(CHECK_OK); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 604 } |
605 ExpectSemicolon(CHECK_OK); | 605 ExpectSemicolon(CHECK_OK); |
606 return Statement::Default(); | 606 return Statement::Default(); |
607 } | 607 } |
608 | 608 |
609 | 609 |
610 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { | 610 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { |
611 // WithStatement :: | 611 // WithStatement :: |
612 // 'with' '(' Expression ')' Statement | 612 // 'with' '(' Expression ')' Statement |
613 Expect(Token::WITH, CHECK_OK); | 613 Expect(Token::WITH, CHECK_OK); |
614 if (!scope_->is_classic_mode()) { | 614 if (!scope_->is_sloppy_mode()) { |
615 ReportMessageAt(scanner()->location(), "strict_mode_with"); | 615 ReportMessageAt(scanner()->location(), "strict_mode_with"); |
616 *ok = false; | 616 *ok = false; |
617 return Statement::Default(); | 617 return Statement::Default(); |
618 } | 618 } |
619 Expect(Token::LPAREN, CHECK_OK); | 619 Expect(Token::LPAREN, CHECK_OK); |
620 ParseExpression(true, CHECK_OK); | 620 ParseExpression(true, CHECK_OK); |
621 Expect(Token::RPAREN, CHECK_OK); | 621 Expect(Token::RPAREN, CHECK_OK); |
622 | 622 |
623 PreParserScope with_scope(scope_, WITH_SCOPE); | 623 PreParserScope with_scope(scope_, WITH_SCOPE); |
624 BlockState block_state(&scope_, &with_scope); | 624 BlockState block_state(&scope_, &with_scope); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 } | 843 } |
844 | 844 |
845 Scanner::Location before = scanner()->peek_location(); | 845 Scanner::Location before = scanner()->peek_location(); |
846 Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK); | 846 Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK); |
847 | 847 |
848 if (!Token::IsAssignmentOp(peek())) { | 848 if (!Token::IsAssignmentOp(peek())) { |
849 // Parsed conditional expression only (no assignment). | 849 // Parsed conditional expression only (no assignment). |
850 return expression; | 850 return expression; |
851 } | 851 } |
852 | 852 |
853 if (!scope_->is_classic_mode() && | 853 if (!scope_->is_sloppy_mode() && |
854 expression.IsIdentifier() && | 854 expression.IsIdentifier() && |
855 expression.AsIdentifier().IsEvalOrArguments()) { | 855 expression.AsIdentifier().IsEvalOrArguments()) { |
856 Scanner::Location after = scanner()->location(); | 856 Scanner::Location after = scanner()->location(); |
857 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | 857 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, |
858 "strict_eval_arguments", NULL); | 858 "strict_eval_arguments", NULL); |
859 *ok = false; | 859 *ok = false; |
860 return Expression::Default(); | 860 return Expression::Default(); |
861 } | 861 } |
862 | 862 |
863 Token::Value op = Next(); // Get assignment operator. | 863 Token::Value op = Next(); // Get assignment operator. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 | 937 |
938 Token::Value op = peek(); | 938 Token::Value op = peek(); |
939 if (Token::IsUnaryOp(op)) { | 939 if (Token::IsUnaryOp(op)) { |
940 op = Next(); | 940 op = Next(); |
941 ParseUnaryExpression(ok); | 941 ParseUnaryExpression(ok); |
942 return Expression::Default(); | 942 return Expression::Default(); |
943 } else if (Token::IsCountOp(op)) { | 943 } else if (Token::IsCountOp(op)) { |
944 op = Next(); | 944 op = Next(); |
945 Scanner::Location before = scanner()->peek_location(); | 945 Scanner::Location before = scanner()->peek_location(); |
946 Expression expression = ParseUnaryExpression(CHECK_OK); | 946 Expression expression = ParseUnaryExpression(CHECK_OK); |
947 if (!scope_->is_classic_mode() && | 947 if (!scope_->is_sloppy_mode() && |
948 expression.IsIdentifier() && | 948 expression.IsIdentifier() && |
949 expression.AsIdentifier().IsEvalOrArguments()) { | 949 expression.AsIdentifier().IsEvalOrArguments()) { |
950 Scanner::Location after = scanner()->location(); | 950 Scanner::Location after = scanner()->location(); |
951 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | 951 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, |
952 "strict_eval_arguments", NULL); | 952 "strict_eval_arguments", NULL); |
953 *ok = false; | 953 *ok = false; |
954 } | 954 } |
955 return Expression::Default(); | 955 return Expression::Default(); |
956 } else { | 956 } else { |
957 return ParsePostfixExpression(ok); | 957 return ParsePostfixExpression(ok); |
958 } | 958 } |
959 } | 959 } |
960 | 960 |
961 | 961 |
962 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { | 962 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { |
963 // PostfixExpression :: | 963 // PostfixExpression :: |
964 // LeftHandSideExpression ('++' | '--')? | 964 // LeftHandSideExpression ('++' | '--')? |
965 | 965 |
966 Scanner::Location before = scanner()->peek_location(); | 966 Scanner::Location before = scanner()->peek_location(); |
967 Expression expression = ParseLeftHandSideExpression(CHECK_OK); | 967 Expression expression = ParseLeftHandSideExpression(CHECK_OK); |
968 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 968 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
969 Token::IsCountOp(peek())) { | 969 Token::IsCountOp(peek())) { |
970 if (!scope_->is_classic_mode() && | 970 if (!scope_->is_sloppy_mode() && |
971 expression.IsIdentifier() && | 971 expression.IsIdentifier() && |
972 expression.AsIdentifier().IsEvalOrArguments()) { | 972 expression.AsIdentifier().IsEvalOrArguments()) { |
973 Scanner::Location after = scanner()->location(); | 973 Scanner::Location after = scanner()->location(); |
974 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | 974 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, |
975 "strict_eval_arguments", NULL); | 975 "strict_eval_arguments", NULL); |
976 *ok = false; | 976 *ok = false; |
977 return Expression::Default(); | 977 return Expression::Default(); |
978 } | 978 } |
979 Next(); | 979 Next(); |
980 return Expression::Default(); | 980 return Expression::Default(); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 Expect(Token::LBRACE, CHECK_OK); | 1295 Expect(Token::LBRACE, CHECK_OK); |
1296 if (is_lazily_parsed) { | 1296 if (is_lazily_parsed) { |
1297 ParseLazyFunctionLiteralBody(CHECK_OK); | 1297 ParseLazyFunctionLiteralBody(CHECK_OK); |
1298 } else { | 1298 } else { |
1299 ParseSourceElements(Token::RBRACE, ok); | 1299 ParseSourceElements(Token::RBRACE, ok); |
1300 } | 1300 } |
1301 Expect(Token::RBRACE, CHECK_OK); | 1301 Expect(Token::RBRACE, CHECK_OK); |
1302 | 1302 |
1303 // Validate strict mode. We can do this only after parsing the function, | 1303 // Validate strict mode. We can do this only after parsing the function, |
1304 // since the function can declare itself strict. | 1304 // since the function can declare itself strict. |
1305 if (!scope_->is_classic_mode()) { | 1305 if (!scope_->is_sloppy_mode()) { |
1306 if (function_name.IsEvalOrArguments()) { | 1306 if (function_name.IsEvalOrArguments()) { |
1307 ReportMessageAt(function_name_location, "strict_eval_arguments"); | 1307 ReportMessageAt(function_name_location, "strict_eval_arguments"); |
1308 *ok = false; | 1308 *ok = false; |
1309 return Expression::Default(); | 1309 return Expression::Default(); |
1310 } | 1310 } |
1311 if (name_is_strict_reserved) { | 1311 if (name_is_strict_reserved) { |
1312 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); | 1312 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); |
1313 *ok = false; | 1313 *ok = false; |
1314 return Expression::Default(); | 1314 return Expression::Default(); |
1315 } | 1315 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 int identifier_pos = position(); | 1377 int identifier_pos = position(); |
1378 if (scanner()->is_literal_ascii()) { | 1378 if (scanner()->is_literal_ascii()) { |
1379 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); | 1379 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); |
1380 } else { | 1380 } else { |
1381 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); | 1381 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); |
1382 } | 1382 } |
1383 } | 1383 } |
1384 | 1384 |
1385 | 1385 |
1386 } } // v8::internal | 1386 } } // v8::internal |
OLD | NEW |