|
4 | 4 |
|
5 | 5 | let {session, contextGroup, Protocol} = InspectorTest.start('Tests that suspended generators produce scopes'); |
6 | 6 |
|
7 | | -contextGroup.addScript( |
8 | | -`function *gen(a) { |
| 7 | +contextGroup.addScript(` |
| 8 | +function *gen(a) { |
9 | 9 | var b = 42; |
10 | 10 | yield a; |
11 | 11 | return b; |
12 | 12 | } |
13 | | -function testSuspendedGenerator() |
14 | | -{ |
| 13 | +
|
| 14 | +function testSuspendedGenerator() { |
15 | 15 | var g = gen(420); |
16 | 16 | g.next(); |
17 | | -
|
18 | 17 | debugger; |
19 | 18 | return g; |
20 | 19 | }`); |
21 | 20 |
|
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 | + }, |
45 | 49 |
|
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 | +]); |
0 commit comments