OLD | NEW |
---|---|
(Empty) | |
1 <html> | |
2 <head> | |
3 <script src="../../http/tests/inspector/inspector-test.js"></script> | |
4 <script src="../../http/tests/inspector/debugger-test.js"></script> | |
5 <script> | |
6 | |
7 function timeoutPromise(value, ms) | |
8 { | |
9 return new Promise(function promiseCallback(resolve, reject) { | |
10 function resolvePromise() | |
11 { | |
12 resolve(value); | |
13 } | |
14 function rejectPromise() | |
15 { | |
16 reject(value); | |
17 } | |
18 if (value instanceof Error) | |
19 setTimeout(rejectPromise, ms || 0); | |
20 else | |
21 setTimeout(resolvePromise, ms || 0); | |
22 }); | |
23 } | |
24 | |
25 function settledPromise(value) | |
yhirano
2014/01/15 13:28:55
Let's use Promise.resolve and Promise.reject.
aandrey
2014/01/15 14:49:53
Added a separate test. The idea was to call those
| |
26 { | |
27 function resolveCallback(resolve, reject) | |
28 { | |
29 resolve(value); | |
30 } | |
31 function rejectCallback(resolve, reject) | |
32 { | |
33 reject(value); | |
34 } | |
35 if (value instanceof Error) | |
36 return new Promise(rejectCallback); | |
37 else | |
38 return new Promise(resolveCallback); | |
39 } | |
40 | |
41 function testFunction() | |
42 { | |
43 setTimeout(testFunctionTimeout, 0); | |
44 } | |
45 | |
46 function testFunctionTimeout() | |
47 { | |
48 var functions = [doTestPromiseConstructor, doTestSettledPromises, doTestChai nedPromises, doTestPromiseAll, doTestThrowFromChain]; | |
49 for (var i = 0; i < functions.length; ++i) | |
50 functions[i](); | |
51 } | |
52 | |
53 function thenCallback(value) | |
54 { | |
55 debugger; | |
56 } | |
57 | |
58 function errorCallback(error) | |
59 { | |
60 debugger; | |
61 } | |
62 | |
63 function doTestPromiseConstructor() | |
64 { | |
65 new Promise(function promiseCallback(resolve, reject) { | |
66 resolve(1); | |
67 debugger; | |
68 }); | |
69 } | |
70 | |
71 function doTestSettledPromises() | |
72 { | |
73 settledPromise("resolved").then(thenCallback, errorCallback); | |
74 settledPromise(Error("rejected")).then(thenCallback, errorCallback); | |
75 } | |
76 | |
77 function doTestChainedPromises() | |
78 { | |
79 timeoutPromise(1).then(function chained1() { | |
80 debugger; | |
81 return timeoutPromise(2); | |
82 }).then(function chained2() { | |
83 debugger; | |
84 return 3; | |
85 }).then(function chained3() { | |
86 debugger; | |
87 return settledPromise(4); | |
88 }).then(function chained4() { | |
89 debugger; | |
90 return timeoutPromise(5); | |
91 }).then(thenCallback, errorCallback); | |
92 } | |
93 | |
94 function doTestPromiseAll() | |
95 { | |
96 Promise.all([11, 22, 33, 44, 55].map(timeoutPromise)) | |
97 .then(thenCallback, errorCallback); | |
98 } | |
99 | |
100 function doTestThrowFromChain() | |
101 { | |
102 timeoutPromise(1).then(function chained1() { | |
103 return timeoutPromise(2); | |
104 }).then(function chained2() { | |
105 return settledPromise(3); | |
106 }).then(function chained3() { | |
107 throw Error("thrown from chained3"); | |
108 }).then(function chained4() { | |
109 return timeoutPromise(5); | |
110 }).catch(function catchCallback() { | |
111 debugger; | |
112 }); | |
113 | |
114 timeoutPromise(1).then(function chained1() { | |
115 return timeoutPromise(2); | |
116 }).then(function chained2() { | |
117 return timeoutPromise(3); | |
118 }).then(function chained3() { | |
119 return timeoutPromise(Error(4)); | |
120 }).then(function chained4() { | |
121 return timeoutPromise(5); | |
122 }).catch(function catchCallback() { | |
123 debugger; | |
124 }); | |
125 } | |
126 | |
127 var test = function() | |
128 { | |
129 var totalDebuggerStatements = 11; | |
130 var maxAsyncCallStackDepth = 4; | |
131 InspectorTest.runAsyncCallStacksTest(totalDebuggerStatements, maxAsyncCallSt ackDepth); | |
132 } | |
133 | |
134 </script> | |
135 </head> | |
136 | |
137 <body onload="runTest()"> | |
138 <p> | |
139 Tests asynchronous call stacks for Promises. | |
140 </p> | |
141 | |
142 </body> | |
143 </html> | |
OLD | NEW |