3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/debugger-test.js"></script>
7 function timeoutPromise(value, ms)
9 return new Promise(function promiseCallback(resolve, reject) {
10 function resolvePromise()
14 function rejectPromise()
18 if (value instanceof Error)
19 setTimeout(rejectPromise, ms || 0);
21 setTimeout(resolvePromise, ms || 0);
25 function settledPromise(value)
27 function resolveCallback(resolve, reject)
31 function rejectCallback(resolve, reject)
35 if (value instanceof Error)
36 return new Promise(rejectCallback);
38 return new Promise(resolveCallback);
41 function testFunction()
43 setTimeout(testFunctionTimeout, 0);
46 function testFunctionTimeout()
48 var functions = [doTestPromiseConstructor, doTestSettledPromises, doTestChainedPromises, doTestPromiseAll, doTestThrowFromChain, doTestPromiseResolveAndReject];
49 for (var i = 0; i < functions.length; ++i)
53 function thenCallback(value)
58 function errorCallback(error)
63 function doTestPromiseConstructor()
65 new Promise(function promiseCallback(resolve, reject) {
71 function doTestSettledPromises()
73 settledPromise("resolved").then(thenCallback, errorCallback);
74 settledPromise(Error("rejected")).then(thenCallback, errorCallback);
77 function doTestChainedPromises()
79 timeoutPromise(1).then(function chained1() {
81 return timeoutPromise(2);
82 }).then(function chained2() {
85 }).then(function chained3() {
87 return settledPromise(4);
88 }).then(function chained4() {
90 return timeoutPromise(5);
91 }).then(thenCallback, errorCallback);
96 .then(function afterJSONStringifyAndParse() {
101 function doTestPromiseAll()
103 Promise.all([11, 22, 33, 44, 55].map(timeoutPromise))
104 .then(thenCallback, errorCallback);
107 function doTestThrowFromChain()
109 timeoutPromise(1).then(function chained1() {
110 return timeoutPromise(2);
111 }).then(function chained2() {
112 return settledPromise(3);
113 }).then(function chained3() {
114 throw Error("thrown from chained3");
115 }).then(function chained4() {
116 return timeoutPromise(5);
117 }).catch(function catchCallback() {
121 timeoutPromise(1).then(function chained1() {
122 return timeoutPromise(2);
123 }).then(function chained2() {
124 return timeoutPromise(3);
125 }).then(function chained3() {
126 return timeoutPromise(Error(4));
127 }).then(function chained4() {
128 return timeoutPromise(5);
129 }).catch(function catchCallback() {
134 function doTestPromiseResolveAndReject()
136 Promise.resolve(1).then(thenCallback, errorCallback);
137 Promise.reject(Error("2")).then(thenCallback, errorCallback);
140 var test = function()
142 var totalDebuggerStatements = 14;
143 var maxAsyncCallStackDepth = 4;
144 InspectorTest.runAsyncCallStacksTest(totalDebuggerStatements, maxAsyncCallStackDepth);
150 <body onload="runTest()">
152 Tests asynchronous call stacks for Promises.