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: --harmony-promises --expose-debug-as debug | 5 // Flags: --harmony-promises --expose-debug-as debug |
6 | 6 |
7 // Test debug events when an exception is thrown inside a Promise, which is | 7 // Test debug events when an exception is thrown inside a Promise, which is |
8 // caught by a custom promise, which throws a new exception in its reject | 8 // caught by a custom promise, which throws a new exception in its reject |
9 // handler. We expect a PendingExceptionInPromise event to be triggered. | 9 // handler. We expect an Exception debug event with a promise to be triggered. |
10 | 10 |
11 Debug = debug.Debug; | 11 Debug = debug.Debug; |
12 | 12 |
13 var log = []; | 13 var log = []; |
14 var step = 0; | 14 var step = 0; |
15 | 15 |
16 var p = new Promise(function(resolve, reject) { | 16 var p = new Promise(function(resolve, reject) { |
17 log.push("resolve"); | 17 log.push("resolve"); |
18 resolve(); | 18 resolve(); |
19 }); | 19 }); |
(...skipping 12 matching lines...) Expand all Loading... | |
32 p.constructor = MyPromise; | 32 p.constructor = MyPromise; |
33 | 33 |
34 var q = p.chain( | 34 var q = p.chain( |
35 function() { | 35 function() { |
36 log.push("throw caught"); | 36 log.push("throw caught"); |
37 throw new Error("caught"); | 37 throw new Error("caught"); |
38 }); | 38 }); |
39 | 39 |
40 function listener(event, exec_state, event_data, data) { | 40 function listener(event, exec_state, event_data, data) { |
41 try { | 41 try { |
42 if (event == Debug.DebugEvent.PendingExceptionInPromise) { | 42 if (event == Debug.DebugEvent.Exception) { |
43 assertEquals(["resolve", "construct", "end main", | 43 assertEquals(["resolve", "construct", "end main", |
44 "throw caught", "throw reject"], log); | 44 "throw caught", "throw reject"], log); |
45 assertEquals("caught", event_data.exception().message); | 45 assertEquals("reject", event_data.exception().message); |
46 } else if (event == Debug.DebugEvent.Exception) { | 46 assertEquals(q, event_data.promise()); |
aandrey
2014/04/30 13:01:07
assertTrue(exec_state.frame(0).sourceLineText().in
| |
47 assertUnreachable(); | |
48 } | 47 } |
49 } catch (e) { | 48 } catch (e) { |
50 // Signal a failure with exit code 1. This is necessary since the | 49 // Signal a failure with exit code 1. This is necessary since the |
51 // debugger swallows exceptions and we expect the chained function | 50 // debugger swallows exceptions and we expect the chained function |
52 // and this listener to be executed after the main script is finished. | 51 // and this listener to be executed after the main script is finished. |
53 print("Unexpected exception: " + e + "\n" + e.stack); | 52 print("Unexpected exception: " + e + "\n" + e.stack); |
54 quit(1); | 53 quit(1); |
55 } | 54 } |
56 } | 55 } |
57 | 56 |
58 Debug.setBreakOnUncaughtException(); | 57 Debug.setBreakOnUncaughtException(); |
59 Debug.setListener(listener); | 58 Debug.setListener(listener); |
60 | 59 |
61 log.push("end main"); | 60 log.push("end main"); |
OLD | NEW |