| 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 1938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 ExpectSemicolon(CHECK_OK); | 1949 ExpectSemicolon(CHECK_OK); |
| 1950 return new(zone()) ReturnStatement(GetLiteralUndefined()); | 1950 return new(zone()) ReturnStatement(GetLiteralUndefined()); |
| 1951 } | 1951 } |
| 1952 | 1952 |
| 1953 Expression* expr = ParseExpression(true, CHECK_OK); | 1953 Expression* expr = ParseExpression(true, CHECK_OK); |
| 1954 ExpectSemicolon(CHECK_OK); | 1954 ExpectSemicolon(CHECK_OK); |
| 1955 return new(zone()) ReturnStatement(expr); | 1955 return new(zone()) ReturnStatement(expr); |
| 1956 } | 1956 } |
| 1957 | 1957 |
| 1958 | 1958 |
| 1959 Block* Parser::WithHelper(Expression* obj, ZoneStringList* labels, bool* ok) { | |
| 1960 // Parse the statement and collect escaping labels. | |
| 1961 TargetCollector collector; | |
| 1962 Statement* stat; | |
| 1963 { Target target(&this->target_stack_, &collector); | |
| 1964 with_nesting_level_++; | |
| 1965 top_scope_->DeclarationScope()->RecordWithStatement(); | |
| 1966 stat = ParseStatement(labels, CHECK_OK); | |
| 1967 with_nesting_level_--; | |
| 1968 } | |
| 1969 // Create resulting block with two statements. | |
| 1970 // 1: Evaluate the with expression. | |
| 1971 // 2: The try-finally block evaluating the body. | |
| 1972 Block* result = new(zone()) Block(isolate(), NULL, 2, false); | |
| 1973 | |
| 1974 if (result != NULL) { | |
| 1975 result->AddStatement(new(zone()) EnterWithContextStatement(obj)); | |
| 1976 | |
| 1977 // Create body block. | |
| 1978 Block* body = new(zone()) Block(isolate(), NULL, 1, false); | |
| 1979 body->AddStatement(stat); | |
| 1980 | |
| 1981 // Create exit block. | |
| 1982 Block* exit = new(zone()) Block(isolate(), NULL, 1, false); | |
| 1983 exit->AddStatement(new(zone()) ExitContextStatement()); | |
| 1984 | |
| 1985 // Return a try-finally statement. | |
| 1986 TryFinallyStatement* wrapper = new(zone()) TryFinallyStatement(body, exit); | |
| 1987 wrapper->set_escaping_targets(collector.targets()); | |
| 1988 result->AddStatement(wrapper); | |
| 1989 } | |
| 1990 return result; | |
| 1991 } | |
| 1992 | |
| 1993 | |
| 1994 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { | 1959 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { |
| 1995 // WithStatement :: | 1960 // WithStatement :: |
| 1996 // 'with' '(' Expression ')' Statement | 1961 // 'with' '(' Expression ')' Statement |
| 1997 | 1962 |
| 1998 Expect(Token::WITH, CHECK_OK); | 1963 Expect(Token::WITH, CHECK_OK); |
| 1999 | 1964 |
| 2000 if (top_scope_->is_strict_mode()) { | 1965 if (top_scope_->is_strict_mode()) { |
| 2001 ReportMessage("strict_mode_with", Vector<const char*>::empty()); | 1966 ReportMessage("strict_mode_with", Vector<const char*>::empty()); |
| 2002 *ok = false; | 1967 *ok = false; |
| 2003 return NULL; | 1968 return NULL; |
| 2004 } | 1969 } |
| 2005 | 1970 |
| 2006 Expect(Token::LPAREN, CHECK_OK); | 1971 Expect(Token::LPAREN, CHECK_OK); |
| 2007 Expression* expr = ParseExpression(true, CHECK_OK); | 1972 Expression* expr = ParseExpression(true, CHECK_OK); |
| 2008 Expect(Token::RPAREN, CHECK_OK); | 1973 Expect(Token::RPAREN, CHECK_OK); |
| 2009 | 1974 |
| 2010 return WithHelper(expr, labels, CHECK_OK); | 1975 ++with_nesting_level_; |
| 1976 top_scope_->DeclarationScope()->RecordWithStatement(); |
| 1977 Statement* stmt = ParseStatement(labels, CHECK_OK); |
| 1978 --with_nesting_level_; |
| 1979 return new(zone()) WithStatement(expr, stmt); |
| 2011 } | 1980 } |
| 2012 | 1981 |
| 2013 | 1982 |
| 2014 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { | 1983 CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { |
| 2015 // CaseClause :: | 1984 // CaseClause :: |
| 2016 // 'case' Expression ':' Statement* | 1985 // 'case' Expression ':' Statement* |
| 2017 // 'default' ':' Statement* | 1986 // 'default' ':' Statement* |
| 2018 | 1987 |
| 2019 Expression* label = NULL; // NULL expression indicates default case | 1988 Expression* label = NULL; // NULL expression indicates default case |
| 2020 if (peek() == Token::CASE) { | 1989 if (peek() == Token::CASE) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 | 2104 |
| 2136 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) { | 2105 if (top_scope_->is_strict_mode() && IsEvalOrArguments(name)) { |
| 2137 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); | 2106 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); |
| 2138 *ok = false; | 2107 *ok = false; |
| 2139 return NULL; | 2108 return NULL; |
| 2140 } | 2109 } |
| 2141 | 2110 |
| 2142 Expect(Token::RPAREN, CHECK_OK); | 2111 Expect(Token::RPAREN, CHECK_OK); |
| 2143 | 2112 |
| 2144 if (peek() == Token::LBRACE) { | 2113 if (peek() == Token::LBRACE) { |
| 2145 // Rewrite the catch body B to a single statement block | 2114 // Rewrite the catch body { B } to a block: |
| 2146 // { try B finally { PopContext }}. | 2115 // { { B } ExitContext; }. |
| 2147 Block* inner_body; | 2116 Target target(&this->target_stack_, &catch_collector); |
| 2148 // We need to collect escapes from the body for both the inner | 2117 catch_scope = NewScope(top_scope_, Scope::CATCH_SCOPE, inside_with()); |
| 2149 // try/finally used to pop the catch context and any possible outer | 2118 if (top_scope_->is_strict_mode()) { |
| 2150 // try/finally. | 2119 catch_scope->EnableStrictMode(); |
| 2151 TargetCollector inner_collector; | 2120 } |
| 2152 { Target target(&this->target_stack_, &catch_collector); | 2121 catch_variable = catch_scope->DeclareLocal(name, Variable::VAR); |
| 2153 { Target target(&this->target_stack_, &inner_collector); | 2122 catch_block = new(zone()) Block(isolate(), NULL, 2, false); |
| 2154 catch_scope = NewScope(top_scope_, Scope::CATCH_SCOPE, inside_with()); | |
| 2155 if (top_scope_->is_strict_mode()) { | |
| 2156 catch_scope->EnableStrictMode(); | |
| 2157 } | |
| 2158 catch_variable = catch_scope->DeclareLocal(name, Variable::VAR); | |
| 2159 | 2123 |
| 2160 Scope* saved_scope = top_scope_; | 2124 Scope* saved_scope = top_scope_; |
| 2161 top_scope_ = catch_scope; | 2125 top_scope_ = catch_scope; |
| 2162 inner_body = ParseBlock(NULL, CHECK_OK); | 2126 Block* catch_body = ParseBlock(NULL, CHECK_OK); |
| 2163 top_scope_ = saved_scope; | 2127 top_scope_ = saved_scope; |
| 2164 } | 2128 catch_block->AddStatement(catch_body); |
| 2165 } | 2129 catch_block->AddStatement(new(zone()) ExitContextStatement()); |
| 2166 | |
| 2167 // Create exit block. | |
| 2168 Block* inner_finally = new(zone()) Block(isolate(), NULL, 1, false); | |
| 2169 inner_finally->AddStatement(new(zone()) ExitContextStatement()); | |
| 2170 | |
| 2171 // Create a try/finally statement. | |
| 2172 TryFinallyStatement* inner_try_finally = | |
| 2173 new(zone()) TryFinallyStatement(inner_body, inner_finally); | |
| 2174 inner_try_finally->set_escaping_targets(inner_collector.targets()); | |
| 2175 | |
| 2176 catch_block = new(zone()) Block(isolate(), NULL, 1, false); | |
| 2177 catch_block->AddStatement(inner_try_finally); | |
| 2178 } else { | 2130 } else { |
| 2179 Expect(Token::LBRACE, CHECK_OK); | 2131 Expect(Token::LBRACE, CHECK_OK); |
| 2180 } | 2132 } |
| 2181 | 2133 |
| 2182 tok = peek(); | 2134 tok = peek(); |
| 2183 } | 2135 } |
| 2184 | 2136 |
| 2185 Block* finally_block = NULL; | 2137 Block* finally_block = NULL; |
| 2186 if (tok == Token::FINALLY || catch_block == NULL) { | 2138 if (tok == Token::FINALLY || catch_block == NULL) { |
| 2187 Consume(Token::FINALLY); | 2139 Consume(Token::FINALLY); |
| (...skipping 2941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5129 info->is_global(), | 5081 info->is_global(), |
| 5130 info->StrictMode()); | 5082 info->StrictMode()); |
| 5131 } | 5083 } |
| 5132 } | 5084 } |
| 5133 | 5085 |
| 5134 info->SetFunction(result); | 5086 info->SetFunction(result); |
| 5135 return (result != NULL); | 5087 return (result != NULL); |
| 5136 } | 5088 } |
| 5137 | 5089 |
| 5138 } } // namespace v8::internal | 5090 } } // namespace v8::internal |
| OLD | NEW |