Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Unified Diff: src/interpreter/bytecode-generator.cc

Issue 1796893002: [Interpreter] Pops the context to the correct level on return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Adds check that break/continue are not seen in top level scope. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/interpreter/bytecode_expectations/BasicLoops.golden » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « no previous file | test/cctest/interpreter/bytecode_expectations/BasicLoops.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698