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 --expose-debug-as debug --allow-natives-syntax 6 7 Debug = debug.Debug; 8 9 var base_id = -1; 10 var exception = null; 11 var expected = [ 12 "enqueue #1", 13 "willHandle #1", 14 "then #1", 15 "enqueue #2", 16 "enqueue #3", 17 "didHandle #1", 18 "willHandle #2", 19 "then #2", 20 "didHandle #2", 21 "willHandle #3", 22 "enqueue #4", 23 "didHandle #3", 24 "willHandle #4", 25 "didHandle #4", 26 ]; 27 28 function assertLog(msg) { 29 print(msg); 30 assertTrue(expected.length > 0); 31 assertEquals(expected.shift(), msg); 32 if (!expected.length) { 33 Debug.setListener(null); 34 } 35 } 36 37 function listener(event, exec_state, event_data, data) { 38 if (event != Debug.DebugEvent.AsyncTaskEvent) return; 39 try { 40 if (base_id < 0) 41 base_id = event_data.id(); 42 var id = event_data.id() - base_id + 1; 43 assertTrue("Promise.resolve" == event_data.name() || 44 "PromiseResolveThenableJob" == event_data.name()); 45 assertLog(event_data.type() + " #" + id); 46 } catch (e) { 47 print(e + e.stack) 48 exception = e; 49 } 50 } 51 52 Debug.setListener(listener); 53 54 var resolver; 55 var p = new Promise(function(resolve, reject) { 56 resolver = resolve; 57 }); 58 59 async function main() { 60 await p; 61 assertLog("then #1"); 62 await undefined; 63 assertLog("then #2"); 64 } 65 main(); 66 resolver(); 67 68 %RunMicrotasks(); 69 70 assertNull(exception); 71