OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 print('Checks stepIntoAsync for Promise.then'); |
| 6 |
| 7 InspectorTest.addScript(` |
| 8 function foo() { |
| 9 } |
| 10 |
| 11 function boo() { |
| 12 } |
| 13 |
| 14 function basic(next) { |
| 15 var p = new Promise(r => resolve = r); |
| 16 debugger; |
| 17 p.then(foo).then(next); |
| 18 resolve(); |
| 19 foo(); |
| 20 } |
| 21 |
| 22 function promiseResolve(next) { |
| 23 debugger; |
| 24 Promise.resolve().then(foo).then(next); |
| 25 } |
| 26 |
| 27 function promiseReject(next) { |
| 28 debugger; |
| 29 Promise.reject().catch(foo).then(next); |
| 30 } |
| 31 |
| 32 function promiseAll(next) { |
| 33 debugger; |
| 34 Promise.all([ Promise.resolve() ]).then(foo).then(next); |
| 35 } |
| 36 |
| 37 function promiseRace(next) { |
| 38 debugger; |
| 39 Promise.race([ Promise.resolve() ]).then(foo).then(next); |
| 40 } |
| 41 |
| 42 function twoChainedCallbacks(next) { |
| 43 debugger; |
| 44 Promise.resolve().then(boo).then(foo).then(next); |
| 45 } |
| 46 |
| 47 function newPromise(next) { |
| 48 var resolve; |
| 49 debugger; |
| 50 new Promise(r => resolve = r).then(boo).then(next); |
| 51 resolve(); |
| 52 } |
| 53 |
| 54 function returnedPromise(next) { |
| 55 function promise() { |
| 56 return Promise.resolve(); |
| 57 } |
| 58 debugger; |
| 59 promise().then(boo).then(next); |
| 60 } |
| 61 |
| 62 function asyncAwait(next) { |
| 63 async function foo2() { |
| 64 await Promise.resolve(); |
| 65 } |
| 66 |
| 67 async function foo1() { |
| 68 await foo2(); |
| 69 next(); |
| 70 } |
| 71 debugger; |
| 72 foo1(); |
| 73 } |
| 74 |
| 75 function runTest(test) { |
| 76 return new Promise(function runTest(resolve) { test(resolve); }); |
| 77 } |
| 78 //# sourceURL=test.js`, 7, 26); |
| 79 |
| 80 InspectorTest.setupScriptMap(); |
| 81 var actions = []; |
| 82 Protocol.Debugger.onPaused(message => { |
| 83 var frames = message.params.callFrames.filter(frame => frame.functionName !==
'runTest'); |
| 84 InspectorTest.logCallFrames(frames); |
| 85 delete message.params.callFrames; |
| 86 if (message.params.data) InspectorTest.logMessage(message); |
| 87 InspectorTest.log(''); |
| 88 var action = actions.shift() || 'resume'; |
| 89 InspectorTest.log('Executing: ' + action); |
| 90 Protocol.Debugger[action]().then(message => { |
| 91 if (!message.error) return; |
| 92 InspectorTest.logMessage(message); |
| 93 Protocol.Debugger.resume(); |
| 94 }); |
| 95 }); |
| 96 |
| 97 Protocol.Debugger.enable(); |
| 98 InspectorTest.runTestSuite([ |
| 99 function testBasic(next) { |
| 100 actions = [ 'stepInto', 'stepInto', 'stepIntoAsync' ]; |
| 101 Protocol.Runtime.evaluate({ expression: 'runTest(basic)', awaitPromise: true
}) |
| 102 .then(next); |
| 103 }, |
| 104 |
| 105 function testPromiseResolve(next) { |
| 106 actions = [ 'stepInto', 'stepInto', 'stepIntoAsync' ]; |
| 107 Protocol.Runtime.evaluate({ expression: 'runTest(promiseResolve)', awaitProm
ise: true }) |
| 108 .then(next); |
| 109 }, |
| 110 |
| 111 function testPromiseReject(next) { |
| 112 actions = [ 'stepInto', 'stepInto', 'stepIntoAsync' ]; |
| 113 Protocol.Runtime.evaluate({ expression: 'runTest(promiseReject)', awaitPromi
se: true }) |
| 114 .then(next); |
| 115 }, |
| 116 |
| 117 function testPromiseAll(next) { |
| 118 actions = [ 'stepInto', 'stepInto', 'stepIntoAsync' ]; |
| 119 Protocol.Runtime.evaluate({ expression: 'runTest(promiseAll)', awaitPromise:
true }) |
| 120 .then(next); |
| 121 }, |
| 122 |
| 123 function testPromiseRace(next) { |
| 124 actions = [ 'stepInto', 'stepInto', 'stepIntoAsync' ]; |
| 125 Protocol.Runtime.evaluate({ expression: 'runTest(promiseRace)', awaitPromise
: true }) |
| 126 .then(next); |
| 127 }, |
| 128 |
| 129 function testTwoChainedCallbacks(next) { |
| 130 actions = [ 'stepInto', 'stepInto', 'stepInto', 'stepIntoAsync' ]; |
| 131 Protocol.Runtime.evaluate({ expression: 'runTest(twoChainedCallbacks)', awai
tPromise: true }) |
| 132 .then(next); |
| 133 }, |
| 134 |
| 135 function testNewPromise(next) { |
| 136 actions = [ 'stepInto', 'stepInto', 'stepOut', 'stepInto', 'stepIntoAsync' ]
; |
| 137 Protocol.Runtime.evaluate({ expression: 'runTest(newPromise)', awaitPromise:
true }) |
| 138 .then(next); |
| 139 }, |
| 140 |
| 141 function testReturnedPromise(next) { |
| 142 actions = [ 'stepInto', 'stepInto', 'stepOut', 'stepInto', 'stepIntoAsync' ]
; |
| 143 Protocol.Runtime.evaluate({ expression: 'runTest(returnedPromise)', awaitPro
mise: true }) |
| 144 .then(next); |
| 145 }, |
| 146 |
| 147 function testAsyncAwait(next) { |
| 148 actions = [ 'stepInto', 'stepInto', 'stepInto', 'stepInto', 'stepInto', 'ste
pInto', 'stepInto' ]; |
| 149 Protocol.Runtime.evaluate({ expression: 'runTest(asyncAwait)', awaitPromise:
true }) |
| 150 .then(next); |
| 151 }, |
| 152 |
| 153 function testResumeWorkAfterBreak(next) { |
| 154 actions = [ 'stepInto', 'stepInto' ]; |
| 155 Protocol.Runtime.evaluate({ expression: 'runTest(basic)', awaitPromise: true
}) |
| 156 .then(next); |
| 157 }, |
| 158 |
| 159 function testStepIntoAsyncWithoutScheduled(next) { |
| 160 actions = [ 'stepIntoAsync' ]; |
| 161 Protocol.Runtime.evaluate({ expression: 'runTest(basic)', awaitPromise: true
}) |
| 162 .then(next); |
| 163 } |
| 164 ]); |
OLD | NEW |