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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 return ParseStatement(ok); | 161 return ParseStatement(ok); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 | 165 |
166 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, | 166 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, |
167 bool* ok) { | 167 bool* ok) { |
168 // SourceElements :: | 168 // SourceElements :: |
169 // (Statement)* <end_token> | 169 // (Statement)* <end_token> |
170 | 170 |
171 bool allow_directive_prologue = true; | 171 bool directive_prologue = true; |
172 while (peek() != end_token) { | 172 while (peek() != end_token) { |
| 173 if (directive_prologue && peek() != Token::STRING) { |
| 174 directive_prologue = false; |
| 175 } |
173 Statement statement = ParseSourceElement(CHECK_OK); | 176 Statement statement = ParseSourceElement(CHECK_OK); |
174 if (allow_directive_prologue) { | 177 if (directive_prologue) { |
175 if (statement.IsUseStrictLiteral()) { | 178 if (statement.IsUseStrictLiteral()) { |
176 set_language_mode(allow_harmony_scoping() ? | 179 set_language_mode(allow_harmony_scoping() ? |
177 EXTENDED_MODE : STRICT_MODE); | 180 EXTENDED_MODE : STRICT_MODE); |
178 } else if (!statement.IsStringLiteral()) { | 181 } else if (!statement.IsStringLiteral()) { |
179 allow_directive_prologue = false; | 182 directive_prologue = false; |
180 } | 183 } |
181 } | 184 } |
182 } | 185 } |
183 return kUnknownSourceElements; | 186 return kUnknownSourceElements; |
184 } | 187 } |
185 | 188 |
186 | 189 |
187 #undef CHECK_OK | 190 #undef CHECK_OK |
188 #define CHECK_OK ok); \ | 191 #define CHECK_OK ok); \ |
189 if (!*ok) return Statement::Default(); \ | 192 if (!*ok) return Statement::Default(); \ |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 if (num_decl != NULL) *num_decl = nvars; | 464 if (num_decl != NULL) *num_decl = nvars; |
462 return Statement::Default(); | 465 return Statement::Default(); |
463 } | 466 } |
464 | 467 |
465 | 468 |
466 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 469 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
467 // ExpressionStatement | LabelledStatement :: | 470 // ExpressionStatement | LabelledStatement :: |
468 // Expression ';' | 471 // Expression ';' |
469 // Identifier ':' Statement | 472 // Identifier ':' Statement |
470 | 473 |
| 474 bool starts_with_identifier = peek_any_identifier(); |
471 Expression expr = ParseExpression(true, CHECK_OK); | 475 Expression expr = ParseExpression(true, CHECK_OK); |
472 if (expr.IsRawIdentifier()) { | 476 // Even if the expression starts with an identifier, it is not necessarily an |
| 477 // identifier. For example, "foo + bar" starts with an identifier but is not |
| 478 // an identifier. |
| 479 if (peek() == Token::COLON && starts_with_identifier && expr.IsIdentifier()) { |
| 480 // Expression is a single identifier, and not, e.g., a parenthesized |
| 481 // identifier. |
473 ASSERT(!expr.AsIdentifier().IsFutureReserved()); | 482 ASSERT(!expr.AsIdentifier().IsFutureReserved()); |
474 ASSERT(is_classic_mode() || | 483 ASSERT(is_classic_mode() || |
475 (!expr.AsIdentifier().IsFutureStrictReserved() && | 484 (!expr.AsIdentifier().IsFutureStrictReserved() && |
476 !expr.AsIdentifier().IsYield())); | 485 !expr.AsIdentifier().IsYield())); |
477 if (peek() == Token::COLON) { | 486 Consume(Token::COLON); |
478 Consume(Token::COLON); | 487 return ParseStatement(ok); |
479 return ParseStatement(ok); | |
480 } | |
481 // Preparsing is disabled for extensions (because the extension details | 488 // Preparsing is disabled for extensions (because the extension details |
482 // aren't passed to lazily compiled functions), so we don't | 489 // aren't passed to lazily compiled functions), so we don't |
483 // accept "native function" in the preparser. | 490 // accept "native function" in the preparser. |
484 } | 491 } |
485 // Parsed expression statement. | 492 // Parsed expression statement. |
486 ExpectSemicolon(CHECK_OK); | 493 ExpectSemicolon(CHECK_OK); |
487 return Statement::ExpressionStatement(expr); | 494 return Statement::ExpressionStatement(expr); |
488 } | 495 } |
489 | 496 |
490 | 497 |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 | 1170 |
1164 case Token::LBRACE: | 1171 case Token::LBRACE: |
1165 result = ParseObjectLiteral(CHECK_OK); | 1172 result = ParseObjectLiteral(CHECK_OK); |
1166 break; | 1173 break; |
1167 | 1174 |
1168 case Token::LPAREN: | 1175 case Token::LPAREN: |
1169 Consume(Token::LPAREN); | 1176 Consume(Token::LPAREN); |
1170 parenthesized_function_ = (peek() == Token::FUNCTION); | 1177 parenthesized_function_ = (peek() == Token::FUNCTION); |
1171 result = ParseExpression(true, CHECK_OK); | 1178 result = ParseExpression(true, CHECK_OK); |
1172 Expect(Token::RPAREN, CHECK_OK); | 1179 Expect(Token::RPAREN, CHECK_OK); |
1173 result = result.Parenthesize(); | |
1174 break; | 1180 break; |
1175 | 1181 |
1176 case Token::MOD: | 1182 case Token::MOD: |
1177 result = ParseV8Intrinsic(CHECK_OK); | 1183 result = ParseV8Intrinsic(CHECK_OK); |
1178 break; | 1184 break; |
1179 | 1185 |
1180 default: { | 1186 default: { |
1181 Token::Value next = Next(); | 1187 Token::Value next = Next(); |
1182 ReportUnexpectedToken(next); | 1188 ReportUnexpectedToken(next); |
1183 *ok = false; | 1189 *ok = false; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1625 ASSERT(IsAccessorAccessorConflict(old_type, type)); | 1631 ASSERT(IsAccessorAccessorConflict(old_type, type)); |
1626 // Both accessors of the same type. | 1632 // Both accessors of the same type. |
1627 parser()->ReportMessageAt(scanner()->location(), | 1633 parser()->ReportMessageAt(scanner()->location(), |
1628 "accessor_get_set"); | 1634 "accessor_get_set"); |
1629 } | 1635 } |
1630 *ok = false; | 1636 *ok = false; |
1631 } | 1637 } |
1632 } | 1638 } |
1633 | 1639 |
1634 } } // v8::internal | 1640 } } // v8::internal |
OLD | NEW |