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