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 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 } | 1552 } |
1553 | 1553 |
1554 | 1554 |
1555 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { | 1555 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { |
1556 // Construct block expecting 16 statements. | 1556 // Construct block expecting 16 statements. |
1557 Block* body = new(zone()) Block(isolate(), labels, 16, false); | 1557 Block* body = new(zone()) Block(isolate(), labels, 16, false); |
1558 Scope* saved_scope = top_scope_; | 1558 Scope* saved_scope = top_scope_; |
1559 Scope* block_scope = NewScope(top_scope_, | 1559 Scope* block_scope = NewScope(top_scope_, |
1560 Scope::BLOCK_SCOPE, | 1560 Scope::BLOCK_SCOPE, |
1561 inside_with()); | 1561 inside_with()); |
1562 body->set_block_scope(block_scope); | |
1563 block_scope->DeclareLocal(isolate()->factory()->block_scope_symbol(), | |
1564 Variable::VAR); | |
1565 if (top_scope_->is_strict_mode()) { | 1562 if (top_scope_->is_strict_mode()) { |
1566 block_scope->EnableStrictMode(); | 1563 block_scope->EnableStrictMode(); |
1567 } | 1564 } |
1568 top_scope_ = block_scope; | 1565 top_scope_ = block_scope; |
1569 | 1566 |
1570 // Parse the statements and collect escaping labels. | 1567 // Parse the statements and collect escaping labels. |
1571 TargetCollector collector; | 1568 TargetCollector collector; |
1572 Target target(&this->target_stack_, &collector); | 1569 Target target(&this->target_stack_, &collector); |
1573 Expect(Token::LBRACE, CHECK_OK); | 1570 Expect(Token::LBRACE, CHECK_OK); |
1574 { | 1571 { |
1575 Target target_body(&this->target_stack_, body); | 1572 Target target_body(&this->target_stack_, body); |
1576 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 1573 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
1577 | 1574 |
1578 while (peek() != Token::RBRACE) { | 1575 while (peek() != Token::RBRACE) { |
1579 Statement* stat = ParseSourceElement(NULL, CHECK_OK); | 1576 Statement* stat = ParseSourceElement(NULL, CHECK_OK); |
1580 if (stat && !stat->IsEmpty()) { | 1577 if (stat && !stat->IsEmpty()) { |
1581 body->AddStatement(stat); | 1578 body->AddStatement(stat); |
1582 block_finder.Update(stat); | 1579 block_finder.Update(stat); |
1583 } | 1580 } |
1584 } | 1581 } |
1585 } | 1582 } |
1586 Expect(Token::RBRACE, CHECK_OK); | 1583 Expect(Token::RBRACE, CHECK_OK); |
1587 | |
1588 // Create exit block. | |
1589 Block* exit = new(zone()) Block(isolate(), NULL, 1, false); | |
1590 exit->AddStatement(new(zone()) ExitContextStatement()); | |
1591 | |
1592 // Create a try-finally statement. | |
1593 TryFinallyStatement* try_finally = | |
1594 new(zone()) TryFinallyStatement(body, exit); | |
1595 try_finally->set_escaping_targets(collector.targets()); | |
1596 top_scope_ = saved_scope; | 1584 top_scope_ = saved_scope; |
1597 | 1585 |
1598 // Create a result block. | 1586 block_scope = block_scope->FinalizeBlockScope(); |
1599 Block* result = new(zone()) Block(isolate(), NULL, 1, false); | 1587 body->set_block_scope(block_scope); |
1600 result->AddStatement(try_finally); | 1588 |
1601 return result; | 1589 if (block_scope != NULL) { |
| 1590 // Create exit block. |
| 1591 Block* exit = new(zone()) Block(isolate(), NULL, 1, false); |
| 1592 exit->AddStatement(new(zone()) ExitContextStatement()); |
| 1593 |
| 1594 // Create a try-finally statement. |
| 1595 TryFinallyStatement* try_finally = |
| 1596 new(zone()) TryFinallyStatement(body, exit); |
| 1597 try_finally->set_escaping_targets(collector.targets()); |
| 1598 |
| 1599 // Create a result block. |
| 1600 Block* result = new(zone()) Block(isolate(), NULL, 1, false); |
| 1601 result->AddStatement(try_finally); |
| 1602 return result; |
| 1603 } else { |
| 1604 return body; |
| 1605 } |
1602 } | 1606 } |
1603 | 1607 |
1604 | 1608 |
1605 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, | 1609 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, |
1606 bool* ok) { | 1610 bool* ok) { |
1607 // VariableStatement :: | 1611 // VariableStatement :: |
1608 // VariableDeclarations ';' | 1612 // VariableDeclarations ';' |
1609 | 1613 |
1610 Handle<String> ignore; | 1614 Handle<String> ignore; |
1611 Block* result = ParseVariableDeclarations(var_context, | 1615 Block* result = ParseVariableDeclarations(var_context, |
(...skipping 3624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5236 result = parser.ParseProgram(source, | 5240 result = parser.ParseProgram(source, |
5237 info->is_global(), | 5241 info->is_global(), |
5238 info->StrictMode()); | 5242 info->StrictMode()); |
5239 } | 5243 } |
5240 } | 5244 } |
5241 info->SetFunction(result); | 5245 info->SetFunction(result); |
5242 return (result != NULL); | 5246 return (result != NULL); |
5243 } | 5247 } |
5244 | 5248 |
5245 } } // namespace v8::internal | 5249 } } // namespace v8::internal |
OLD | NEW |