OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 print('Checks that async stacks works good with different limits'); | |
6 | |
7 InspectorTest.addScript(` | |
8 var resolveTest; | |
9 | |
10 function foo1() { | |
11 debugger; | |
12 } | |
13 | |
14 function foo2() { | |
15 debugger; | |
16 if (resolveTest) resolveTest(); | |
17 } | |
18 | |
19 function promise() { | |
20 var resolve1; | |
21 var p1 = new Promise(resolve => resolve1 = resolve); | |
22 var p2 = p1.then(foo1); | |
23 resolve1(); | |
24 return p2; | |
25 } | |
26 | |
27 function twoPromises() { | |
28 var resolve1; | |
29 var resolve2; | |
30 var p1 = new Promise(resolve => resolve1 = resolve); | |
31 var p2 = new Promise(resolve => resolve2 = resolve); | |
32 var p3 = p1.then(foo1); | |
33 var p4 = p2.then(foo2); | |
34 resolve1(); | |
35 resolve2(); | |
36 return Promise.all([p3, p4]); | |
37 } | |
38 | |
39 function twoSetTimeout() { | |
40 setTimeout(foo1, 0); | |
41 setTimeout(foo2, 0); | |
42 return new Promise(resolve => resolveTest = resolve); | |
43 } | |
44 | |
45 function threeSetTimeout() { | |
46 setTimeout(foo1, 0); | |
47 setTimeout(foo2, 0); | |
48 return new Promise(resolve => resolveTest = resolve); | |
49 } | |
50 | |
51 //# sourceURL=test.js`, 7, 26); | |
52 | |
53 InspectorTest.setupScriptMap(); | |
54 Protocol.Debugger.onPaused(message => { | |
55 InspectorTest.logCallFrames(message.params.callFrames); | |
56 var asyncStackTrace = message.params.asyncStackTrace; | |
57 while (asyncStackTrace) { | |
58 InspectorTest.log(`-- ${asyncStackTrace.description} --`); | |
59 InspectorTest.logCallFrames(asyncStackTrace.callFrames); | |
60 asyncStackTrace = asyncStackTrace.parent; | |
61 } | |
62 InspectorTest.log(''); | |
63 Protocol.Debugger.resume(); | |
64 }); | |
65 | |
66 Protocol.Debugger.enable(); | |
67 Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 }); | |
68 InspectorTest.runTestSuite([ | |
69 function testZeroLimit(next) { | |
70 Protocol.Runtime.evaluate({ | |
71 expression: 'setMaxAsyncTaskStacks(0)//# sourceURL=expr.js'}) | |
72 .then(() => Protocol.Runtime.evaluate({ | |
73 expression: 'promise()//# sourceURL=expr.js', awaitPromise: true | |
74 })) | |
75 .then(() => cancelAllAsyncTasks()) | |
76 .then(next); | |
77 }, | |
78 | |
79 function testOneLimit(next) { | |
80 Protocol.Runtime.evaluate({ | |
81 expression: 'setMaxAsyncTaskStacks(1)//# sourceURL=expr.js'}) | |
82 .then(() => Protocol.Runtime.evaluate({ | |
83 expression: 'promise()//# sourceURL=expr.js', awaitPromise: true | |
84 })) | |
85 .then(() => cancelAllAsyncTasks()) | |
86 .then(next); | |
87 }, | |
88 | |
89 function testOneLimitTwoPromises(next) { | |
90 // Should be no async stacks because when first microtask is finished | |
91 // it will resolve and schedule p3 - will remove async stack for scheduled | |
92 // p2. | |
93 Protocol.Runtime.evaluate({ | |
94 expression: 'setMaxAsyncTaskStacks(1)//# sourceURL=expr.js'}) | |
95 .then(() => Protocol.Runtime.evaluate({ | |
96 expression: 'twoPromises()//# sourceURL=expr.js', awaitPromise: true | |
97 })) | |
98 .then(() => cancelAllAsyncTasks()) | |
99 .then(next); | |
100 }, | |
101 | |
102 function testTwoLimitTwoPromises(next) { | |
103 Protocol.Runtime.evaluate({ | |
104 expression: 'setMaxAsyncTaskStacks(2)//# sourceURL=expr.js'}) | |
105 .then(() => Protocol.Runtime.evaluate({ | |
106 expression: 'twoPromises()//# sourceURL=expr.js', awaitPromise: true | |
107 })) | |
108 .then(() => cancelAllAsyncTasks()) | |
109 .then(next); | |
110 }, | |
111 | |
112 function testOneLimitTwoSetTimeouts(next) { | |
113 Protocol.Runtime.evaluate({ | |
114 expression: 'setMaxAsyncTaskStacks(1)//# sourceURL=expr.js'}) | |
115 .then(() => Protocol.Runtime.evaluate({ | |
116 expression: 'twoSetTimeout()//# sourceURL=expr.js', awaitPromise: true | |
117 })) | |
118 .then(() => cancelAllAsyncTasks()) | |
119 .then(next); | |
120 }, | |
121 | |
122 function testTwoLimitTwoSetTimeouts(next) { | |
dgozman
2016/12/18 03:31:01
Let's add testTenLimitTwentySetTimeouts.
kozy
2016/12/18 06:27:38
Done.
| |
123 Protocol.Runtime.evaluate({ | |
124 expression: 'setMaxAsyncTaskStacks(2)//# sourceURL=expr.js'}) | |
125 .then(() => Protocol.Runtime.evaluate({ | |
126 expression: 'twoSetTimeout()//# sourceURL=expr.js', awaitPromise: true | |
127 })) | |
128 .then(() => cancelAllAsyncTasks()) | |
129 .then(next); | |
130 } | |
131 ]); | |
132 | |
133 function cancelAllAsyncTasks() { | |
134 return Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }) | |
135 .then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 })); | |
136 } | |
OLD | NEW |