| 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 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3805 | 3811 |
| 3806 // We want a non-null handle as the function name. | 3812 // We want a non-null handle as the function name. |
| 3807 if (should_infer_name) { | 3813 if (should_infer_name) { |
| 3808 function_name = isolate()->factory()->empty_symbol(); | 3814 function_name = isolate()->factory()->empty_symbol(); |
| 3809 } | 3815 } |
| 3810 | 3816 |
| 3811 int num_parameters = 0; | 3817 int num_parameters = 0; |
| 3812 // Function declarations are function scoped in normal mode, so they are | 3818 // Function declarations are function scoped in normal mode, so they are |
| 3813 // hoisted. In harmony block scoping mode they are block scoped, so they | 3819 // hoisted. In harmony block scoping mode they are block scoped, so they |
| 3814 // are not hoisted. | 3820 // are not hoisted. |
| 3815 Scope* scope = (type == FunctionLiteral::DECLARATION && | 3821 Scope* scope = (type == FunctionLiteral::DECLARATION && !harmony_scoping_) |
| 3816 !harmony_scoping_) | 3822 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) |
| 3817 ? NewScope(top_scope_->DeclarationScope(), Scope::FUNCTION_SCOPE) | 3823 : NewScope(top_scope_, FUNCTION_SCOPE); |
| 3818 : NewScope(top_scope_, Scope::FUNCTION_SCOPE); | |
| 3819 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8); | 3824 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8); |
| 3820 int materialized_literal_count; | 3825 int materialized_literal_count; |
| 3821 int expected_property_count; | 3826 int expected_property_count; |
| 3822 int start_pos; | |
| 3823 int end_pos; | |
| 3824 bool only_simple_this_property_assignments; | 3827 bool only_simple_this_property_assignments; |
| 3825 Handle<FixedArray> this_property_assignments; | 3828 Handle<FixedArray> this_property_assignments; |
| 3826 bool has_duplicate_parameters = false; | 3829 bool has_duplicate_parameters = false; |
| 3827 // Parse function body. | 3830 // Parse function body. |
| 3828 { LexicalScope lexical_scope(this, scope, isolate()); | 3831 { LexicalScope lexical_scope(this, scope, isolate()); |
| 3829 top_scope_->SetScopeName(function_name); | 3832 top_scope_->SetScopeName(function_name); |
| 3830 | 3833 |
| 3831 // FormalParameterList :: | 3834 // FormalParameterList :: |
| 3832 // '(' (Identifier)*[','] ')' | 3835 // '(' (Identifier)*[','] ')' |
| 3833 Expect(Token::LPAREN, CHECK_OK); | 3836 Expect(Token::LPAREN, CHECK_OK); |
| 3834 start_pos = scanner().location().beg_pos; | 3837 scope->set_start_position(scanner().location().beg_pos); |
| 3835 Scanner::Location name_loc = Scanner::Location::invalid(); | 3838 Scanner::Location name_loc = Scanner::Location::invalid(); |
| 3836 Scanner::Location dupe_loc = Scanner::Location::invalid(); | 3839 Scanner::Location dupe_loc = Scanner::Location::invalid(); |
| 3837 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 3840 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
| 3838 | 3841 |
| 3839 bool done = (peek() == Token::RPAREN); | 3842 bool done = (peek() == Token::RPAREN); |
| 3840 while (!done) { | 3843 while (!done) { |
| 3841 bool is_strict_reserved = false; | 3844 bool is_strict_reserved = false; |
| 3842 Handle<String> param_name = | 3845 Handle<String> param_name = |
| 3843 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, | 3846 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, |
| 3844 CHECK_OK); | 3847 CHECK_OK); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3899 parenthesized_function_ = false; // The bit was set for this function only. | 3902 parenthesized_function_ = false; // The bit was set for this function only. |
| 3900 | 3903 |
| 3901 if (is_lazily_compiled) { | 3904 if (is_lazily_compiled) { |
| 3902 int function_block_pos = scanner().location().beg_pos; | 3905 int function_block_pos = scanner().location().beg_pos; |
| 3903 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); | 3906 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); |
| 3904 if (!entry.is_valid()) { | 3907 if (!entry.is_valid()) { |
| 3905 // There is no preparser data for the function, we will not lazily | 3908 // There is no preparser data for the function, we will not lazily |
| 3906 // compile after all. | 3909 // compile after all. |
| 3907 is_lazily_compiled = false; | 3910 is_lazily_compiled = false; |
| 3908 } else { | 3911 } else { |
| 3909 end_pos = entry.end_pos(); | 3912 scope->set_end_position(entry.end_pos()); |
| 3910 if (end_pos <= function_block_pos) { | 3913 if (scope->end_position() <= function_block_pos) { |
| 3911 // End position greater than end of stream is safe, and hard to check. | 3914 // End position greater than end of stream is safe, and hard to check. |
| 3912 ReportInvalidPreparseData(function_name, CHECK_OK); | 3915 ReportInvalidPreparseData(function_name, CHECK_OK); |
| 3913 } | 3916 } |
| 3914 isolate()->counters()->total_preparse_skipped()->Increment( | 3917 isolate()->counters()->total_preparse_skipped()->Increment( |
| 3915 end_pos - function_block_pos); | 3918 scope->end_position() - function_block_pos); |
| 3916 // Seek to position just before terminal '}'. | 3919 // Seek to position just before terminal '}'. |
| 3917 scanner().SeekForward(end_pos - 1); | 3920 scanner().SeekForward(scope->end_position() - 1); |
| 3918 materialized_literal_count = entry.literal_count(); | 3921 materialized_literal_count = entry.literal_count(); |
| 3919 expected_property_count = entry.property_count(); | 3922 expected_property_count = entry.property_count(); |
| 3920 if (entry.strict_mode()) top_scope_->EnableStrictMode(); | 3923 if (entry.strict_mode()) top_scope_->EnableStrictMode(); |
| 3921 only_simple_this_property_assignments = false; | 3924 only_simple_this_property_assignments = false; |
| 3922 this_property_assignments = isolate()->factory()->empty_fixed_array(); | 3925 this_property_assignments = isolate()->factory()->empty_fixed_array(); |
| 3923 Expect(Token::RBRACE, CHECK_OK); | 3926 Expect(Token::RBRACE, CHECK_OK); |
| 3924 } | 3927 } |
| 3925 } | 3928 } |
| 3926 | 3929 |
| 3927 if (!is_lazily_compiled) { | 3930 if (!is_lazily_compiled) { |
| 3928 ParseSourceElements(body, Token::RBRACE, CHECK_OK); | 3931 ParseSourceElements(body, Token::RBRACE, CHECK_OK); |
| 3929 | 3932 |
| 3930 materialized_literal_count = lexical_scope.materialized_literal_count(); | 3933 materialized_literal_count = lexical_scope.materialized_literal_count(); |
| 3931 expected_property_count = lexical_scope.expected_property_count(); | 3934 expected_property_count = lexical_scope.expected_property_count(); |
| 3932 only_simple_this_property_assignments = | 3935 only_simple_this_property_assignments = |
| 3933 lexical_scope.only_simple_this_property_assignments(); | 3936 lexical_scope.only_simple_this_property_assignments(); |
| 3934 this_property_assignments = lexical_scope.this_property_assignments(); | 3937 this_property_assignments = lexical_scope.this_property_assignments(); |
| 3935 | 3938 |
| 3936 Expect(Token::RBRACE, CHECK_OK); | 3939 Expect(Token::RBRACE, CHECK_OK); |
| 3937 end_pos = scanner().location().end_pos; | 3940 scope->set_end_position(scanner().location().end_pos); |
| 3938 } | 3941 } |
| 3939 | 3942 |
| 3940 // Validate strict mode. | 3943 // Validate strict mode. |
| 3941 if (top_scope_->is_strict_mode()) { | 3944 if (top_scope_->is_strict_mode()) { |
| 3942 if (IsEvalOrArguments(function_name)) { | 3945 if (IsEvalOrArguments(function_name)) { |
| 3946 int start_pos = scope->start_position(); |
| 3943 int position = function_token_position != RelocInfo::kNoPosition | 3947 int position = function_token_position != RelocInfo::kNoPosition |
| 3944 ? function_token_position | 3948 ? function_token_position |
| 3945 : (start_pos > 0 ? start_pos - 1 : start_pos); | 3949 : (start_pos > 0 ? start_pos - 1 : start_pos); |
| 3946 Scanner::Location location = Scanner::Location(position, start_pos); | 3950 Scanner::Location location = Scanner::Location(position, start_pos); |
| 3947 ReportMessageAt(location, | 3951 ReportMessageAt(location, |
| 3948 "strict_function_name", Vector<const char*>::empty()); | 3952 "strict_function_name", Vector<const char*>::empty()); |
| 3949 *ok = false; | 3953 *ok = false; |
| 3950 return NULL; | 3954 return NULL; |
| 3951 } | 3955 } |
| 3952 if (name_loc.IsValid()) { | 3956 if (name_loc.IsValid()) { |
| 3953 ReportMessageAt(name_loc, "strict_param_name", | 3957 ReportMessageAt(name_loc, "strict_param_name", |
| 3954 Vector<const char*>::empty()); | 3958 Vector<const char*>::empty()); |
| 3955 *ok = false; | 3959 *ok = false; |
| 3956 return NULL; | 3960 return NULL; |
| 3957 } | 3961 } |
| 3958 if (dupe_loc.IsValid()) { | 3962 if (dupe_loc.IsValid()) { |
| 3959 ReportMessageAt(dupe_loc, "strict_param_dupe", | 3963 ReportMessageAt(dupe_loc, "strict_param_dupe", |
| 3960 Vector<const char*>::empty()); | 3964 Vector<const char*>::empty()); |
| 3961 *ok = false; | 3965 *ok = false; |
| 3962 return NULL; | 3966 return NULL; |
| 3963 } | 3967 } |
| 3964 if (name_is_strict_reserved) { | 3968 if (name_is_strict_reserved) { |
| 3969 int start_pos = scope->start_position(); |
| 3965 int position = function_token_position != RelocInfo::kNoPosition | 3970 int position = function_token_position != RelocInfo::kNoPosition |
| 3966 ? function_token_position | 3971 ? function_token_position |
| 3967 : (start_pos > 0 ? start_pos - 1 : start_pos); | 3972 : (start_pos > 0 ? start_pos - 1 : start_pos); |
| 3968 Scanner::Location location = Scanner::Location(position, start_pos); | 3973 Scanner::Location location = Scanner::Location(position, start_pos); |
| 3969 ReportMessageAt(location, "strict_reserved_word", | 3974 ReportMessageAt(location, "strict_reserved_word", |
| 3970 Vector<const char*>::empty()); | 3975 Vector<const char*>::empty()); |
| 3971 *ok = false; | 3976 *ok = false; |
| 3972 return NULL; | 3977 return NULL; |
| 3973 } | 3978 } |
| 3974 if (reserved_loc.IsValid()) { | 3979 if (reserved_loc.IsValid()) { |
| 3975 ReportMessageAt(reserved_loc, "strict_reserved_word", | 3980 ReportMessageAt(reserved_loc, "strict_reserved_word", |
| 3976 Vector<const char*>::empty()); | 3981 Vector<const char*>::empty()); |
| 3977 *ok = false; | 3982 *ok = false; |
| 3978 return NULL; | 3983 return NULL; |
| 3979 } | 3984 } |
| 3980 CheckOctalLiteral(start_pos, end_pos, CHECK_OK); | 3985 CheckOctalLiteral(scope->start_position(), |
| 3986 scope->end_position(), |
| 3987 CHECK_OK); |
| 3981 } | 3988 } |
| 3982 } | 3989 } |
| 3983 | 3990 |
| 3984 if (harmony_scoping_) { | 3991 if (harmony_scoping_) { |
| 3985 CheckConflictingVarDeclarations(scope, CHECK_OK); | 3992 CheckConflictingVarDeclarations(scope, CHECK_OK); |
| 3986 } | 3993 } |
| 3987 | 3994 |
| 3988 FunctionLiteral* function_literal = | 3995 FunctionLiteral* function_literal = |
| 3989 new(zone()) FunctionLiteral(isolate(), | 3996 new(zone()) FunctionLiteral(isolate(), |
| 3990 function_name, | 3997 function_name, |
| 3991 scope, | 3998 scope, |
| 3992 body, | 3999 body, |
| 3993 materialized_literal_count, | 4000 materialized_literal_count, |
| 3994 expected_property_count, | 4001 expected_property_count, |
| 3995 only_simple_this_property_assignments, | 4002 only_simple_this_property_assignments, |
| 3996 this_property_assignments, | 4003 this_property_assignments, |
| 3997 num_parameters, | 4004 num_parameters, |
| 3998 start_pos, | |
| 3999 end_pos, | |
| 4000 type, | 4005 type, |
| 4001 has_duplicate_parameters); | 4006 has_duplicate_parameters); |
| 4002 function_literal->set_function_token_position(function_token_position); | 4007 function_literal->set_function_token_position(function_token_position); |
| 4003 | 4008 |
| 4004 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 4009 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
| 4005 return function_literal; | 4010 return function_literal; |
| 4006 } | 4011 } |
| 4007 | 4012 |
| 4008 | 4013 |
| 4009 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 4014 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
| (...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5328 result = parser.ParseProgram(source, | 5333 result = parser.ParseProgram(source, |
| 5329 info->is_global(), | 5334 info->is_global(), |
| 5330 info->StrictMode()); | 5335 info->StrictMode()); |
| 5331 } | 5336 } |
| 5332 } | 5337 } |
| 5333 info->SetFunction(result); | 5338 info->SetFunction(result); |
| 5334 return (result != NULL); | 5339 return (result != NULL); |
| 5335 } | 5340 } |
| 5336 | 5341 |
| 5337 } } // namespace v8::internal | 5342 } } // namespace v8::internal |
| OLD | NEW |