Commit 09de9969 authored by yangguo's avatar yangguo Committed by Commit bot

[debugger] fix switch block source positions.

The switch statement itself is part of the switch block.
However, the source position of the statement is outside of
the block. This leads to confusion for the debugger, if the
switch block pushes a block context: the current context is
a block context, but the scope analysis based on the current
source position tells the debugger that we should be outside
the scope, so we should have the function context.

R=marja@chromium.org
BUG=v8:6085

Review-Url: https://codereview.chromium.org/2744213003
Cr-Commit-Position: refs/heads/master@{#43744}
parent 098f939d
......@@ -5194,7 +5194,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseSwitchStatement(
{
BlockState cases_block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
scope()->set_start_position(switch_pos);
scope()->SetNonlinear();
typename Types::Target target(this, switch_statement);
......
......@@ -1665,6 +1665,10 @@ Statement* Parser::RewriteSwitchStatement(Expression* tag,
Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
cases_block->statements()->Add(switch_statement, zone());
cases_block->set_scope(scope);
DCHECK_IMPLIES(scope != nullptr,
switch_statement->position() >= scope->start_position());
DCHECK_IMPLIES(scope != nullptr,
switch_statement->position() < scope->end_position());
switch_block->statements()->Add(cases_block, zone());
return switch_block;
}
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function* serialize() {
debugger;
switch (0) {
case 0:
let x = 1;
return x; // Check scopes
}
}
let exception = null;
let step_count = 0;
let scopes_checked = false;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
if (exec_state.frame().sourceLineText().includes("Check scopes")) {
let expected = [ debug.ScopeType.Block,
debug.ScopeType.Local,
debug.ScopeType.Script,
debug.ScopeType.Global ];
for (let i = 0; i < exec_state.frame().scopeCount(); i++) {
assertEquals(expected[i], exec_state.frame().scope(i).scopeType());
}
scopes_checked = true;
}
if (step_count++ < 3) exec_state.prepareStep(Debug.StepAction.StepNext);
} catch (e) {
exception = e;
print(e, e.stack);
}
}
let Debug = debug.Debug;
Debug.setListener(listener);
let gen = serialize();
gen.next();
Debug.setListener(null);
assertNull(exception);
assertEquals(4, step_count);
assertTrue(scopes_checked);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment