OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-debug-as debug | 5 // Flags: --expose-debug-as debug |
6 | 6 |
7 Debug = debug.Debug; | 7 Debug = debug.Debug; |
8 | 8 |
9 var exception = null; | 9 var exception = null; |
10 var new_promise; | 10 var new_promise; |
11 | 11 |
12 function listener(event, exec_state, event_data, data) { | 12 function listener(event, exec_state, event_data, data) { |
13 if (event != Debug.DebugEvent.PromiseEvent) return; | 13 if (!(event_data instanceof debug.NewPromiseEvent)) return; |
14 try { | 14 try { |
15 assertTrue(event_data.resolver().isFunction()); | 15 assertTrue(event_data.resolver().isFunction()); |
16 assertEquals(resolver, event_data.resolver().value()); | 16 assertEquals(resolver, event_data.resolver().value()); |
17 assertTrue(event_data.resolver().resolved()); | 17 assertTrue(event_data.resolver().resolved()); |
18 assertEquals("resolver", event_data.resolver().name()); | 18 assertEquals("resolver", event_data.resolver().name()); |
19 assertTrue(event_data.resolver().source().indexOf("Token") > 0); | 19 assertTrue(event_data.resolver().source().indexOf("Token") > 0); |
20 | 20 |
21 assertTrue(event_data.promise().isPromise()); | 21 assertTrue(event_data.promise().isPromise()); |
22 new_promise = event_data.promise().value(); | 22 new_promise = event_data.promise().value(); |
23 assertEquals("pending", event_data.promise().status()); | 23 assertEquals("pending", event_data.promise().status()); |
24 } catch (e) { | 24 } catch (e) { |
25 print(e + e.stack) | 25 print(e + e.stack) |
26 exception = e; | 26 exception = e; |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 Debug.setListener(listener); | 30 Debug.setListener(listener); |
31 | 31 |
32 function resolver(resolve, reject) { | 32 function resolver(resolve, reject) { |
33 resolve(); // Token | 33 resolve(); // Token |
34 } | 34 } |
35 | 35 |
36 var p = new Promise(resolver); | 36 var p = new Promise(resolver); |
37 assertEquals(new_promise, p); | 37 assertEquals(new_promise, p); |
38 | 38 |
39 assertNull(exception); | 39 assertNull(exception); |
40 Debug.setListener(null); | 40 Debug.setListener(null); |
OLD | NEW |