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) |
| 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, doTestSettledPromisesResolved, do
TestSettledPromisesRejected, doTestChainedPromises, doTestChainedPromisesJSON, d
oTestPromiseAll, doTestThrowFromChain, doTestTimeoutChain, doTestPromiseResolve,
doTestPromiseReject]; |
| 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 async function doTestSettledPromisesResolved() |
| 72 { |
| 73 try { |
| 74 let value = await settledPromise("resolved"); |
| 75 thenCallback(value); |
| 76 } catch (e) { |
| 77 errorCallback(e); |
| 78 } |
| 79 } |
| 80 |
| 81 async function doTestSettledPromisesRejected() |
| 82 { |
| 83 try { |
| 84 let value = await settledPromise("rejected"); |
| 85 thenCallback(value); |
| 86 } catch (e) { |
| 87 errorCallback(e); |
| 88 } |
| 89 } |
| 90 |
| 91 async function doTestChainedPromises() |
| 92 { |
| 93 try { |
| 94 await timeoutPromise(1); |
| 95 debugger; |
| 96 await timeoutPromise(2); |
| 97 debugger; |
| 98 await 3; |
| 99 debugger; |
| 100 await settledPromise(4); |
| 101 debuger; |
| 102 thenCallback(await timeoutPromise(5)); |
| 103 } catch (e) |
| 104 errorCallback(e); |
| 105 } |
| 106 } |
| 107 |
| 108 async function doTestChainedPromisesJSON() |
| 109 { |
| 110 let one = await timeoutPromise(1); |
| 111 let stringify = await JSON.stringify(one); |
| 112 let parse = await JSON.parse(stringify); |
| 113 debugger; |
| 114 } |
| 115 |
| 116 async function doTestPromiseAll() |
| 117 { |
| 118 try { |
| 119 let all = await Promise.all([11, 22, 33, 44, 55].map(timeoutPromise)); |
| 120 thenCallback(all); |
| 121 } catch (e) { |
| 122 errorCallback(e); |
| 123 } |
| 124 } |
| 125 |
| 126 async function doTestThrowFromChain() |
| 127 { |
| 128 await timeoutPromise(1); |
| 129 await timeoutPromise(2); |
| 130 await settledPromise(3); |
| 131 throw Error("thrown from 4"); |
| 132 await timeoutPromise(5); |
| 133 debugger; |
| 134 } |
| 135 |
| 136 async function doTestTimeoutChain() { |
| 137 await timeoutPromise(1); |
| 138 await timeoutPromise(2); |
| 139 await timeoutPromise(3); |
| 140 await timeoutPromise(Error(4)); |
| 141 throw Error("thrown from chained3"); |
| 142 await timeoutPromise(5); |
| 143 debugger; |
| 144 } |
| 145 |
| 146 function doTestPromiseResolve() |
| 147 { |
| 148 try { |
| 149 let value = Promise.resolve(1); |
| 150 thenCallback(e); |
| 151 } catch (e) { |
| 152 errorCallback(e); |
| 153 } |
| 154 } |
| 155 |
| 156 function doTestPromiseReject() |
| 157 { |
| 158 try { |
| 159 let value = Promise.reject(Error("2")) |
| 160 thenCallback(e); |
| 161 } catch (e) { |
| 162 errorCallback(e); |
| 163 } |
| 164 } |
| 165 |
| 166 var test = function() |
| 167 { |
| 168 var totalDebuggerStatements = 14; |
| 169 var maxAsyncCallStackDepth = 4; |
| 170 InspectorTest.runAsyncCallStacksTest(totalDebuggerStatements, maxAsyncCallSt
ackDepth); |
| 171 } |
| 172 |
| 173 </script> |
| 174 </head> |
| 175 |
| 176 <body onload="runTest()"> |
| 177 <p> |
| 178 Tests asynchronous call stacks for Promises. |
| 179 </p> |
| 180 |
| 181 </body> |
| 182 </html> |
| 183 |
OLD | NEW |