Skip to content

Commit 68af366

Browse files
alexkozyCommit Bot
authored andcommitted
[inspector] report [[Scopes]] all the time
Before we used to require compiled debugger script to report Scopes. After migration inspection to brand-new native API we can report Scopes all the time and remove this hidden dependency. R=dgozman@chromium.org Bug: none Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I3530bc7ead691a51073e384aea4a4ef428dc94da Reviewed-on: https://chromium-review.googlesource.com/662097 Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Cr-Commit-Position: refs/heads/master@{#47982}
1 parent 90eb06b commit 68af366

6 files changed

Lines changed: 229 additions & 127 deletions

File tree

src/inspector/v8-debugger.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,6 @@ std::shared_ptr<AsyncStackTrace> V8Debugger::currentAsyncCreation() {
563563
v8::MaybeLocal<v8::Value> V8Debugger::getTargetScopes(
564564
v8::Local<v8::Context> context, v8::Local<v8::Value> value,
565565
ScopeTargetKind kind) {
566-
if (!enabled()) {
567-
UNREACHABLE();
568-
}
569566
v8::Local<v8::Value> scopesValue;
570567
std::unique_ptr<v8::debug::ScopeIterator> iterator;
571568
switch (kind) {
@@ -664,15 +661,13 @@ v8::MaybeLocal<v8::Array> V8Debugger::internalProperties(
664661
toV8StringInternalized(m_isolate, "[[GeneratorLocation]]"));
665662
createDataProperty(context, properties, properties->Length(), location);
666663
}
667-
if (!enabled()) return properties;
668664
v8::Local<v8::Value> scopes;
669665
if (generatorScopes(context, value).ToLocal(&scopes)) {
670666
createDataProperty(context, properties, properties->Length(),
671667
toV8StringInternalized(m_isolate, "[[Scopes]]"));
672668
createDataProperty(context, properties, properties->Length(), scopes);
673669
}
674670
}
675-
if (!enabled()) return properties;
676671
if (value->IsFunction()) {
677672
v8::Local<v8::Function> function = value.As<v8::Function>();
678673
v8::Local<v8::Value> boundFunction = function->GetBoundFunction();
Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,55 @@
11
Tests that suspended generators produce scopes
22

33
Running test: testScopesPaused
4-
{
5-
id : <messageId>
6-
result : {
7-
result : [
8-
[0] : {
9-
configurable : true
10-
enumerable : true
11-
isOwn : true
12-
name : b
13-
value : {
14-
description : 42
15-
type : number
16-
value : 42
17-
}
18-
writable : true
19-
}
20-
[1] : {
21-
configurable : true
22-
enumerable : true
23-
isOwn : true
24-
name : a
25-
value : {
26-
description : 420
27-
type : number
28-
value : 420
29-
}
30-
writable : true
31-
}
32-
]
4+
[
5+
[0] : {
6+
configurable : true
7+
enumerable : true
8+
isOwn : true
9+
name : b
10+
value : {
11+
description : 42
12+
type : number
13+
value : 42
14+
}
15+
writable : true
3316
}
34-
}
17+
[1] : {
18+
configurable : true
19+
enumerable : true
20+
isOwn : true
21+
name : a
22+
value : {
23+
description : 420
24+
type : number
25+
value : 420
26+
}
27+
writable : true
28+
}
29+
]
3530

3631
Running test: testScopesNonPaused
37-
{
38-
id : <messageId>
39-
result : {
40-
result : [
41-
[0] : {
42-
configurable : true
43-
enumerable : true
44-
isOwn : true
45-
name : b
46-
value : {
47-
type : undefined
48-
}
49-
writable : true
50-
}
51-
[1] : {
52-
configurable : true
53-
enumerable : true
54-
isOwn : true
55-
name : a
56-
value : {
57-
description : 430
58-
type : number
59-
value : 430
60-
}
61-
writable : true
62-
}
63-
]
32+
[
33+
[0] : {
34+
configurable : true
35+
enumerable : true
36+
isOwn : true
37+
name : b
38+
value : {
39+
type : undefined
40+
}
41+
writable : true
42+
}
43+
[1] : {
44+
configurable : true
45+
enumerable : true
46+
isOwn : true
47+
name : a
48+
value : {
49+
description : 430
50+
type : number
51+
value : 430
52+
}
53+
writable : true
6454
}
65-
}
55+
]

test/inspector/debugger/suspended-generator-scopes.js

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,66 @@
44

55
let {session, contextGroup, Protocol} = InspectorTest.start('Tests that suspended generators produce scopes');
66

7-
contextGroup.addScript(
8-
`function *gen(a) {
7+
contextGroup.addScript(`
8+
function *gen(a) {
99
var b = 42;
1010
yield a;
1111
return b;
1212
}
13-
function testSuspendedGenerator()
14-
{
13+
14+
function testSuspendedGenerator() {
1515
var g = gen(420);
1616
g.next();
17-
1817
debugger;
1918
return g;
2019
}`);
2120

22-
Protocol.Debugger.enable().then(testSuite);
23-
24-
function dumpInnermostScope(msg) {
25-
var scopes = msg.result.result;
26-
var inner_scope = scopes[0].value;
27-
return Protocol.Runtime.getProperties({ objectId : inner_scope.objectId })
28-
.then(InspectorTest.logMessage);
29-
}
30-
31-
function dumpGeneratorScopes(msg)
32-
{
33-
var props = msg.result.internalProperties;
34-
var promises = props
35-
.filter(prop => prop.name == "[[Scopes]]")
36-
.map(prop => prop.value.objectId)
37-
.map(scopesId => Protocol.Runtime.getProperties({ objectId : scopesId })
38-
.then(dumpInnermostScope));
39-
return Promise.all(promises);
40-
}
41-
42-
function fetchGeneratorProperties(objectId) {
43-
return Protocol.Runtime.getProperties({ objectId : objectId });
44-
}
21+
InspectorTest.runAsyncTestSuite([
22+
async function testScopesPaused() {
23+
Protocol.Debugger.enable();
24+
Protocol.Runtime.evaluate({expression: 'testSuspendedGenerator()'});
25+
let {params:{callFrames:[callFrame]}} = await Protocol.Debugger.oncePaused();
26+
// Current local scope.
27+
let localScope = callFrame.scopeChain.find(scope => scope.type === 'local');
28+
let variables = (await Protocol.Runtime.getProperties({
29+
objectId: localScope.object.objectId
30+
})).result.result;
31+
let genObjectId =
32+
variables.find(variable => variable.name === 'g').value.objectId;
33+
let {result:{internalProperties}} = await Protocol.Runtime.getProperties({
34+
objectId: genObjectId
35+
});
36+
// Generator [[Scopes]].
37+
let scopes = internalProperties.find(prop => prop.name === '[[Scopes]]');
38+
let {result:{result}} = await Protocol.Runtime.getProperties({
39+
objectId: scopes.value.objectId
40+
});
41+
// Locals from generator.
42+
let scope = result.find(scope => scope.value.description === 'Local (gen)');
43+
({result:{result}} = await Protocol.Runtime.getProperties({
44+
objectId: scope.value.objectId
45+
}));
46+
InspectorTest.logMessage(result);
47+
await Protocol.Debugger.disable();
48+
},
4549

46-
function extractGeneratorObjectFromScope(scopeId) {
47-
return Protocol.Runtime.getProperties({ objectId : scopeId })
48-
.then(msg => {
49-
var generatorObjectId = msg.result.result[0].value.objectId;
50-
return fetchGeneratorProperties(generatorObjectId);
51-
});
52-
}
53-
54-
function dumpGeneratorScopesOnPause(msg) {
55-
var scopeChain = msg.params.callFrames[0].scopeChain;
56-
var promises = scopeChain
57-
.filter(scope => scope.type === "local")
58-
.map(scope => scope.object.objectId)
59-
.map(scopeId => extractGeneratorObjectFromScope(scopeId)
60-
.then(dumpGeneratorScopes));
61-
return Promise.all(promises).then(Protocol.Debugger.resume);
62-
}
63-
64-
function testSuite() {
65-
InspectorTest.runTestSuite([
66-
67-
function testScopesPaused(next) {
68-
Protocol.Debugger.oncePaused()
69-
.then(dumpGeneratorScopesOnPause)
70-
.then(next);
71-
Protocol.Runtime.evaluate({ expression : "testSuspendedGenerator()" });
72-
},
73-
74-
function testScopesNonPaused(next) {
75-
Protocol.Runtime.evaluate({ expression : "gen(430)"})
76-
.then(msg => fetchGeneratorProperties(msg.result.result.objectId))
77-
.then(dumpGeneratorScopes)
78-
.then(next);
79-
},
80-
]);
81-
}
50+
async function testScopesNonPaused() {
51+
let {result:{result:{objectId}}} = await Protocol.Runtime.evaluate({
52+
expression: 'gen(430)'
53+
});
54+
let {result:{internalProperties}} = await Protocol.Runtime.getProperties({
55+
objectId
56+
});
57+
// Generator [[Scopes]].
58+
let scopes = internalProperties.find(prop => prop.name === '[[Scopes]]');
59+
let {result:{result}} = await Protocol.Runtime.getProperties({
60+
objectId: scopes.value.objectId
61+
});
62+
// Locals from generator.
63+
let scope = result.find(scope => scope.value.description === 'Local (gen)');
64+
({result:{result}} = await Protocol.Runtime.getProperties({
65+
objectId: scope.value.objectId
66+
}));
67+
InspectorTest.logMessage(result);
68+
}
69+
]);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Checks [[Scopes]] for functions
2+
Catch:
3+
{
4+
configurable : true
5+
enumerable : true
6+
isOwn : true
7+
name : a
8+
value : {
9+
description : 1
10+
type : number
11+
value : 1
12+
}
13+
writable : true
14+
}
15+
With block:
16+
{
17+
configurable : true
18+
enumerable : true
19+
isOwn : true
20+
name : b
21+
value : {
22+
description : 2
23+
type : number
24+
value : 2
25+
}
26+
writable : true
27+
}
28+
Closure (closure):
29+
{
30+
configurable : true
31+
enumerable : true
32+
isOwn : true
33+
name : c
34+
value : {
35+
description : 3
36+
type : number
37+
value : 3
38+
}
39+
writable : true
40+
}
41+
Global:
42+
{
43+
configurable : false
44+
enumerable : true
45+
isOwn : true
46+
name : e
47+
value : {
48+
description : 5
49+
type : number
50+
value : 5
51+
}
52+
writable : true
53+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
let {session, contextGroup, Protocol} = InspectorTest.start('Checks [[Scopes]] for functions');
6+
7+
contextGroup.addScript(`
8+
var f;
9+
try {
10+
throw 1;
11+
} catch (a) {
12+
with({b:2}) {
13+
function closure() {
14+
var c = 3;
15+
function foo() {
16+
var d = 4;
17+
return a + b + c + d;
18+
}
19+
return foo;
20+
}
21+
f = closure;
22+
}
23+
}
24+
var e = 5;
25+
//# sourceURL=test.js`);
26+
27+
(async function test() {
28+
let {result:{result:{objectId}}} = await Protocol.Runtime.evaluate({
29+
expression: 'f()'
30+
});
31+
let {result:{internalProperties}} = await Protocol.Runtime.getProperties({
32+
objectId
33+
});
34+
let scopes = internalProperties.find(prop => prop.name === '[[Scopes]]');
35+
let {result:{result}} = await Protocol.Runtime.getProperties({
36+
objectId: scopes.value.objectId
37+
});
38+
await Promise.all(result.map(async scope => {
39+
scope.variables = (await Protocol.Runtime.getProperties({
40+
objectId: scope.value.objectId
41+
})).result.result;
42+
}));
43+
let catchScope = result.find(scope => scope.value.description === 'Catch');
44+
InspectorTest.log('Catch:');
45+
InspectorTest.logMessage(catchScope.variables.find(variable => variable.name === 'a'));
46+
InspectorTest.log('With block:');
47+
let withScope = result.find(scope => scope.value.description === 'With Block');
48+
InspectorTest.logMessage(withScope.variables.find(variable => variable.name === 'b'));
49+
InspectorTest.log('Closure (closure):');
50+
let closureScope = result.find(scope => scope.value.description === 'Closure (closure)');
51+
InspectorTest.logMessage(closureScope.variables.find(variable => variable.name === 'c'));
52+
InspectorTest.log('Global:');
53+
let globalScope = result.find(scope => scope.value.description === 'Global');
54+
InspectorTest.logMessage(globalScope.variables.find(variable => variable.name === 'e'));
55+
InspectorTest.completeTest();
56+
})();

0 commit comments

Comments
 (0)