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 InspectorTest.log('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 twentySetTimeout() { | |
46 var resolve1; | |
47 var p1 = new Promise(resolve => resolve1 = resolve); | |
48 for (var i = 1; i <= 19; ++i) | |
49 setTimeout('(function foo' + i + '(){debugger;})()',0); | |
50 setTimeout(resolve1, 0); | |
51 return p1; | |
52 } | |
53 | |
54 //# sourceURL=test.js`, 7, 26); | |
55 | |
56 InspectorTest.setupScriptMap(); | |
57 Protocol.Debugger.onPaused(message => { | |
58 InspectorTest.logCallFrames(message.params.callFrames); | |
59 var asyncStackTrace = message.params.asyncStackTrace; | |
60 while (asyncStackTrace) { | |
61 InspectorTest.log(`-- ${asyncStackTrace.description} --`); | |
62 InspectorTest.logCallFrames(asyncStackTrace.callFrames); | |
63 asyncStackTrace = asyncStackTrace.parent; | |
64 } | |
65 InspectorTest.log(''); | |
66 Protocol.Debugger.resume(); | |
67 }); | |
68 | |
69 Protocol.Debugger.enable(); | |
70 Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 }); | |
71 InspectorTest.runTestSuite([ | |
72 function testZeroLimit(next) { | |
73 Protocol.Runtime.evaluate({ | |
74 expression: 'setMaxAsyncTaskStacks(0)//# sourceURL=expr.js'}) | |
75 .then(() => Protocol.Runtime.evaluate({ | |
76 expression: 'promise()//# sourceURL=expr.js', awaitPromise: true | |
77 })) | |
78 .then(() => cancelAllAsyncTasks()) | |
79 .then(next); | |
80 }, | |
81 | |
82 function testTwoLimit(next) { | |
83 // we need one stack for parent task and one for next task. | |
84 Protocol.Runtime | |
85 .evaluate({expression: 'setMaxAsyncTaskStacks(2)//# sourceURL=expr.js'}) | |
86 .then(() => Protocol.Runtime.evaluate({ | |
87 expression: 'promise()//# sourceURL=expr.js', | |
88 awaitPromise: true | |
89 })) | |
90 .then(() => cancelAllAsyncTasks()) | |
91 .then(next); | |
92 }, | |
93 | |
94 function testOneLimitTwoPromises(next) { | |
95 // Should be no async stacks because when first microtask is finished | |
96 // it will resolve and schedule p3 - will remove async stack for scheduled | |
97 // p2. | |
98 Protocol.Runtime.evaluate({ | |
99 expression: 'setMaxAsyncTaskStacks(1)//# sourceURL=expr.js'}) | |
100 .then(() => Protocol.Runtime.evaluate({ | |
101 expression: 'twoPromises()//# sourceURL=expr.js', awaitPromise: true | |
102 })) | |
103 .then(() => cancelAllAsyncTasks()) | |
104 .then(next); | |
105 }, | |
106 | |
107 function testFourLimitTwoPromises(next) { | |
108 Protocol.Runtime | |
109 .evaluate({expression: 'setMaxAsyncTaskStacks(4)//# sourceURL=expr.js'}) | |
110 .then(() => Protocol.Runtime.evaluate({ | |
111 expression: 'twoPromises()//# sourceURL=expr.js', | |
112 awaitPromise: true | |
113 })) | |
114 .then(() => cancelAllAsyncTasks()) | |
115 .then(next); | |
116 }, | |
117 | |
118 function testSixLimitTwoPromises(next) { | |
119 Protocol.Runtime | |
120 .evaluate({expression: 'setMaxAsyncTaskStacks(6)//# sourceURL=expr.js'}) | |
121 .then(() => Protocol.Runtime.evaluate({ | |
122 expression: 'twoPromises()//# sourceURL=expr.js', | |
123 awaitPromise: true | |
124 })) | |
125 .then(() => cancelAllAsyncTasks()) | |
126 .then(next); | |
127 }, | |
128 | |
129 function testTwoLimitTwoSetTimeouts(next) { | |
130 Protocol.Runtime.evaluate({ | |
131 expression: 'setMaxAsyncTaskStacks(2)//# sourceURL=expr.js'}) | |
132 .then(() => Protocol.Runtime.evaluate({ | |
133 expression: 'twoSetTimeout()//# sourceURL=expr.js', awaitPromise: true | |
134 })) | |
135 .then(() => cancelAllAsyncTasks()) | |
136 .then(next); | |
137 }, | |
138 | |
139 function testThreeLimitTwoSetTimeouts(next) { | |
140 Protocol.Runtime.evaluate({ | |
141 expression: 'setMaxAsyncTaskStacks(3)//# sourceURL=expr.js'}) | |
142 .then(() => Protocol.Runtime.evaluate({ | |
143 expression: 'twoSetTimeout()//# sourceURL=expr.js', awaitPromise: true | |
144 })) | |
145 .then(() => cancelAllAsyncTasks()) | |
146 .then(next); | |
147 }, | |
148 | |
149 function testTenLimitTwentySetTimeouts(next) { | |
150 Protocol.Runtime.evaluate({ | |
151 expression: 'setMaxAsyncTaskStacks(10)//# sourceURL=expr.js'}) | |
152 .then(() => Protocol.Runtime.evaluate({ | |
153 expression: 'twentySetTimeout()//# sourceURL=expr.js', | |
154 awaitPromise: true | |
155 })) | |
156 .then(() => cancelAllAsyncTasks()) | |
157 .then(next); | |
158 } | |
159 ]); | |
160 | |
161 function cancelAllAsyncTasks() { | |
162 return Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }) | |
163 .then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 })); | |
164 } | |
OLD | NEW |