| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef V8_COMPILER_AST_GRAPH_BUILDER_H_ | 5 #ifndef V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| 6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ | 6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/ast.h" | 10 #include "src/ast.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 // mutations of the context chain within the function body and allows to | 415 // mutations of the context chain within the function body and allows to |
| 416 // change the current {scope} and {context} during visitation. | 416 // change the current {scope} and {context} during visitation. |
| 417 class AstGraphBuilder::ContextScope BASE_EMBEDDED { | 417 class AstGraphBuilder::ContextScope BASE_EMBEDDED { |
| 418 public: | 418 public: |
| 419 ContextScope(AstGraphBuilder* owner, Scope* scope, Node* context) | 419 ContextScope(AstGraphBuilder* owner, Scope* scope, Node* context) |
| 420 : owner_(owner), | 420 : owner_(owner), |
| 421 next_(owner->execution_context()), | 421 next_(owner->execution_context()), |
| 422 outer_(owner->current_context()), | 422 outer_(owner->current_context()), |
| 423 scope_(scope) { | 423 scope_(scope) { |
| 424 owner_->set_execution_context(this); // Push. | 424 owner_->set_execution_context(this); // Push. |
| 425 owner_->set_current_context(context); | 425 if (context != nullptr) { |
| 426 owner_->set_current_context(context); |
| 427 need_context = true; |
| 428 } else { |
| 429 need_context = false; |
| 430 } |
| 426 } | 431 } |
| 427 | 432 |
| 428 ~ContextScope() { | 433 ~ContextScope() { |
| 429 owner_->set_execution_context(next_); // Pop. | 434 owner_->set_execution_context(next_); // Pop. |
| 430 owner_->set_current_context(outer_); | 435 if (need_context) { |
| 436 owner_->set_current_context(outer_); |
| 437 } |
| 431 } | 438 } |
| 432 | 439 |
| 433 // Current scope during visitation. | 440 // Current scope during visitation. |
| 434 Scope* scope() const { return scope_; } | 441 Scope* scope() const { return scope_; } |
| 435 | 442 |
| 436 private: | 443 private: |
| 437 AstGraphBuilder* owner_; | 444 AstGraphBuilder* owner_; |
| 438 ContextScope* next_; | 445 ContextScope* next_; |
| 439 Node* outer_; | 446 Node* outer_; |
| 440 Scope* scope_; | 447 Scope* scope_; |
| 448 bool need_context; |
| 441 }; | 449 }; |
| 442 | 450 |
| 443 Scope* AstGraphBuilder::current_scope() const { | 451 Scope* AstGraphBuilder::current_scope() const { |
| 444 return execution_context_->scope(); | 452 return execution_context_->scope(); |
| 445 } | 453 } |
| 446 | 454 |
| 447 } // namespace compiler | 455 } // namespace compiler |
| 448 } // namespace internal | 456 } // namespace internal |
| 449 } // namespace v8 | 457 } // namespace v8 |
| 450 | 458 |
| 451 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 459 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| OLD | NEW |