OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/rewriter.h" | 7 #include "src/rewriter.h" |
8 | 8 |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
11 #include "src/scopes.h" | 11 #include "src/scopes.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 class Processor: public AstVisitor { | 16 class Processor: public AstVisitor { |
17 public: | 17 public: |
18 Processor(Variable* result, Zone* zone) | 18 Processor(Variable* result, Zone* zone) |
19 : result_(result), | 19 : result_(result), |
20 result_assigned_(false), | 20 result_assigned_(false), |
21 is_set_(false), | 21 is_set_(false), |
22 in_try_(false), | 22 in_try_(false), |
23 factory_(zone) { | 23 // Passing a null AstValueFactory is fine, because Processor doesn't |
| 24 // need to create strings or literals. |
| 25 factory_(zone, NULL) { |
24 InitializeAstVisitor(zone); | 26 InitializeAstVisitor(zone); |
25 } | 27 } |
26 | 28 |
27 virtual ~Processor() { } | 29 virtual ~Processor() { } |
28 | 30 |
29 void Process(ZoneList<Statement*>* statements); | 31 void Process(ZoneList<Statement*>* statements); |
30 bool result_assigned() const { return result_assigned_; } | 32 bool result_assigned() const { return result_assigned_; } |
31 | 33 |
32 AstNodeFactory<AstNullVisitor>* factory() { | 34 AstNodeFactory<AstNullVisitor>* factory() { |
33 return &factory_; | 35 return &factory_; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // continue to be used in the case of failure. | 229 // continue to be used in the case of failure. |
228 bool Rewriter::Rewrite(CompilationInfo* info) { | 230 bool Rewriter::Rewrite(CompilationInfo* info) { |
229 FunctionLiteral* function = info->function(); | 231 FunctionLiteral* function = info->function(); |
230 ASSERT(function != NULL); | 232 ASSERT(function != NULL); |
231 Scope* scope = function->scope(); | 233 Scope* scope = function->scope(); |
232 ASSERT(scope != NULL); | 234 ASSERT(scope != NULL); |
233 if (!scope->is_global_scope() && !scope->is_eval_scope()) return true; | 235 if (!scope->is_global_scope() && !scope->is_eval_scope()) return true; |
234 | 236 |
235 ZoneList<Statement*>* body = function->body(); | 237 ZoneList<Statement*>* body = function->body(); |
236 if (!body->is_empty()) { | 238 if (!body->is_empty()) { |
237 Variable* result = scope->NewTemporary( | 239 Variable* result = |
238 info->isolate()->factory()->dot_result_string()); | 240 scope->NewTemporary(info->ast_value_factory()->dot_result_string()); |
| 241 // The name string must be internalized at this point. |
| 242 ASSERT(!result->name().is_null()); |
239 Processor processor(result, info->zone()); | 243 Processor processor(result, info->zone()); |
240 processor.Process(body); | 244 processor.Process(body); |
241 if (processor.HasStackOverflow()) return false; | 245 if (processor.HasStackOverflow()) return false; |
242 | 246 |
243 if (processor.result_assigned()) { | 247 if (processor.result_assigned()) { |
244 ASSERT(function->end_position() != RelocInfo::kNoPosition); | 248 ASSERT(function->end_position() != RelocInfo::kNoPosition); |
245 // Set the position of the assignment statement one character past the | 249 // Set the position of the assignment statement one character past the |
246 // source code, such that it definitely is not in the source code range | 250 // source code, such that it definitely is not in the source code range |
247 // of an immediate inner scope. For example in | 251 // of an immediate inner scope. For example in |
248 // eval('with ({x:1}) x = 1'); | 252 // eval('with ({x:1}) x = 1'); |
249 // the end position of the function generated for executing the eval code | 253 // the end position of the function generated for executing the eval code |
250 // coincides with the end of the with scope which is the position of '1'. | 254 // coincides with the end of the with scope which is the position of '1'. |
251 int pos = function->end_position(); | 255 int pos = function->end_position(); |
252 VariableProxy* result_proxy = processor.factory()->NewVariableProxy( | 256 VariableProxy* result_proxy = processor.factory()->NewVariableProxy( |
253 result->name(), false, result->interface(), pos); | 257 result->raw_name(), false, result->interface(), pos); |
254 result_proxy->BindTo(result); | 258 result_proxy->BindTo(result); |
255 Statement* result_statement = | 259 Statement* result_statement = |
256 processor.factory()->NewReturnStatement(result_proxy, pos); | 260 processor.factory()->NewReturnStatement(result_proxy, pos); |
257 body->Add(result_statement, info->zone()); | 261 body->Add(result_statement, info->zone()); |
258 } | 262 } |
259 } | 263 } |
260 | 264 |
261 return true; | 265 return true; |
262 } | 266 } |
263 | 267 |
264 | 268 |
265 } } // namespace v8::internal | 269 } } // namespace v8::internal |
OLD | NEW |