OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 bool Rewriter::Rewrite(CompilationInfo* info) { | 246 bool Rewriter::Rewrite(CompilationInfo* info) { |
247 FunctionLiteral* function = info->function(); | 247 FunctionLiteral* function = info->function(); |
248 ASSERT(function != NULL); | 248 ASSERT(function != NULL); |
249 Scope* scope = function->scope(); | 249 Scope* scope = function->scope(); |
250 ASSERT(scope != NULL); | 250 ASSERT(scope != NULL); |
251 if (!scope->is_global_scope() && !scope->is_eval_scope()) return true; | 251 if (!scope->is_global_scope() && !scope->is_eval_scope()) return true; |
252 | 252 |
253 ZoneList<Statement*>* body = function->body(); | 253 ZoneList<Statement*>* body = function->body(); |
254 if (!body->is_empty()) { | 254 if (!body->is_empty()) { |
255 Variable* result = scope->NewTemporary( | 255 Variable* result = scope->NewTemporary( |
256 info->isolate()->factory()->result_symbol()); | 256 info->isolate()->factory()->result_string()); |
257 Processor processor(result, info->zone()); | 257 Processor processor(result, info->zone()); |
258 processor.Process(body); | 258 processor.Process(body); |
259 if (processor.HasStackOverflow()) return false; | 259 if (processor.HasStackOverflow()) return false; |
260 | 260 |
261 if (processor.result_assigned()) { | 261 if (processor.result_assigned()) { |
262 ASSERT(function->end_position() != RelocInfo::kNoPosition); | 262 ASSERT(function->end_position() != RelocInfo::kNoPosition); |
263 // Set the position of the assignment statement one character past the | 263 // Set the position of the assignment statement one character past the |
264 // source code, such that it definitely is not in the source code range | 264 // source code, such that it definitely is not in the source code range |
265 // of an immediate inner scope. For example in | 265 // of an immediate inner scope. For example in |
266 // eval('with ({x:1}) x = 1'); | 266 // eval('with ({x:1}) x = 1'); |
267 // the end position of the function generated for executing the eval code | 267 // the end position of the function generated for executing the eval code |
268 // coincides with the end of the with scope which is the position of '1'. | 268 // coincides with the end of the with scope which is the position of '1'. |
269 int position = function->end_position(); | 269 int position = function->end_position(); |
270 VariableProxy* result_proxy = processor.factory()->NewVariableProxy( | 270 VariableProxy* result_proxy = processor.factory()->NewVariableProxy( |
271 result->name(), false, result->interface(), position); | 271 result->name(), false, result->interface(), position); |
272 result_proxy->BindTo(result); | 272 result_proxy->BindTo(result); |
273 Statement* result_statement = | 273 Statement* result_statement = |
274 processor.factory()->NewReturnStatement(result_proxy); | 274 processor.factory()->NewReturnStatement(result_proxy); |
275 result_statement->set_statement_pos(position); | 275 result_statement->set_statement_pos(position); |
276 body->Add(result_statement, info->zone()); | 276 body->Add(result_statement, info->zone()); |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 return true; | 280 return true; |
281 } | 281 } |
282 | 282 |
283 | 283 |
284 } } // namespace v8::internal | 284 } } // namespace v8::internal |
OLD | NEW |