mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 11:36:57 +00:00

PR-URL: https://github.com/nodejs/node/pull/47251 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
70 lines
2.4 KiB
JavaScript
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);
|
|
}
|
|
]);
|