Chromium Code Reviews| Index: LayoutTests/inspector/debugger/async-callstack-promises.html |
| diff --git a/LayoutTests/inspector/debugger/async-callstack-promises.html b/LayoutTests/inspector/debugger/async-callstack-promises.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..577774ae28e95c8e2f9dbb6c5fd1a3f23e246e8d |
| --- /dev/null |
| +++ b/LayoutTests/inspector/debugger/async-callstack-promises.html |
| @@ -0,0 +1,156 @@ |
| +<html> |
| +<head> |
| +<script src="../../http/tests/inspector/inspector-test.js"></script> |
| +<script src="../../http/tests/inspector/debugger-test.js"></script> |
| +<script> |
| + |
| +function timeoutPromise(value, ms) |
| +{ |
| + return new Promise(function promiseCallback(resolve, reject) { |
| + function resolvePromise() |
| + { |
| + resolve(value); |
| + } |
| + function rejectPromise() |
| + { |
| + reject(value); |
| + } |
| + if (value instanceof Error) |
| + setTimeout(rejectPromise, ms || 0); |
| + else |
| + setTimeout(resolvePromise, ms || 0); |
| + }); |
| +} |
| + |
| +function settledPromise(value) |
| +{ |
| + function resolveCallback(resolve, reject) |
| + { |
| + resolve(value); |
| + } |
| + function rejectCallback(resolve, reject) |
| + { |
| + reject(value); |
| + } |
| + if (value instanceof Error) |
| + return new Promise(rejectCallback); |
| + else |
| + return new Promise(resolveCallback); |
| +} |
| + |
| +function testFunction() |
| +{ |
| + setTimeout(testFunctionTimeout, 0); |
| +} |
| + |
| +function testFunctionTimeout() |
| +{ |
| + var functions = [doTestPromiseConstructor, doTestSettledPromises, doTestChainedPromises, doTestPromiseAll, doTestThrowFromChain, doTestPromiseResolveAndReject]; |
|
yurys
2014/01/16 12:49:20
Will these functions be always executed in this or
aandrey
2014/01/16 14:15:29
You mean the "debugger" breaks?
Answer: NO.
We sor
|
| + for (var i = 0; i < functions.length; ++i) |
| + functions[i](); |
| +} |
| + |
| +function thenCallback(value) |
| +{ |
| + debugger; |
| +} |
| + |
| +function errorCallback(error) |
| +{ |
| + debugger; |
| +} |
| + |
| +function doTestPromiseConstructor() |
| +{ |
| + new Promise(function promiseCallback(resolve, reject) { |
| + resolve(1); |
| + debugger; |
| + }); |
| +} |
| + |
| +function doTestSettledPromises() |
| +{ |
| + settledPromise("resolved").then(thenCallback, errorCallback); |
| + settledPromise(Error("rejected")).then(thenCallback, errorCallback); |
| +} |
| + |
| +function doTestChainedPromises() |
| +{ |
| + timeoutPromise(1).then(function chained1() { |
| + debugger; |
| + return timeoutPromise(2); |
| + }).then(function chained2() { |
| + debugger; |
| + return 3; |
| + }).then(function chained3() { |
| + debugger; |
| + return settledPromise(4); |
| + }).then(function chained4() { |
| + debugger; |
| + return timeoutPromise(5); |
| + }).then(thenCallback, errorCallback); |
| + |
| + timeoutPromise(1) |
| + .then(JSON.stringify) |
| + .then(JSON.parse) |
| + .then(function afterJSONStringifyAndParse() { |
| + debugger; |
| + }); |
| +} |
| + |
| +function doTestPromiseAll() |
| +{ |
| + Promise.all([11, 22, 33, 44, 55].map(timeoutPromise)) |
| + .then(thenCallback, errorCallback); |
| +} |
| + |
| +function doTestThrowFromChain() |
| +{ |
| + timeoutPromise(1).then(function chained1() { |
| + return timeoutPromise(2); |
| + }).then(function chained2() { |
| + return settledPromise(3); |
| + }).then(function chained3() { |
| + throw Error("thrown from chained3"); |
| + }).then(function chained4() { |
| + return timeoutPromise(5); |
| + }).catch(function catchCallback() { |
| + debugger; |
| + }); |
| + |
| + timeoutPromise(1).then(function chained1() { |
| + return timeoutPromise(2); |
| + }).then(function chained2() { |
| + return timeoutPromise(3); |
| + }).then(function chained3() { |
| + return timeoutPromise(Error(4)); |
| + }).then(function chained4() { |
| + return timeoutPromise(5); |
| + }).catch(function catchCallback() { |
| + debugger; |
| + }); |
| +} |
| + |
| +function doTestPromiseResolveAndReject() |
| +{ |
| + Promise.resolve(1).then(thenCallback, errorCallback); |
| + Promise.reject(Error("2")).then(thenCallback, errorCallback); |
| +} |
| + |
| +var test = function() |
| +{ |
| + var totalDebuggerStatements = 14; |
| + var maxAsyncCallStackDepth = 4; |
| + InspectorTest.runAsyncCallStacksTest(totalDebuggerStatements, maxAsyncCallStackDepth); |
| +} |
| + |
| +</script> |
| +</head> |
| + |
| +<body onload="runTest()"> |
| +<p> |
| +Tests asynchronous call stacks for Promises. |
| +</p> |
| + |
| +</body> |
| +</html> |