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