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, AstNode::IdGen* ast_node_id_gen) | 18 Processor(Variable* result, AstValueFactory* ast_value_factory) |
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 // Passing a null AstValueFactory is fine, because Processor doesn't | 23 factory_(ast_value_factory) { |
24 // need to create strings or literals. | 24 InitializeAstVisitor(ast_value_factory->zone()); |
25 factory_(zone, NULL, ast_node_id_gen) { | |
26 InitializeAstVisitor(zone); | |
27 } | 25 } |
28 | 26 |
29 virtual ~Processor() { } | 27 virtual ~Processor() { } |
30 | 28 |
31 void Process(ZoneList<Statement*>* statements); | 29 void Process(ZoneList<Statement*>* statements); |
32 bool result_assigned() const { return result_assigned_; } | 30 bool result_assigned() const { return result_assigned_; } |
33 | 31 |
34 AstNodeFactory<AstNullVisitor>* factory() { | 32 AstNodeFactory<AstNullVisitor>* factory() { |
35 return &factory_; | 33 return &factory_; |
36 } | 34 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 Scope* scope = function->scope(); | 231 Scope* scope = function->scope(); |
234 DCHECK(scope != NULL); | 232 DCHECK(scope != NULL); |
235 if (!scope->is_global_scope() && !scope->is_eval_scope()) return true; | 233 if (!scope->is_global_scope() && !scope->is_eval_scope()) return true; |
236 | 234 |
237 ZoneList<Statement*>* body = function->body(); | 235 ZoneList<Statement*>* body = function->body(); |
238 if (!body->is_empty()) { | 236 if (!body->is_empty()) { |
239 Variable* result = | 237 Variable* result = |
240 scope->NewTemporary(info->ast_value_factory()->dot_result_string()); | 238 scope->NewTemporary(info->ast_value_factory()->dot_result_string()); |
241 // The name string must be internalized at this point. | 239 // The name string must be internalized at this point. |
242 DCHECK(!result->name().is_null()); | 240 DCHECK(!result->name().is_null()); |
243 Processor processor(result, info->zone(), info->ast_node_id_gen()); | 241 Processor processor(result, info->ast_value_factory()); |
244 processor.Process(body); | 242 processor.Process(body); |
245 if (processor.HasStackOverflow()) return false; | 243 if (processor.HasStackOverflow()) return false; |
246 | 244 |
247 if (processor.result_assigned()) { | 245 if (processor.result_assigned()) { |
248 DCHECK(function->end_position() != RelocInfo::kNoPosition); | 246 DCHECK(function->end_position() != RelocInfo::kNoPosition); |
249 // Set the position of the assignment statement one character past the | 247 // Set the position of the assignment statement one character past the |
250 // source code, such that it definitely is not in the source code range | 248 // source code, such that it definitely is not in the source code range |
251 // of an immediate inner scope. For example in | 249 // of an immediate inner scope. For example in |
252 // eval('with ({x:1}) x = 1'); | 250 // eval('with ({x:1}) x = 1'); |
253 // the end position of the function generated for executing the eval code | 251 // the end position of the function generated for executing the eval code |
254 // coincides with the end of the with scope which is the position of '1'. | 252 // coincides with the end of the with scope which is the position of '1'. |
255 int pos = function->end_position(); | 253 int pos = function->end_position(); |
256 VariableProxy* result_proxy = | 254 VariableProxy* result_proxy = |
257 processor.factory()->NewVariableProxy(result, pos); | 255 processor.factory()->NewVariableProxy(result, pos); |
258 Statement* result_statement = | 256 Statement* result_statement = |
259 processor.factory()->NewReturnStatement(result_proxy, pos); | 257 processor.factory()->NewReturnStatement(result_proxy, pos); |
260 body->Add(result_statement, info->zone()); | 258 body->Add(result_statement, info->zone()); |
261 } | 259 } |
262 } | 260 } |
263 | 261 |
264 return true; | 262 return true; |
265 } | 263 } |
266 | 264 |
267 | 265 |
268 } } // namespace v8::internal | 266 } } // namespace v8::internal |
OLD | NEW |