v8/test/inspector/debugger/suspended-generator-scopes.js
jgruber f0d3cf5bae [inspector] Expose scopes for suspended generator objects
This exposes scopes for suspended generator objects by adding a
[[Scopes]] internal property to generator objects, similar to how
scopes for functions currently not on the stack are handled.

BUG=chromium:667286

Review-Url: https://codereview.chromium.org/2516973003
Cr-Commit-Position: refs/heads/master@{#41244}
2016-11-24 07:32:40 +00:00

79 lines
2.2 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.
InspectorTest.addScript(
`function *gen(a) {
var b = 42;
yield a;
return b;
}
function testSuspendedGenerator()
{
var g = gen(420);
g.next();
debugger;
}`);
Protocol.Debugger.enable().then(testSuite);
function dumpInnermostScope(msg) {
var scopes = msg.result.result;
var inner_scope = scopes[0].value;
return Protocol.Runtime.getProperties({ objectId : inner_scope.objectId })
.then(InspectorTest.logMessage);
}
function dumpGeneratorScopes(msg)
{
var props = msg.result.internalProperties;
var promises = props
.filter(prop => prop.name == "[[Scopes]]")
.map(prop => prop.value.objectId)
.map(scopesId => Protocol.Runtime.getProperties({ objectId : scopesId })
.then(dumpInnermostScope));
return Promise.all(promises);
}
function fetchGeneratorProperties(objectId) {
return Protocol.Runtime.getProperties({ objectId : objectId });
}
function extractGeneratorObjectFromScope(scopeId) {
return Protocol.Runtime.getProperties({ objectId : scopeId })
.then(msg => {
var generatorObjectId = msg.result.result[0].value.objectId;
return fetchGeneratorProperties(generatorObjectId);
});
}
function dumpGeneratorScopesOnPause(msg) {
var scopeChain = msg.params.callFrames[0].scopeChain;
var promises = scopeChain
.filter(scope => scope.type === "local")
.map(scope => scope.object.objectId)
.map(scopeId => extractGeneratorObjectFromScope(scopeId)
.then(dumpGeneratorScopes));
return Promise.all(promises).then(Protocol.Debugger.resume);
}
function testSuite() {
InspectorTest.runTestSuite([
function testScopesPaused(next) {
Protocol.Debugger.oncePaused()
.then(dumpGeneratorScopesOnPause)
.then(next);
Protocol.Runtime.evaluate({ expression : "testSuspendedGenerator()" });
},
function testScopesNonPaused(next) {
Protocol.Runtime.evaluate({ expression : "gen(430)"})
.then(msg => fetchGeneratorProperties(msg.result.result.objectId))
.then(dumpGeneratorScopes)
.then(next);
},
]);
}