Chromium Code Reviews| Index: src/interpreter/bytecode-generator.cc |
| diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc |
| index 412c0d34356c56e3988c29f9da2418c6d2a00721..85eb91cc0ecda2458418ea73eb42b3f9d3db907b 100644 |
| --- a/src/interpreter/bytecode-generator.cc |
| +++ b/src/interpreter/bytecode-generator.cc |
| @@ -72,6 +72,7 @@ class BytecodeGenerator::ContextScope BASE_EMBEDDED { |
| Scope* scope() const { return scope_; } |
| Register reg() const { return register_; } |
| + bool ShouldPopContext() { return should_pop_context_; } |
| private: |
| const BytecodeArrayBuilder* builder() const { return generator_->builder(); } |
| @@ -212,15 +213,15 @@ class BytecodeGenerator::ControlScopeForTopLevel final |
| protected: |
| bool Execute(Command command, Statement* statement) override { |
| switch (command) { |
| - case CMD_BREAK: |
| - case CMD_CONTINUE: |
| - break; |
| case CMD_RETURN: |
| generator()->builder()->Return(); |
| return true; |
| case CMD_RETHROW: |
| generator()->builder()->ReThrow(); |
| return true; |
| + case CMD_BREAK: // We should never see break/continue in top-level. |
|
Michael Starzinger
2016/03/16 14:16:53
nit: Please leave the cases in the same order as e
mythria
2016/03/16 14:33:19
Done.
|
| + case CMD_CONTINUE: |
| + UNREACHABLE(); |
| } |
| return false; |
| } |
| @@ -363,21 +364,20 @@ void BytecodeGenerator::ControlScope::PerformCommand(Command command, |
| Statement* statement) { |
| ControlScope* current = this; |
| ContextScope* context = generator()->execution_context(); |
| + // Do not pop if it is the outermost context. |
|
rmcilroy
2016/03/16 12:07:28
This comment is a bit confusing. Could you make th
mythria
2016/03/16 14:33:19
Done.
|
| + if (context != current->context() && context->ShouldPopContext()) { |
| + generator()->builder()->PopContext(current->context()->reg()); |
| + } |
| do { |
| - if (current->context() != context) { |
| - // Pop context to the expected depth for break and continue. For return |
| - // and throw it is not required to pop. Debugger expects that the |
| - // context is not popped on return. So do not pop on return. |
| - // TODO(rmcilroy): Only emit a single context pop. |
| - if (command == CMD_BREAK || command == CMD_CONTINUE) { |
| - generator()->builder()->PopContext(current->context()->reg()); |
| - } |
| - context = current->context(); |
| - } |
| if (current->Execute(command, statement)) { |
| return; |
| } |
| current = current->outer(); |
| + if (current->context() != context) { |
| + // Pop context to the expected depth. |
| + // TODO(rmcilroy): Only emit a single context pop. |
| + generator()->builder()->PopContext(current->context()->reg()); |
| + } |
| } while (current != nullptr); |
| UNREACHABLE(); |
| } |