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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 | 111 |
112 #define CHECK_OK ok); \ | 112 #define CHECK_OK ok); \ |
113 if (!*ok) return kUnknownSourceElements; \ | 113 if (!*ok) return kUnknownSourceElements; \ |
114 ((void)0 | 114 ((void)0 |
115 #define DUMMY ) // to make indentation work | 115 #define DUMMY ) // to make indentation work |
116 #undef DUMMY | 116 #undef DUMMY |
117 | 117 |
118 | 118 |
119 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { | 119 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { |
| 120 // (Ecma 262 5th Edition, clause 14): |
| 121 // SourceElement: |
| 122 // Statement |
| 123 // FunctionDeclaration |
| 124 // |
| 125 // In harmony mode we allow additionally the following productions |
| 126 // SourceElement: |
| 127 // LetDeclaration |
| 128 |
120 switch (peek()) { | 129 switch (peek()) { |
| 130 case i::Token::FUNCTION: |
| 131 return ParseFunctionDeclaration(ok); |
121 case i::Token::LET: | 132 case i::Token::LET: |
122 return ParseVariableStatement(kSourceElement, ok); | 133 return ParseVariableStatement(kSourceElement, ok); |
123 default: | 134 default: |
124 return ParseStatement(ok); | 135 return ParseStatement(ok); |
125 } | 136 } |
126 } | 137 } |
127 | 138 |
128 | 139 |
129 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, | 140 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, |
130 bool* ok) { | 141 bool* ok) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 229 |
219 case i::Token::SWITCH: | 230 case i::Token::SWITCH: |
220 return ParseSwitchStatement(ok); | 231 return ParseSwitchStatement(ok); |
221 | 232 |
222 case i::Token::THROW: | 233 case i::Token::THROW: |
223 return ParseThrowStatement(ok); | 234 return ParseThrowStatement(ok); |
224 | 235 |
225 case i::Token::TRY: | 236 case i::Token::TRY: |
226 return ParseTryStatement(ok); | 237 return ParseTryStatement(ok); |
227 | 238 |
228 case i::Token::FUNCTION: | 239 case i::Token::FUNCTION: { |
229 return ParseFunctionDeclaration(ok); | 240 i::Scanner::Location start_location = scanner_->peek_location(); |
| 241 Statement statement = ParseFunctionDeclaration(CHECK_OK); |
| 242 i::Scanner::Location end_location = scanner_->location(); |
| 243 if (strict_mode()) { |
| 244 ReportMessageAt(start_location.beg_pos, end_location.end_pos, |
| 245 "strict_function", NULL); |
| 246 *ok = false; |
| 247 return Statement::Default(); |
| 248 } else { |
| 249 return statement; |
| 250 } |
| 251 } |
230 | 252 |
231 case i::Token::DEBUGGER: | 253 case i::Token::DEBUGGER: |
232 return ParseDebuggerStatement(ok); | 254 return ParseDebuggerStatement(ok); |
233 | 255 |
234 default: | 256 default: |
235 return ParseExpressionOrLabelledStatement(ok); | 257 return ParseExpressionOrLabelledStatement(ok); |
236 } | 258 } |
237 } | 259 } |
238 | 260 |
239 | 261 |
(...skipping 24 matching lines...) Expand all Loading... |
264 | 286 |
265 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 287 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
266 // Block :: | 288 // Block :: |
267 // '{' Statement* '}' | 289 // '{' Statement* '}' |
268 | 290 |
269 // Note that a Block does not introduce a new execution scope! | 291 // Note that a Block does not introduce a new execution scope! |
270 // (ECMA-262, 3rd, 12.2) | 292 // (ECMA-262, 3rd, 12.2) |
271 // | 293 // |
272 Expect(i::Token::LBRACE, CHECK_OK); | 294 Expect(i::Token::LBRACE, CHECK_OK); |
273 while (peek() != i::Token::RBRACE) { | 295 while (peek() != i::Token::RBRACE) { |
274 i::Scanner::Location start_location = scanner_->peek_location(); | 296 if (harmony_block_scoping_) { |
275 Statement statement = ParseSourceElement(CHECK_OK); | 297 ParseSourceElement(CHECK_OK); |
276 i::Scanner::Location end_location = scanner_->location(); | 298 } else { |
277 if (strict_mode() && statement.IsFunctionDeclaration()) { | 299 ParseStatement(CHECK_OK); |
278 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | |
279 "strict_function", NULL); | |
280 *ok = false; | |
281 return Statement::Default(); | |
282 } | 300 } |
283 } | 301 } |
284 Expect(i::Token::RBRACE, ok); | 302 Expect(i::Token::RBRACE, ok); |
285 return Statement::Default(); | 303 return Statement::Default(); |
286 } | 304 } |
287 | 305 |
288 | 306 |
289 PreParser::Statement PreParser::ParseVariableStatement( | 307 PreParser::Statement PreParser::ParseVariableStatement( |
290 VariableDeclarationContext var_context, | 308 VariableDeclarationContext var_context, |
291 bool* ok) { | 309 bool* ok) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 } | 383 } |
366 | 384 |
367 | 385 |
368 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 386 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
369 // ExpressionStatement | LabelledStatement :: | 387 // ExpressionStatement | LabelledStatement :: |
370 // Expression ';' | 388 // Expression ';' |
371 // Identifier ':' Statement | 389 // Identifier ':' Statement |
372 | 390 |
373 Expression expr = ParseExpression(true, CHECK_OK); | 391 Expression expr = ParseExpression(true, CHECK_OK); |
374 if (expr.IsRawIdentifier()) { | 392 if (expr.IsRawIdentifier()) { |
375 if (peek() == i::Token::COLON && | 393 ASSERT(!expr.AsIdentifier().IsFutureReserved()); |
376 (!strict_mode() || !expr.AsIdentifier().IsFutureReserved())) { | 394 ASSERT(!strict_mode() || !expr.AsIdentifier().IsFutureStrictReserved()); |
| 395 if (peek() == i::Token::COLON) { |
377 Consume(i::Token::COLON); | 396 Consume(i::Token::COLON); |
378 i::Scanner::Location start_location = scanner_->peek_location(); | 397 return ParseStatement(ok); |
379 Statement statement = ParseStatement(CHECK_OK); | |
380 if (strict_mode() && statement.IsFunctionDeclaration()) { | |
381 i::Scanner::Location end_location = scanner_->location(); | |
382 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | |
383 "strict_function", NULL); | |
384 *ok = false; | |
385 } | |
386 return Statement::Default(); | |
387 } | 398 } |
388 // Preparsing is disabled for extensions (because the extension details | 399 // Preparsing is disabled for extensions (because the extension details |
389 // aren't passed to lazily compiled functions), so we don't | 400 // aren't passed to lazily compiled functions), so we don't |
390 // accept "native function" in the preparser. | 401 // accept "native function" in the preparser. |
391 } | 402 } |
392 // Parsed expression statement. | 403 // Parsed expression statement. |
393 ExpectSemicolon(CHECK_OK); | 404 ExpectSemicolon(CHECK_OK); |
394 return Statement::ExpressionStatement(expr); | 405 return Statement::ExpressionStatement(expr); |
395 } | 406 } |
396 | 407 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 i::Token::Value token = peek(); | 517 i::Token::Value token = peek(); |
507 while (token != i::Token::RBRACE) { | 518 while (token != i::Token::RBRACE) { |
508 if (token == i::Token::CASE) { | 519 if (token == i::Token::CASE) { |
509 Expect(i::Token::CASE, CHECK_OK); | 520 Expect(i::Token::CASE, CHECK_OK); |
510 ParseExpression(true, CHECK_OK); | 521 ParseExpression(true, CHECK_OK); |
511 Expect(i::Token::COLON, CHECK_OK); | 522 Expect(i::Token::COLON, CHECK_OK); |
512 } else if (token == i::Token::DEFAULT) { | 523 } else if (token == i::Token::DEFAULT) { |
513 Expect(i::Token::DEFAULT, CHECK_OK); | 524 Expect(i::Token::DEFAULT, CHECK_OK); |
514 Expect(i::Token::COLON, CHECK_OK); | 525 Expect(i::Token::COLON, CHECK_OK); |
515 } else { | 526 } else { |
516 i::Scanner::Location start_location = scanner_->peek_location(); | 527 ParseStatement(CHECK_OK); |
517 Statement statement = ParseStatement(CHECK_OK); | |
518 if (strict_mode() && statement.IsFunctionDeclaration()) { | |
519 i::Scanner::Location end_location = scanner_->location(); | |
520 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | |
521 "strict_function", NULL); | |
522 *ok = false; | |
523 return Statement::Default(); | |
524 } | |
525 } | 528 } |
526 token = peek(); | 529 token = peek(); |
527 } | 530 } |
528 Expect(i::Token::RBRACE, ok); | 531 Expect(i::Token::RBRACE, ok); |
529 return Statement::Default(); | 532 return Statement::Default(); |
530 } | 533 } |
531 | 534 |
532 | 535 |
533 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { | 536 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { |
534 // DoStatement :: | 537 // DoStatement :: |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 | 1430 |
1428 | 1431 |
1429 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { | 1432 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { |
1430 i::Token::Value next = Next(); | 1433 i::Token::Value next = Next(); |
1431 switch (next) { | 1434 switch (next) { |
1432 case i::Token::FUTURE_RESERVED_WORD: { | 1435 case i::Token::FUTURE_RESERVED_WORD: { |
1433 i::Scanner::Location location = scanner_->location(); | 1436 i::Scanner::Location location = scanner_->location(); |
1434 ReportMessageAt(location.beg_pos, location.end_pos, | 1437 ReportMessageAt(location.beg_pos, location.end_pos, |
1435 "reserved_word", NULL); | 1438 "reserved_word", NULL); |
1436 *ok = false; | 1439 *ok = false; |
| 1440 return GetIdentifierSymbol(); |
1437 } | 1441 } |
| 1442 case i::Token::FUTURE_STRICT_RESERVED_WORD: |
| 1443 if (strict_mode()) { |
| 1444 i::Scanner::Location location = scanner_->location(); |
| 1445 ReportMessageAt(location.beg_pos, location.end_pos, |
| 1446 "strict_reserved_word", NULL); |
| 1447 *ok = false; |
| 1448 } |
1438 // FALLTHROUGH | 1449 // FALLTHROUGH |
1439 case i::Token::FUTURE_STRICT_RESERVED_WORD: | |
1440 case i::Token::IDENTIFIER: | 1450 case i::Token::IDENTIFIER: |
1441 return GetIdentifierSymbol(); | 1451 return GetIdentifierSymbol(); |
1442 default: | 1452 default: |
1443 *ok = false; | 1453 *ok = false; |
1444 return Identifier::Default(); | 1454 return Identifier::Default(); |
1445 } | 1455 } |
1446 } | 1456 } |
1447 | 1457 |
1448 | 1458 |
1449 void PreParser::SetStrictModeViolation(i::Scanner::Location location, | 1459 void PreParser::SetStrictModeViolation(i::Scanner::Location location, |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); | 1680 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
1671 } | 1681 } |
1672 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1682 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
1673 } | 1683 } |
1674 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1684 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
1675 | 1685 |
1676 backing_store_.AddBlock(bytes); | 1686 backing_store_.AddBlock(bytes); |
1677 return backing_store_.EndSequence().start(); | 1687 return backing_store_.EndSequence().start(); |
1678 } | 1688 } |
1679 } } // v8::preparser | 1689 } } // v8::preparser |
OLD | NEW |