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