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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 unsigned ScriptDataImpl::Read(int position) { | 400 unsigned ScriptDataImpl::Read(int position) { |
401 return store_[PreparseDataConstants::kHeaderSize + position]; | 401 return store_[PreparseDataConstants::kHeaderSize + position]; |
402 } | 402 } |
403 | 403 |
404 | 404 |
405 unsigned* ScriptDataImpl::ReadAddress(int position) { | 405 unsigned* ScriptDataImpl::ReadAddress(int position) { |
406 return &store_[PreparseDataConstants::kHeaderSize + position]; | 406 return &store_[PreparseDataConstants::kHeaderSize + position]; |
407 } | 407 } |
408 | 408 |
409 | 409 |
410 Scope* Parser::NewScope(Scope* parent, ScopeType type) { | 410 Scope* Parser::NewScope(Scope* parent, Scope::Type type) { |
411 Scope* result = new(zone()) Scope(parent, type); | 411 Scope* result = new(zone()) Scope(parent, type); |
412 result->Initialize(); | 412 result->Initialize(); |
413 return result; | 413 return result; |
414 } | 414 } |
415 | 415 |
416 | 416 |
417 // ---------------------------------------------------------------------------- | 417 // ---------------------------------------------------------------------------- |
418 // Target is a support class to facilitate manipulation of the | 418 // Target is a support class to facilitate manipulation of the |
419 // Parser's target_stack_ (the stack of potential 'break' and | 419 // Parser's target_stack_ (the stack of potential 'break' and |
420 // 'continue' statement targets). Upon construction, a new target is | 420 // 'continue' statement targets). Upon construction, a new target is |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 bool in_global_context, | 636 bool in_global_context, |
637 StrictModeFlag strict_mode, | 637 StrictModeFlag strict_mode, |
638 ZoneScope* zone_scope) { | 638 ZoneScope* zone_scope) { |
639 ASSERT(target_stack_ == NULL); | 639 ASSERT(target_stack_ == NULL); |
640 if (pre_data_ != NULL) pre_data_->Initialize(); | 640 if (pre_data_ != NULL) pre_data_->Initialize(); |
641 | 641 |
642 // Compute the parsing mode. | 642 // Compute the parsing mode. |
643 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; | 643 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; |
644 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; | 644 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; |
645 | 645 |
646 ScopeType type = in_global_context ? GLOBAL_SCOPE : EVAL_SCOPE; | 646 Scope::Type type = |
| 647 in_global_context |
| 648 ? Scope::GLOBAL_SCOPE |
| 649 : Scope::EVAL_SCOPE; |
647 Handle<String> no_name = isolate()->factory()->empty_symbol(); | 650 Handle<String> no_name = isolate()->factory()->empty_symbol(); |
648 | 651 |
649 FunctionLiteral* result = NULL; | 652 FunctionLiteral* result = NULL; |
650 { Scope* scope = NewScope(top_scope_, type); | 653 { Scope* scope = NewScope(top_scope_, type); |
651 scope->set_start_position(0); | |
652 scope->set_end_position(source->length()); | |
653 LexicalScope lexical_scope(this, scope, isolate()); | 654 LexicalScope lexical_scope(this, scope, isolate()); |
654 if (strict_mode == kStrictMode) { | 655 if (strict_mode == kStrictMode) { |
655 top_scope_->EnableStrictMode(); | 656 top_scope_->EnableStrictMode(); |
656 } | 657 } |
657 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); | 658 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); |
658 bool ok = true; | 659 bool ok = true; |
659 int beg_loc = scanner().location().beg_pos; | 660 int beg_loc = scanner().location().beg_pos; |
660 ParseSourceElements(body, Token::EOS, &ok); | 661 ParseSourceElements(body, Token::EOS, &ok); |
661 if (ok && top_scope_->is_strict_mode()) { | 662 if (ok && top_scope_->is_strict_mode()) { |
662 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 663 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
663 } | 664 } |
664 | 665 |
665 if (ok && harmony_scoping_) { | 666 if (ok && harmony_scoping_) { |
666 CheckConflictingVarDeclarations(scope, &ok); | 667 CheckConflictingVarDeclarations(scope, &ok); |
667 } | 668 } |
668 | 669 |
669 if (ok) { | 670 if (ok) { |
670 result = new(zone()) FunctionLiteral( | 671 result = new(zone()) FunctionLiteral( |
671 isolate(), | 672 isolate(), |
672 no_name, | 673 no_name, |
673 top_scope_, | 674 top_scope_, |
674 body, | 675 body, |
675 lexical_scope.materialized_literal_count(), | 676 lexical_scope.materialized_literal_count(), |
676 lexical_scope.expected_property_count(), | 677 lexical_scope.expected_property_count(), |
677 lexical_scope.only_simple_this_property_assignments(), | 678 lexical_scope.only_simple_this_property_assignments(), |
678 lexical_scope.this_property_assignments(), | 679 lexical_scope.this_property_assignments(), |
679 0, | 680 0, |
| 681 0, |
| 682 source->length(), |
680 FunctionLiteral::ANONYMOUS_EXPRESSION, | 683 FunctionLiteral::ANONYMOUS_EXPRESSION, |
681 false); // Does not have duplicate parameters. | 684 false); // Does not have duplicate parameters. |
682 } else if (stack_overflow_) { | 685 } else if (stack_overflow_) { |
683 isolate()->StackOverflow(); | 686 isolate()->StackOverflow(); |
684 } | 687 } |
685 } | 688 } |
686 | 689 |
687 // Make sure the target stack is empty. | 690 // Make sure the target stack is empty. |
688 ASSERT(target_stack_ == NULL); | 691 ASSERT(target_stack_ == NULL); |
689 | 692 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 fni_ = new(zone()) FuncNameInferrer(isolate()); | 733 fni_ = new(zone()) FuncNameInferrer(isolate()); |
731 fni_->PushEnclosingName(name); | 734 fni_->PushEnclosingName(name); |
732 | 735 |
733 mode_ = PARSE_EAGERLY; | 736 mode_ = PARSE_EAGERLY; |
734 | 737 |
735 // Place holder for the result. | 738 // Place holder for the result. |
736 FunctionLiteral* result = NULL; | 739 FunctionLiteral* result = NULL; |
737 | 740 |
738 { | 741 { |
739 // Parse the function literal. | 742 // Parse the function literal. |
740 Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); | 743 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE); |
741 if (!info->closure().is_null()) { | 744 if (!info->closure().is_null()) { |
742 scope = Scope::DeserializeScopeChain(info, scope); | 745 scope = Scope::DeserializeScopeChain(info, scope); |
743 } | 746 } |
744 LexicalScope lexical_scope(this, scope, isolate()); | 747 LexicalScope lexical_scope(this, scope, isolate()); |
745 | 748 |
746 if (shared_info->strict_mode()) { | 749 if (shared_info->strict_mode()) { |
747 top_scope_->EnableStrictMode(); | 750 top_scope_->EnableStrictMode(); |
748 } | 751 } |
749 | 752 |
750 FunctionLiteral::Type type = shared_info->is_expression() | 753 FunctionLiteral::Type type = shared_info->is_expression() |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 | 1588 |
1586 | 1589 |
1587 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { | 1590 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { |
1588 // The harmony mode uses source elements instead of statements. | 1591 // The harmony mode uses source elements instead of statements. |
1589 // | 1592 // |
1590 // Block :: | 1593 // Block :: |
1591 // '{' SourceElement* '}' | 1594 // '{' SourceElement* '}' |
1592 | 1595 |
1593 // Construct block expecting 16 statements. | 1596 // Construct block expecting 16 statements. |
1594 Block* body = new(zone()) Block(isolate(), labels, 16, false); | 1597 Block* body = new(zone()) Block(isolate(), labels, 16, false); |
1595 Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE); | 1598 Scope* block_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE); |
1596 if (top_scope_->is_strict_mode()) { | 1599 if (top_scope_->is_strict_mode()) { |
1597 block_scope->EnableStrictMode(); | 1600 block_scope->EnableStrictMode(); |
1598 } | 1601 } |
1599 | 1602 |
1600 // Parse the statements and collect escaping labels. | 1603 // Parse the statements and collect escaping labels. |
1601 Expect(Token::LBRACE, CHECK_OK); | 1604 Expect(Token::LBRACE, CHECK_OK); |
1602 block_scope->set_start_position(scanner().location().beg_pos); | |
1603 { SaveScope save_scope(this, block_scope); | 1605 { SaveScope save_scope(this, block_scope); |
1604 TargetCollector collector; | 1606 TargetCollector collector; |
1605 Target target(&this->target_stack_, &collector); | 1607 Target target(&this->target_stack_, &collector); |
1606 Target target_body(&this->target_stack_, body); | 1608 Target target_body(&this->target_stack_, body); |
1607 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 1609 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
1608 | 1610 |
1609 while (peek() != Token::RBRACE) { | 1611 while (peek() != Token::RBRACE) { |
1610 Statement* stat = ParseSourceElement(NULL, CHECK_OK); | 1612 Statement* stat = ParseSourceElement(NULL, CHECK_OK); |
1611 if (stat && !stat->IsEmpty()) { | 1613 if (stat && !stat->IsEmpty()) { |
1612 body->AddStatement(stat); | 1614 body->AddStatement(stat); |
1613 block_finder.Update(stat); | 1615 block_finder.Update(stat); |
1614 } | 1616 } |
1615 } | 1617 } |
1616 } | 1618 } |
1617 Expect(Token::RBRACE, CHECK_OK); | 1619 Expect(Token::RBRACE, CHECK_OK); |
1618 block_scope->set_end_position(scanner().location().end_pos); | 1620 |
1619 block_scope = block_scope->FinalizeBlockScope(); | 1621 block_scope = block_scope->FinalizeBlockScope(); |
1620 body->set_block_scope(block_scope); | 1622 body->set_block_scope(block_scope); |
1621 return body; | 1623 return body; |
1622 } | 1624 } |
1623 | 1625 |
1624 | 1626 |
1625 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, | 1627 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, |
1626 bool* ok) { | 1628 bool* ok) { |
1627 // VariableStatement :: | 1629 // VariableStatement :: |
1628 // VariableDeclarations ';' | 1630 // VariableDeclarations ';' |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2105 ReportMessage("strict_mode_with", Vector<const char*>::empty()); | 2107 ReportMessage("strict_mode_with", Vector<const char*>::empty()); |
2106 *ok = false; | 2108 *ok = false; |
2107 return NULL; | 2109 return NULL; |
2108 } | 2110 } |
2109 | 2111 |
2110 Expect(Token::LPAREN, CHECK_OK); | 2112 Expect(Token::LPAREN, CHECK_OK); |
2111 Expression* expr = ParseExpression(true, CHECK_OK); | 2113 Expression* expr = ParseExpression(true, CHECK_OK); |
2112 Expect(Token::RPAREN, CHECK_OK); | 2114 Expect(Token::RPAREN, CHECK_OK); |
2113 | 2115 |
2114 top_scope_->DeclarationScope()->RecordWithStatement(); | 2116 top_scope_->DeclarationScope()->RecordWithStatement(); |
2115 Scope* with_scope = NewScope(top_scope_, WITH_SCOPE); | 2117 Scope* with_scope = NewScope(top_scope_, Scope::WITH_SCOPE); |
2116 Statement* stmt; | 2118 Statement* stmt; |
2117 { SaveScope save_scope(this, with_scope); | 2119 { SaveScope save_scope(this, with_scope); |
2118 with_scope->set_start_position(scanner().peek_location().beg_pos); | |
2119 stmt = ParseStatement(labels, CHECK_OK); | 2120 stmt = ParseStatement(labels, CHECK_OK); |
2120 with_scope->set_end_position(scanner().location().end_pos); | |
2121 } | 2121 } |
2122 return new(zone()) WithStatement(expr, stmt); | 2122 return new(zone()) WithStatement(expr, stmt); |
2123 } | 2123 } |
2124 | 2124 |
2125 | 2125 |
2126 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { | 2126 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { |
2127 // CaseClause :: | 2127 // CaseClause :: |
2128 // 'case' Expression ':' Statement* | 2128 // 'case' Expression ':' Statement* |
2129 // 'default' ':' Statement* | 2129 // 'default' ':' Statement* |
2130 | 2130 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 // always collect the targets. | 2236 // always collect the targets. |
2237 TargetCollector catch_collector; | 2237 TargetCollector catch_collector; |
2238 Scope* catch_scope = NULL; | 2238 Scope* catch_scope = NULL; |
2239 Variable* catch_variable = NULL; | 2239 Variable* catch_variable = NULL; |
2240 Block* catch_block = NULL; | 2240 Block* catch_block = NULL; |
2241 Handle<String> name; | 2241 Handle<String> name; |
2242 if (tok == Token::CATCH) { | 2242 if (tok == Token::CATCH) { |
2243 Consume(Token::CATCH); | 2243 Consume(Token::CATCH); |
2244 | 2244 |
2245 Expect(Token::LPAREN, CHECK_OK); | 2245 Expect(Token::LPAREN, CHECK_OK); |
2246 catch_scope = NewScope(top_scope_, CATCH_SCOPE); | |
2247 if (top_scope_->is_strict_mode()) { | |
2248 catch_scope->EnableStrictMode(); | |
2249 } | |
2250 catch_scope->set_start_position(scanner().location().beg_pos); | |
2251 name = ParseIdentifier(CHECK_OK); | 2246 name = ParseIdentifier(CHECK_OK); |
2252 | 2247 |
2253 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) { | 2248 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) { |
2254 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); | 2249 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); |
2255 *ok = false; | 2250 *ok = false; |
2256 return NULL; | 2251 return NULL; |
2257 } | 2252 } |
2258 | 2253 |
2259 Expect(Token::RPAREN, CHECK_OK); | 2254 Expect(Token::RPAREN, CHECK_OK); |
2260 | 2255 |
2261 if (peek() == Token::LBRACE) { | 2256 if (peek() == Token::LBRACE) { |
2262 Target target(&this->target_stack_, &catch_collector); | 2257 Target target(&this->target_stack_, &catch_collector); |
| 2258 catch_scope = NewScope(top_scope_, Scope::CATCH_SCOPE); |
| 2259 if (top_scope_->is_strict_mode()) { |
| 2260 catch_scope->EnableStrictMode(); |
| 2261 } |
2263 VariableMode mode = harmony_scoping_ ? LET : VAR; | 2262 VariableMode mode = harmony_scoping_ ? LET : VAR; |
2264 catch_variable = catch_scope->DeclareLocal(name, mode); | 2263 catch_variable = catch_scope->DeclareLocal(name, mode); |
2265 | 2264 |
2266 SaveScope save_scope(this, catch_scope); | 2265 SaveScope save_scope(this, catch_scope); |
2267 catch_block = ParseBlock(NULL, CHECK_OK); | 2266 catch_block = ParseBlock(NULL, CHECK_OK); |
2268 } else { | 2267 } else { |
2269 Expect(Token::LBRACE, CHECK_OK); | 2268 Expect(Token::LBRACE, CHECK_OK); |
2270 } | 2269 } |
2271 catch_scope->set_end_position(scanner().location().end_pos); | 2270 |
2272 tok = peek(); | 2271 tok = peek(); |
2273 } | 2272 } |
2274 | 2273 |
2275 Block* finally_block = NULL; | 2274 Block* finally_block = NULL; |
2276 if (tok == Token::FINALLY || catch_block == NULL) { | 2275 if (tok == Token::FINALLY || catch_block == NULL) { |
2277 Consume(Token::FINALLY); | 2276 Consume(Token::FINALLY); |
2278 finally_block = ParseBlock(NULL, CHECK_OK); | 2277 finally_block = ParseBlock(NULL, CHECK_OK); |
2279 } | 2278 } |
2280 | 2279 |
2281 // Simplify the AST nodes by converting: | 2280 // Simplify the AST nodes by converting: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2369 | 2368 |
2370 | 2369 |
2371 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { | 2370 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { |
2372 // ForStatement :: | 2371 // ForStatement :: |
2373 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 2372 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
2374 | 2373 |
2375 Statement* init = NULL; | 2374 Statement* init = NULL; |
2376 | 2375 |
2377 // Create an in-between scope for let-bound iteration variables. | 2376 // Create an in-between scope for let-bound iteration variables. |
2378 Scope* saved_scope = top_scope_; | 2377 Scope* saved_scope = top_scope_; |
2379 Scope* for_scope = NewScope(top_scope_, BLOCK_SCOPE); | 2378 Scope* for_scope = NewScope(top_scope_, Scope::BLOCK_SCOPE); |
2380 if (top_scope_->is_strict_mode()) { | 2379 if (top_scope_->is_strict_mode()) { |
2381 for_scope->EnableStrictMode(); | 2380 for_scope->EnableStrictMode(); |
2382 } | 2381 } |
2383 top_scope_ = for_scope; | 2382 top_scope_ = for_scope; |
2384 | 2383 |
2385 Expect(Token::FOR, CHECK_OK); | 2384 Expect(Token::FOR, CHECK_OK); |
2386 Expect(Token::LPAREN, CHECK_OK); | 2385 Expect(Token::LPAREN, CHECK_OK); |
2387 for_scope->set_start_position(scanner().location().beg_pos); | |
2388 if (peek() != Token::SEMICOLON) { | 2386 if (peek() != Token::SEMICOLON) { |
2389 if (peek() == Token::VAR || peek() == Token::CONST) { | 2387 if (peek() == Token::VAR || peek() == Token::CONST) { |
2390 Handle<String> name; | 2388 Handle<String> name; |
2391 Block* variable_statement = | 2389 Block* variable_statement = |
2392 ParseVariableDeclarations(kForStatement, NULL, &name, CHECK_OK); | 2390 ParseVariableDeclarations(kForStatement, NULL, &name, CHECK_OK); |
2393 | 2391 |
2394 if (peek() == Token::IN && !name.is_null()) { | 2392 if (peek() == Token::IN && !name.is_null()) { |
2395 VariableProxy* each = top_scope_->NewUnresolved(name); | 2393 VariableProxy* each = top_scope_->NewUnresolved(name); |
2396 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels); | 2394 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels); |
2397 Target target(&this->target_stack_, loop); | 2395 Target target(&this->target_stack_, loop); |
2398 | 2396 |
2399 Expect(Token::IN, CHECK_OK); | 2397 Expect(Token::IN, CHECK_OK); |
2400 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2398 Expression* enumerable = ParseExpression(true, CHECK_OK); |
2401 Expect(Token::RPAREN, CHECK_OK); | 2399 Expect(Token::RPAREN, CHECK_OK); |
2402 | 2400 |
2403 Statement* body = ParseStatement(NULL, CHECK_OK); | 2401 Statement* body = ParseStatement(NULL, CHECK_OK); |
2404 loop->Initialize(each, enumerable, body); | 2402 loop->Initialize(each, enumerable, body); |
2405 Block* result = new(zone()) Block(isolate(), NULL, 2, false); | 2403 Block* result = new(zone()) Block(isolate(), NULL, 2, false); |
2406 result->AddStatement(variable_statement); | 2404 result->AddStatement(variable_statement); |
2407 result->AddStatement(loop); | 2405 result->AddStatement(loop); |
2408 top_scope_ = saved_scope; | 2406 top_scope_ = saved_scope; |
2409 for_scope->set_end_position(scanner().location().end_pos); | |
2410 for_scope = for_scope->FinalizeBlockScope(); | 2407 for_scope = for_scope->FinalizeBlockScope(); |
2411 ASSERT(for_scope == NULL); | 2408 ASSERT(for_scope == NULL); |
2412 // Parsed for-in loop w/ variable/const declaration. | 2409 // Parsed for-in loop w/ variable/const declaration. |
2413 return result; | 2410 return result; |
2414 } else { | 2411 } else { |
2415 init = variable_statement; | 2412 init = variable_statement; |
2416 } | 2413 } |
2417 } else if (peek() == Token::LET) { | 2414 } else if (peek() == Token::LET) { |
2418 Handle<String> name; | 2415 Handle<String> name; |
2419 VariableDeclarationProperties decl_props = kHasNoInitializers; | 2416 VariableDeclarationProperties decl_props = kHasNoInitializers; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2456 each, | 2453 each, |
2457 temp_proxy, | 2454 temp_proxy, |
2458 RelocInfo::kNoPosition); | 2455 RelocInfo::kNoPosition); |
2459 Statement* assignment_statement = | 2456 Statement* assignment_statement = |
2460 new(zone()) ExpressionStatement(assignment); | 2457 new(zone()) ExpressionStatement(assignment); |
2461 body_block->AddStatement(variable_statement); | 2458 body_block->AddStatement(variable_statement); |
2462 body_block->AddStatement(assignment_statement); | 2459 body_block->AddStatement(assignment_statement); |
2463 body_block->AddStatement(body); | 2460 body_block->AddStatement(body); |
2464 loop->Initialize(temp_proxy, enumerable, body_block); | 2461 loop->Initialize(temp_proxy, enumerable, body_block); |
2465 top_scope_ = saved_scope; | 2462 top_scope_ = saved_scope; |
2466 for_scope->set_end_position(scanner().location().end_pos); | |
2467 for_scope = for_scope->FinalizeBlockScope(); | 2463 for_scope = for_scope->FinalizeBlockScope(); |
2468 body_block->set_block_scope(for_scope); | 2464 body_block->set_block_scope(for_scope); |
2469 // Parsed for-in loop w/ let declaration. | 2465 // Parsed for-in loop w/ let declaration. |
2470 return loop; | 2466 return loop; |
2471 | 2467 |
2472 } else { | 2468 } else { |
2473 init = variable_statement; | 2469 init = variable_statement; |
2474 } | 2470 } |
2475 } else { | 2471 } else { |
2476 Expression* expression = ParseExpression(false, CHECK_OK); | 2472 Expression* expression = ParseExpression(false, CHECK_OK); |
(...skipping 10 matching lines...) Expand all Loading... |
2487 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels); | 2483 ForInStatement* loop = new(zone()) ForInStatement(isolate(), labels); |
2488 Target target(&this->target_stack_, loop); | 2484 Target target(&this->target_stack_, loop); |
2489 | 2485 |
2490 Expect(Token::IN, CHECK_OK); | 2486 Expect(Token::IN, CHECK_OK); |
2491 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2487 Expression* enumerable = ParseExpression(true, CHECK_OK); |
2492 Expect(Token::RPAREN, CHECK_OK); | 2488 Expect(Token::RPAREN, CHECK_OK); |
2493 | 2489 |
2494 Statement* body = ParseStatement(NULL, CHECK_OK); | 2490 Statement* body = ParseStatement(NULL, CHECK_OK); |
2495 if (loop) loop->Initialize(expression, enumerable, body); | 2491 if (loop) loop->Initialize(expression, enumerable, body); |
2496 top_scope_ = saved_scope; | 2492 top_scope_ = saved_scope; |
2497 for_scope->set_end_position(scanner().location().end_pos); | |
2498 for_scope = for_scope->FinalizeBlockScope(); | 2493 for_scope = for_scope->FinalizeBlockScope(); |
2499 ASSERT(for_scope == NULL); | 2494 ASSERT(for_scope == NULL); |
2500 // Parsed for-in loop. | 2495 // Parsed for-in loop. |
2501 return loop; | 2496 return loop; |
2502 | 2497 |
2503 } else { | 2498 } else { |
2504 init = new(zone()) ExpressionStatement(expression); | 2499 init = new(zone()) ExpressionStatement(expression); |
2505 } | 2500 } |
2506 } | 2501 } |
2507 } | 2502 } |
(...skipping 13 matching lines...) Expand all Loading... |
2521 | 2516 |
2522 Statement* next = NULL; | 2517 Statement* next = NULL; |
2523 if (peek() != Token::RPAREN) { | 2518 if (peek() != Token::RPAREN) { |
2524 Expression* exp = ParseExpression(true, CHECK_OK); | 2519 Expression* exp = ParseExpression(true, CHECK_OK); |
2525 next = new(zone()) ExpressionStatement(exp); | 2520 next = new(zone()) ExpressionStatement(exp); |
2526 } | 2521 } |
2527 Expect(Token::RPAREN, CHECK_OK); | 2522 Expect(Token::RPAREN, CHECK_OK); |
2528 | 2523 |
2529 Statement* body = ParseStatement(NULL, CHECK_OK); | 2524 Statement* body = ParseStatement(NULL, CHECK_OK); |
2530 top_scope_ = saved_scope; | 2525 top_scope_ = saved_scope; |
2531 for_scope->set_end_position(scanner().location().end_pos); | |
2532 for_scope = for_scope->FinalizeBlockScope(); | 2526 for_scope = for_scope->FinalizeBlockScope(); |
2533 if (for_scope != NULL) { | 2527 if (for_scope != NULL) { |
2534 // Rewrite a for statement of the form | 2528 // Rewrite a for statement of the form |
2535 // | 2529 // |
2536 // for (let x = i; c; n) b | 2530 // for (let x = i; c; n) b |
2537 // | 2531 // |
2538 // into | 2532 // into |
2539 // | 2533 // |
2540 // { | 2534 // { |
2541 // let x = i; | 2535 // let x = i; |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3869 | 3863 |
3870 // We want a non-null handle as the function name. | 3864 // We want a non-null handle as the function name. |
3871 if (should_infer_name) { | 3865 if (should_infer_name) { |
3872 function_name = isolate()->factory()->empty_symbol(); | 3866 function_name = isolate()->factory()->empty_symbol(); |
3873 } | 3867 } |
3874 | 3868 |
3875 int num_parameters = 0; | 3869 int num_parameters = 0; |
3876 // Function declarations are function scoped in normal mode, so they are | 3870 // Function declarations are function scoped in normal mode, so they are |
3877 // hoisted. In harmony block scoping mode they are block scoped, so they | 3871 // hoisted. In harmony block scoping mode they are block scoped, so they |
3878 // are not hoisted. | 3872 // are not hoisted. |
3879 Scope* scope = (type == FunctionLiteral::DECLARATION && !harmony_scoping_) | 3873 Scope* scope = (type == FunctionLiteral::DECLARATION && |
3880 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) | 3874 !harmony_scoping_) |
3881 : NewScope(top_scope_, FUNCTION_SCOPE); | 3875 ? NewScope(top_scope_->DeclarationScope(), Scope::FUNCTION_SCOPE) |
| 3876 : NewScope(top_scope_, Scope::FUNCTION_SCOPE); |
3882 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8); | 3877 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8); |
3883 int materialized_literal_count; | 3878 int materialized_literal_count; |
3884 int expected_property_count; | 3879 int expected_property_count; |
| 3880 int start_pos; |
| 3881 int end_pos; |
3885 bool only_simple_this_property_assignments; | 3882 bool only_simple_this_property_assignments; |
3886 Handle<FixedArray> this_property_assignments; | 3883 Handle<FixedArray> this_property_assignments; |
3887 bool has_duplicate_parameters = false; | 3884 bool has_duplicate_parameters = false; |
3888 // Parse function body. | 3885 // Parse function body. |
3889 { LexicalScope lexical_scope(this, scope, isolate()); | 3886 { LexicalScope lexical_scope(this, scope, isolate()); |
3890 top_scope_->SetScopeName(function_name); | 3887 top_scope_->SetScopeName(function_name); |
3891 | 3888 |
3892 // FormalParameterList :: | 3889 // FormalParameterList :: |
3893 // '(' (Identifier)*[','] ')' | 3890 // '(' (Identifier)*[','] ')' |
3894 Expect(Token::LPAREN, CHECK_OK); | 3891 Expect(Token::LPAREN, CHECK_OK); |
3895 scope->set_start_position(scanner().location().beg_pos); | 3892 start_pos = scanner().location().beg_pos; |
3896 Scanner::Location name_loc = Scanner::Location::invalid(); | 3893 Scanner::Location name_loc = Scanner::Location::invalid(); |
3897 Scanner::Location dupe_loc = Scanner::Location::invalid(); | 3894 Scanner::Location dupe_loc = Scanner::Location::invalid(); |
3898 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 3895 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
3899 | 3896 |
3900 bool done = (peek() == Token::RPAREN); | 3897 bool done = (peek() == Token::RPAREN); |
3901 while (!done) { | 3898 while (!done) { |
3902 bool is_strict_reserved = false; | 3899 bool is_strict_reserved = false; |
3903 Handle<String> param_name = | 3900 Handle<String> param_name = |
3904 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, | 3901 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, |
3905 CHECK_OK); | 3902 CHECK_OK); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3960 parenthesized_function_ = false; // The bit was set for this function only. | 3957 parenthesized_function_ = false; // The bit was set for this function only. |
3961 | 3958 |
3962 if (is_lazily_compiled) { | 3959 if (is_lazily_compiled) { |
3963 int function_block_pos = scanner().location().beg_pos; | 3960 int function_block_pos = scanner().location().beg_pos; |
3964 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); | 3961 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); |
3965 if (!entry.is_valid()) { | 3962 if (!entry.is_valid()) { |
3966 // There is no preparser data for the function, we will not lazily | 3963 // There is no preparser data for the function, we will not lazily |
3967 // compile after all. | 3964 // compile after all. |
3968 is_lazily_compiled = false; | 3965 is_lazily_compiled = false; |
3969 } else { | 3966 } else { |
3970 scope->set_end_position(entry.end_pos()); | 3967 end_pos = entry.end_pos(); |
3971 if (scope->end_position() <= function_block_pos) { | 3968 if (end_pos <= function_block_pos) { |
3972 // End position greater than end of stream is safe, and hard to check. | 3969 // End position greater than end of stream is safe, and hard to check. |
3973 ReportInvalidPreparseData(function_name, CHECK_OK); | 3970 ReportInvalidPreparseData(function_name, CHECK_OK); |
3974 } | 3971 } |
3975 isolate()->counters()->total_preparse_skipped()->Increment( | 3972 isolate()->counters()->total_preparse_skipped()->Increment( |
3976 scope->end_position() - function_block_pos); | 3973 end_pos - function_block_pos); |
3977 // Seek to position just before terminal '}'. | 3974 // Seek to position just before terminal '}'. |
3978 scanner().SeekForward(scope->end_position() - 1); | 3975 scanner().SeekForward(end_pos - 1); |
3979 materialized_literal_count = entry.literal_count(); | 3976 materialized_literal_count = entry.literal_count(); |
3980 expected_property_count = entry.property_count(); | 3977 expected_property_count = entry.property_count(); |
3981 if (entry.strict_mode()) top_scope_->EnableStrictMode(); | 3978 if (entry.strict_mode()) top_scope_->EnableStrictMode(); |
3982 only_simple_this_property_assignments = false; | 3979 only_simple_this_property_assignments = false; |
3983 this_property_assignments = isolate()->factory()->empty_fixed_array(); | 3980 this_property_assignments = isolate()->factory()->empty_fixed_array(); |
3984 Expect(Token::RBRACE, CHECK_OK); | 3981 Expect(Token::RBRACE, CHECK_OK); |
3985 } | 3982 } |
3986 } | 3983 } |
3987 | 3984 |
3988 if (!is_lazily_compiled) { | 3985 if (!is_lazily_compiled) { |
3989 ParseSourceElements(body, Token::RBRACE, CHECK_OK); | 3986 ParseSourceElements(body, Token::RBRACE, CHECK_OK); |
3990 | 3987 |
3991 materialized_literal_count = lexical_scope.materialized_literal_count(); | 3988 materialized_literal_count = lexical_scope.materialized_literal_count(); |
3992 expected_property_count = lexical_scope.expected_property_count(); | 3989 expected_property_count = lexical_scope.expected_property_count(); |
3993 only_simple_this_property_assignments = | 3990 only_simple_this_property_assignments = |
3994 lexical_scope.only_simple_this_property_assignments(); | 3991 lexical_scope.only_simple_this_property_assignments(); |
3995 this_property_assignments = lexical_scope.this_property_assignments(); | 3992 this_property_assignments = lexical_scope.this_property_assignments(); |
3996 | 3993 |
3997 Expect(Token::RBRACE, CHECK_OK); | 3994 Expect(Token::RBRACE, CHECK_OK); |
3998 scope->set_end_position(scanner().location().end_pos); | 3995 end_pos = scanner().location().end_pos; |
3999 } | 3996 } |
4000 | 3997 |
4001 // Validate strict mode. | 3998 // Validate strict mode. |
4002 if (top_scope_->is_strict_mode()) { | 3999 if (top_scope_->is_strict_mode()) { |
4003 if (IsEvalOrArguments(function_name)) { | 4000 if (IsEvalOrArguments(function_name)) { |
4004 int start_pos = scope->start_position(); | |
4005 int position = function_token_position != RelocInfo::kNoPosition | 4001 int position = function_token_position != RelocInfo::kNoPosition |
4006 ? function_token_position | 4002 ? function_token_position |
4007 : (start_pos > 0 ? start_pos - 1 : start_pos); | 4003 : (start_pos > 0 ? start_pos - 1 : start_pos); |
4008 Scanner::Location location = Scanner::Location(position, start_pos); | 4004 Scanner::Location location = Scanner::Location(position, start_pos); |
4009 ReportMessageAt(location, | 4005 ReportMessageAt(location, |
4010 "strict_function_name", Vector<const char*>::empty()); | 4006 "strict_function_name", Vector<const char*>::empty()); |
4011 *ok = false; | 4007 *ok = false; |
4012 return NULL; | 4008 return NULL; |
4013 } | 4009 } |
4014 if (name_loc.IsValid()) { | 4010 if (name_loc.IsValid()) { |
4015 ReportMessageAt(name_loc, "strict_param_name", | 4011 ReportMessageAt(name_loc, "strict_param_name", |
4016 Vector<const char*>::empty()); | 4012 Vector<const char*>::empty()); |
4017 *ok = false; | 4013 *ok = false; |
4018 return NULL; | 4014 return NULL; |
4019 } | 4015 } |
4020 if (dupe_loc.IsValid()) { | 4016 if (dupe_loc.IsValid()) { |
4021 ReportMessageAt(dupe_loc, "strict_param_dupe", | 4017 ReportMessageAt(dupe_loc, "strict_param_dupe", |
4022 Vector<const char*>::empty()); | 4018 Vector<const char*>::empty()); |
4023 *ok = false; | 4019 *ok = false; |
4024 return NULL; | 4020 return NULL; |
4025 } | 4021 } |
4026 if (name_is_strict_reserved) { | 4022 if (name_is_strict_reserved) { |
4027 int start_pos = scope->start_position(); | |
4028 int position = function_token_position != RelocInfo::kNoPosition | 4023 int position = function_token_position != RelocInfo::kNoPosition |
4029 ? function_token_position | 4024 ? function_token_position |
4030 : (start_pos > 0 ? start_pos - 1 : start_pos); | 4025 : (start_pos > 0 ? start_pos - 1 : start_pos); |
4031 Scanner::Location location = Scanner::Location(position, start_pos); | 4026 Scanner::Location location = Scanner::Location(position, start_pos); |
4032 ReportMessageAt(location, "strict_reserved_word", | 4027 ReportMessageAt(location, "strict_reserved_word", |
4033 Vector<const char*>::empty()); | 4028 Vector<const char*>::empty()); |
4034 *ok = false; | 4029 *ok = false; |
4035 return NULL; | 4030 return NULL; |
4036 } | 4031 } |
4037 if (reserved_loc.IsValid()) { | 4032 if (reserved_loc.IsValid()) { |
4038 ReportMessageAt(reserved_loc, "strict_reserved_word", | 4033 ReportMessageAt(reserved_loc, "strict_reserved_word", |
4039 Vector<const char*>::empty()); | 4034 Vector<const char*>::empty()); |
4040 *ok = false; | 4035 *ok = false; |
4041 return NULL; | 4036 return NULL; |
4042 } | 4037 } |
4043 CheckOctalLiteral(scope->start_position(), | 4038 CheckOctalLiteral(start_pos, end_pos, CHECK_OK); |
4044 scope->end_position(), | |
4045 CHECK_OK); | |
4046 } | 4039 } |
4047 } | 4040 } |
4048 | 4041 |
4049 if (harmony_scoping_) { | 4042 if (harmony_scoping_) { |
4050 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4043 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4051 } | 4044 } |
4052 | 4045 |
4053 FunctionLiteral* function_literal = | 4046 FunctionLiteral* function_literal = |
4054 new(zone()) FunctionLiteral(isolate(), | 4047 new(zone()) FunctionLiteral(isolate(), |
4055 function_name, | 4048 function_name, |
4056 scope, | 4049 scope, |
4057 body, | 4050 body, |
4058 materialized_literal_count, | 4051 materialized_literal_count, |
4059 expected_property_count, | 4052 expected_property_count, |
4060 only_simple_this_property_assignments, | 4053 only_simple_this_property_assignments, |
4061 this_property_assignments, | 4054 this_property_assignments, |
4062 num_parameters, | 4055 num_parameters, |
| 4056 start_pos, |
| 4057 end_pos, |
4063 type, | 4058 type, |
4064 has_duplicate_parameters); | 4059 has_duplicate_parameters); |
4065 function_literal->set_function_token_position(function_token_position); | 4060 function_literal->set_function_token_position(function_token_position); |
4066 | 4061 |
4067 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 4062 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
4068 return function_literal; | 4063 return function_literal; |
4069 } | 4064 } |
4070 | 4065 |
4071 | 4066 |
4072 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 4067 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5391 result = parser.ParseProgram(source, | 5386 result = parser.ParseProgram(source, |
5392 info->is_global(), | 5387 info->is_global(), |
5393 info->StrictMode()); | 5388 info->StrictMode()); |
5394 } | 5389 } |
5395 } | 5390 } |
5396 info->SetFunction(result); | 5391 info->SetFunction(result); |
5397 return (result != NULL); | 5392 return (result != NULL); |
5398 } | 5393 } |
5399 | 5394 |
5400 } } // namespace v8::internal | 5395 } } // namespace v8::internal |
OLD | NEW |