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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 #undef DEF_VISIT | 211 #undef DEF_VISIT |
212 | 212 |
213 | 213 |
214 // Assumes code has been parsed and scopes have been analyzed. Mutates the | 214 // Assumes code has been parsed and scopes have been analyzed. Mutates the |
215 // AST, so the AST should not continue to be used in the case of failure. | 215 // AST, so the AST should not continue to be used in the case of failure. |
216 bool Rewriter::Rewrite(CompilationInfo* info) { | 216 bool Rewriter::Rewrite(CompilationInfo* info) { |
217 FunctionLiteral* function = info->function(); | 217 FunctionLiteral* function = info->function(); |
218 ASSERT(function != NULL); | 218 ASSERT(function != NULL); |
219 Scope* scope = function->scope(); | 219 Scope* scope = function->scope(); |
220 ASSERT(scope != NULL); | 220 ASSERT(scope != NULL); |
221 if (scope->is_function_scope()) return true; | 221 if (!scope->is_global_scope() && !scope->is_eval_scope()) return true; |
222 | 222 |
223 ZoneList<Statement*>* body = function->body(); | 223 ZoneList<Statement*>* body = function->body(); |
224 if (!body->is_empty()) { | 224 if (!body->is_empty()) { |
225 Variable* result = scope->NewTemporary( | 225 Variable* result = scope->NewTemporary( |
226 info->isolate()->factory()->result_symbol()); | 226 info->isolate()->factory()->result_symbol()); |
227 Processor processor(result); | 227 Processor processor(result); |
228 processor.Process(body); | 228 processor.Process(body); |
229 if (processor.HasStackOverflow()) return false; | 229 if (processor.HasStackOverflow()) return false; |
230 | 230 |
231 if (processor.result_assigned()) { | 231 if (processor.result_assigned()) { |
232 VariableProxy* result_proxy = new VariableProxy(result); | 232 VariableProxy* result_proxy = new VariableProxy(result); |
233 body->Add(new ReturnStatement(result_proxy)); | 233 body->Add(new ReturnStatement(result_proxy)); |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
237 return true; | 237 return true; |
238 } | 238 } |
239 | 239 |
240 | 240 |
241 } } // namespace v8::internal | 241 } } // namespace v8::internal |
OLD | NEW |