| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 // Flags: --harmony-async-await | |
| 6 | |
| 7 // The test observes the callbacks that async/await makes to the inspector | |
| 8 // to make accurate stack traces. The pattern is based on saving a stack once | |
| 9 // with enqueueRecurring and restoring it multiple times. | |
| 10 | |
| 11 // Additionally, the limited number of events is an indirect indication that | |
| 12 // we are not doing extra Promise processing that could be associated with memor
y | |
| 13 // leaks (v8:5380). In particular, no stacks are saved and restored for extra | |
| 14 // Promise handling on throwaway Promises. | |
| 15 | |
| 16 // TODO(littledan): Write a test that demonstrates that the memory leak in | |
| 17 // the exception case is fixed. | |
| 18 | |
| 19 Debug = debug.Debug; | |
| 20 | |
| 21 var base_id = -1; | |
| 22 var exception = null; | |
| 23 var expected = [ | |
| 24 'enqueueRecurring #1', | |
| 25 'willHandle #1', | |
| 26 'then #1', | |
| 27 'didHandle #1', | |
| 28 'willHandle #1', | |
| 29 'then #2', | |
| 30 'cancel #1', | |
| 31 'didHandle #1', | |
| 32 ]; | |
| 33 | |
| 34 function assertLog(msg) { | |
| 35 print(msg); | |
| 36 assertTrue(expected.length > 0); | |
| 37 assertEquals(expected.shift(), msg); | |
| 38 if (!expected.length) { | |
| 39 Debug.setListener(null); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 function listener(event, exec_state, event_data, data) { | |
| 44 if (event != Debug.DebugEvent.AsyncTaskEvent) return; | |
| 45 try { | |
| 46 if ("Promise.resolve" == event_data.name()) return; | |
| 47 if (base_id < 0) | |
| 48 base_id = event_data.id(); | |
| 49 var id = event_data.id() - base_id + 1; | |
| 50 assertTrue("async function" == event_data.name()); | |
| 51 assertLog(event_data.type() + " #" + id); | |
| 52 } catch (e) { | |
| 53 print(e + e.stack) | |
| 54 exception = e; | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 Debug.setListener(listener); | |
| 59 | |
| 60 var resolver; | |
| 61 var p = new Promise(function(resolve, reject) { | |
| 62 resolver = resolve; | |
| 63 }); | |
| 64 | |
| 65 async function main() { | |
| 66 await p; | |
| 67 assertLog("then #1"); | |
| 68 await undefined; | |
| 69 assertLog("then #2"); | |
| 70 } | |
| 71 main(); | |
| 72 resolver(); | |
| 73 | |
| 74 %RunMicrotasks(); | |
| 75 | |
| 76 assertNull(exception); | |
| 77 | |
| 78 Debug.clearBreakOnUncaughtException(); | |
| 79 Debug.setListener(null); | |
| 80 | |
| 81 var resolve; | |
| 82 var turnOnListenerPromise = new Promise(r => resolve = r); | |
| 83 async function confused() { | |
| 84 await turnOnListenerPromise; | |
| 85 throw foo | |
| 86 } | |
| 87 | |
| 88 confused(); | |
| 89 | |
| 90 Promise.resolve().then(() => { | |
| 91 Debug.setListener(listener); | |
| 92 Debug.setBreakOnUncaughtException(); | |
| 93 resolve(); | |
| 94 }); | |
| 95 | |
| 96 %RunMicrotasks(); | |
| 97 assertNull(exception); | |
| OLD | NEW |