Skip to content

Commit dd8982d

Browse files
committed
deps: cherry-pick 09de996 from V8 upstream
Original commit message: [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. [email protected] BUG=v8:6085 Review-Url: https://codereview.chromium.org/2744213003 Cr-Commit-Position: refs/heads/master@{#43744} Committed: https://chromium.googlesource.com/v8/v8/+/09de9969ccb9bc3bbd667788afad665b309d02f5 Fixes: #11746 PR-URL: #11905 Fixes: #11746 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]>
1 parent 5bda5fa commit dd8982d

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

deps/v8/include/v8-version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 5
1212
#define V8_MINOR_VERSION 6
1313
#define V8_BUILD_NUMBER 326
14-
#define V8_PATCH_LEVEL 56
14+
#define V8_PATCH_LEVEL 57
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/parsing/parser-base.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5008,7 +5008,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseSwitchStatement(
50085008

50095009
{
50105010
BlockState cases_block_state(zone(), &scope_state_);
5011-
cases_block_state.set_start_position(scanner()->location().beg_pos);
5011+
cases_block_state.set_start_position(switch_pos);
50125012
cases_block_state.SetNonlinear();
50135013
typename Types::Target target(this, switch_statement);
50145014

deps/v8/src/parsing/parser.cc

+4
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,10 @@ Statement* Parser::RewriteSwitchStatement(Expression* tag,
17291729
Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
17301730
cases_block->statements()->Add(switch_statement, zone());
17311731
cases_block->set_scope(scope);
1732+
DCHECK_IMPLIES(scope != nullptr,
1733+
switch_statement->position() >= scope->start_position());
1734+
DCHECK_IMPLIES(scope != nullptr,
1735+
switch_statement->position() < scope->end_position());
17321736
switch_block->statements()->Add(cases_block, zone());
17331737
return switch_block;
17341738
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2017 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
function* serialize() {
6+
debugger;
7+
switch (0) {
8+
case 0:
9+
let x = 1;
10+
return x; // Check scopes
11+
}
12+
}
13+
14+
let exception = null;
15+
let step_count = 0;
16+
let scopes_checked = false;
17+
18+
function listener(event, exec_state, event_data, data) {
19+
if (event != Debug.DebugEvent.Break) return;
20+
try {
21+
if (exec_state.frame().sourceLineText().includes("Check scopes")) {
22+
let expected = [ debug.ScopeType.Block,
23+
debug.ScopeType.Local,
24+
debug.ScopeType.Script,
25+
debug.ScopeType.Global ];
26+
for (let i = 0; i < exec_state.frame().scopeCount(); i++) {
27+
assertEquals(expected[i], exec_state.frame().scope(i).scopeType());
28+
}
29+
scopes_checked = true;
30+
}
31+
if (step_count++ < 3) exec_state.prepareStep(Debug.StepAction.StepNext);
32+
} catch (e) {
33+
exception = e;
34+
print(e, e.stack);
35+
}
36+
}
37+
38+
39+
40+
let Debug = debug.Debug;
41+
Debug.setListener(listener);
42+
43+
let gen = serialize();
44+
gen.next();
45+
46+
Debug.setListener(null);
47+
assertNull(exception);
48+
assertEquals(4, step_count);
49+
assertTrue(scopes_checked);

0 commit comments

Comments
 (0)