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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 1601153002: [Interpreter] Ensure that block breaks are within the correct context scope. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/interpreter/bytecode-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/interpreter/bytecode-register-allocator.h" 9 #include "src/interpreter/bytecode-register-allocator.h"
10 #include "src/interpreter/control-flow-builders.h" 10 #include "src/interpreter/control-flow-builders.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 415
416 // Visit declarations within the function scope. 416 // Visit declarations within the function scope.
417 VisitDeclarations(scope()->declarations()); 417 VisitDeclarations(scope()->declarations());
418 418
419 // Visit statements in the function body. 419 // Visit statements in the function body.
420 VisitStatements(info()->literal()->body()); 420 VisitStatements(info()->literal()->body());
421 } 421 }
422 422
423 423
424 void BytecodeGenerator::VisitBlock(Block* stmt) { 424 void BytecodeGenerator::VisitBlock(Block* stmt) {
425 BlockBuilder block_builder(this->builder()); 425 // Visit declarations and statements.
426 if (stmt->scope() != nullptr && stmt->scope()->NeedsContext()) {
427 VisitNewLocalBlockContext(stmt->scope());
428 ContextScope scope(this, stmt->scope());
429 VisitBlockDeclarationsAndStatements(stmt);
430 } else {
431 VisitBlockDeclarationsAndStatements(stmt);
432 }
433 }
434
435
436 void BytecodeGenerator::VisitBlockDeclarationsAndStatements(Block* stmt) {
437 BlockBuilder block_builder(builder());
426 ControlScopeForBreakable execution_control(this, stmt, &block_builder); 438 ControlScopeForBreakable execution_control(this, stmt, &block_builder);
427 439 if (stmt->scope() != nullptr) {
428 if (stmt->scope() == NULL) { 440 VisitDeclarations(stmt->scope()->declarations());
429 // Visit statements in the same scope, no declarations.
430 VisitStatements(stmt->statements());
431 } else {
432 // Visit declarations and statements in a block scope.
433 if (stmt->scope()->NeedsContext()) {
434 VisitNewLocalBlockContext(stmt->scope());
435 ContextScope scope(this, stmt->scope());
436 VisitDeclarations(stmt->scope()->declarations());
437 VisitStatements(stmt->statements());
438 } else {
439 VisitDeclarations(stmt->scope()->declarations());
440 VisitStatements(stmt->statements());
441 }
442 } 441 }
442 VisitStatements(stmt->statements());
443 if (stmt->labels() != nullptr) block_builder.EndBlock(); 443 if (stmt->labels() != nullptr) block_builder.EndBlock();
444 } 444 }
445 445
446 446
447 void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { 447 void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) {
448 Variable* variable = decl->proxy()->var(); 448 Variable* variable = decl->proxy()->var();
449 VariableMode mode = decl->mode(); 449 VariableMode mode = decl->mode();
450 // Const and let variables are initialized with the hole so that we can 450 // Const and let variables are initialized with the hole so that we can
451 // check that they are only assigned once. 451 // check that they are only assigned once.
452 bool hole_init = mode == CONST || mode == CONST_LEGACY || mode == LET; 452 bool hole_init = mode == CONST || mode == CONST_LEGACY || mode == LET;
(...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 } 2216 }
2217 2217
2218 2218
2219 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 2219 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
2220 return info()->feedback_vector()->GetIndex(slot); 2220 return info()->feedback_vector()->GetIndex(slot);
2221 } 2221 }
2222 2222
2223 } // namespace interpreter 2223 } // namespace interpreter
2224 } // namespace internal 2224 } // namespace internal
2225 } // namespace v8 2225 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698