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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 305 |
306 | 306 |
307 PreParser::Statement PreParser::ParseVariableStatement( | 307 PreParser::Statement PreParser::ParseVariableStatement( |
308 VariableDeclarationContext var_context, | 308 VariableDeclarationContext var_context, |
309 bool* ok) { | 309 bool* ok) { |
310 // VariableStatement :: | 310 // VariableStatement :: |
311 // VariableDeclarations ';' | 311 // VariableDeclarations ';' |
312 | 312 |
313 Statement result = ParseVariableDeclarations(var_context, | 313 Statement result = ParseVariableDeclarations(var_context, |
314 NULL, | 314 NULL, |
| 315 NULL, |
315 CHECK_OK); | 316 CHECK_OK); |
316 ExpectSemicolon(CHECK_OK); | 317 ExpectSemicolon(CHECK_OK); |
317 return result; | 318 return result; |
318 } | 319 } |
319 | 320 |
320 | 321 |
321 // If the variable declaration declares exactly one non-const | 322 // If the variable declaration declares exactly one non-const |
322 // variable, then *var is set to that variable. In all other cases, | 323 // variable, then *var is set to that variable. In all other cases, |
323 // *var is untouched; in particular, it is the caller's responsibility | 324 // *var is untouched; in particular, it is the caller's responsibility |
324 // to initialize it properly. This mechanism is also used for the parsing | 325 // to initialize it properly. This mechanism is also used for the parsing |
325 // of 'for-in' loops. | 326 // of 'for-in' loops. |
326 PreParser::Statement PreParser::ParseVariableDeclarations( | 327 PreParser::Statement PreParser::ParseVariableDeclarations( |
327 VariableDeclarationContext var_context, | 328 VariableDeclarationContext var_context, |
| 329 VariableDeclarationProperties* decl_props, |
328 int* num_decl, | 330 int* num_decl, |
329 bool* ok) { | 331 bool* ok) { |
330 // VariableDeclarations :: | 332 // VariableDeclarations :: |
331 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] | 333 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] |
332 | 334 |
333 if (peek() == i::Token::VAR) { | 335 if (peek() == i::Token::VAR) { |
334 Consume(i::Token::VAR); | 336 Consume(i::Token::VAR); |
335 } else if (peek() == i::Token::CONST) { | 337 } else if (peek() == i::Token::CONST) { |
336 if (strict_mode()) { | 338 if (strict_mode()) { |
337 i::Scanner::Location location = scanner_->peek_location(); | 339 i::Scanner::Location location = scanner_->peek_location(); |
(...skipping 30 matching lines...) Expand all Loading... |
368 StrictModeIdentifierViolation(scanner_->location(), | 370 StrictModeIdentifierViolation(scanner_->location(), |
369 "strict_var_name", | 371 "strict_var_name", |
370 identifier, | 372 identifier, |
371 ok); | 373 ok); |
372 return Statement::Default(); | 374 return Statement::Default(); |
373 } | 375 } |
374 nvars++; | 376 nvars++; |
375 if (peek() == i::Token::ASSIGN) { | 377 if (peek() == i::Token::ASSIGN) { |
376 Expect(i::Token::ASSIGN, CHECK_OK); | 378 Expect(i::Token::ASSIGN, CHECK_OK); |
377 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); | 379 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); |
| 380 if (decl_props != NULL) *decl_props = kHasInitializers; |
378 } | 381 } |
379 } while (peek() == i::Token::COMMA); | 382 } while (peek() == i::Token::COMMA); |
380 | 383 |
381 if (num_decl != NULL) *num_decl = nvars; | 384 if (num_decl != NULL) *num_decl = nvars; |
382 return Statement::Default(); | 385 return Statement::Default(); |
383 } | 386 } |
384 | 387 |
385 | 388 |
386 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 389 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
387 // ExpressionStatement | LabelledStatement :: | 390 // ExpressionStatement | LabelledStatement :: |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 | 565 |
563 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 566 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
564 // ForStatement :: | 567 // ForStatement :: |
565 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 568 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
566 | 569 |
567 Expect(i::Token::FOR, CHECK_OK); | 570 Expect(i::Token::FOR, CHECK_OK); |
568 Expect(i::Token::LPAREN, CHECK_OK); | 571 Expect(i::Token::LPAREN, CHECK_OK); |
569 if (peek() != i::Token::SEMICOLON) { | 572 if (peek() != i::Token::SEMICOLON) { |
570 if (peek() == i::Token::VAR || peek() == i::Token::CONST || | 573 if (peek() == i::Token::VAR || peek() == i::Token::CONST || |
571 peek() == i::Token::LET) { | 574 peek() == i::Token::LET) { |
| 575 bool is_let = peek() == i::Token::LET; |
572 int decl_count; | 576 int decl_count; |
573 ParseVariableDeclarations(kForStatement, &decl_count, CHECK_OK); | 577 VariableDeclarationProperties decl_props = kHasNoInitializers; |
574 if (peek() == i::Token::IN && decl_count == 1) { | 578 ParseVariableDeclarations( |
| 579 kForStatement, &decl_props, &decl_count, CHECK_OK); |
| 580 bool accept_IN = decl_count == 1 && |
| 581 !(is_let && decl_props == kHasInitializers); |
| 582 if (peek() == i::Token::IN && accept_IN) { |
575 Expect(i::Token::IN, CHECK_OK); | 583 Expect(i::Token::IN, CHECK_OK); |
576 ParseExpression(true, CHECK_OK); | 584 ParseExpression(true, CHECK_OK); |
577 Expect(i::Token::RPAREN, CHECK_OK); | 585 Expect(i::Token::RPAREN, CHECK_OK); |
578 | 586 |
579 ParseStatement(CHECK_OK); | 587 ParseStatement(CHECK_OK); |
580 return Statement::Default(); | 588 return Statement::Default(); |
581 } | 589 } |
582 } else { | 590 } else { |
583 ParseExpression(false, CHECK_OK); | 591 ParseExpression(false, CHECK_OK); |
584 if (peek() == i::Token::IN) { | 592 if (peek() == i::Token::IN) { |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); | 1688 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
1681 } | 1689 } |
1682 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1690 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
1683 } | 1691 } |
1684 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1692 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
1685 | 1693 |
1686 backing_store_.AddBlock(bytes); | 1694 backing_store_.AddBlock(bytes); |
1687 return backing_store_.EndSequence().start(); | 1695 return backing_store_.EndSequence().start(); |
1688 } | 1696 } |
1689 } } // v8::preparser | 1697 } } // v8::preparser |
OLD | NEW |