v8/test/inspector/debugger/suspended-generator-scopes.js
Alexey Kozyatinskiy 68af366f91 [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}
2017-09-12 21:17:35 +00:00

70 lines
2.4 KiB
JavaScript

// Copyright 2016 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.
let {session, contextGroup, Protocol} = InspectorTest.start('Tests that suspended generators produce scopes');
contextGroup.addScript(`
function *gen(a) {
var b = 42;
yield a;
return b;
}
function testSuspendedGenerator() {
var g = gen(420);
g.next();
debugger;
return g;
}`);
InspectorTest.runAsyncTestSuite([
async function testScopesPaused() {
Protocol.Debugger.enable();
Protocol.Runtime.evaluate({expression: 'testSuspendedGenerator()'});
let {params:{callFrames:[callFrame]}} = await Protocol.Debugger.oncePaused();
// Current local scope.
let localScope = callFrame.scopeChain.find(scope => scope.type === 'local');
let variables = (await Protocol.Runtime.getProperties({
objectId: localScope.object.objectId
})).result.result;
let genObjectId =
variables.find(variable => variable.name === 'g').value.objectId;
let {result:{internalProperties}} = await Protocol.Runtime.getProperties({
objectId: genObjectId
});
// Generator [[Scopes]].
let scopes = internalProperties.find(prop => prop.name === '[[Scopes]]');
let {result:{result}} = await Protocol.Runtime.getProperties({
objectId: scopes.value.objectId
});
// Locals from generator.
let scope = result.find(scope => scope.value.description === 'Local (gen)');
({result:{result}} = await Protocol.Runtime.getProperties({
objectId: scope.value.objectId
}));
InspectorTest.logMessage(result);
await Protocol.Debugger.disable();
},
async function testScopesNonPaused() {
let {result:{result:{objectId}}} = await Protocol.Runtime.evaluate({
expression: 'gen(430)'
});
let {result:{internalProperties}} = await Protocol.Runtime.getProperties({
objectId
});
// Generator [[Scopes]].
let scopes = internalProperties.find(prop => prop.name === '[[Scopes]]');
let {result:{result}} = await Protocol.Runtime.getProperties({
objectId: scopes.value.objectId
});
// Locals from generator.
let scope = result.find(scope => scope.value.description === 'Local (gen)');
({result:{result}} = await Protocol.Runtime.getProperties({
objectId: scope.value.objectId
}));
InspectorTest.logMessage(result);
}
]);