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 has no reject handler. | 8 // caught by a custom promise, which has no reject handler. |
9 // We expect a PendingExceptionInPromise event to be triggered. | 9 // We expect an Exception 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 }); |
20 | 20 |
21 function MyPromise(resolver) { | 21 function MyPromise(resolver) { |
22 var reject = undefined; | 22 var reject = undefined; |
23 var resolve = function() { }; | 23 var resolve = function() { }; |
24 log.push("construct"); | 24 log.push("construct"); |
25 resolver(resolve, reject); | 25 resolver(resolve, reject); |
26 }; | 26 }; |
27 | 27 |
28 MyPromise.prototype = p; | 28 MyPromise.prototype = p; |
29 p.constructor = MyPromise; | 29 p.constructor = MyPromise; |
30 | 30 |
31 var q = p.chain( | 31 var q = p.chain( |
32 function() { | 32 function() { |
33 log.push("throw caught"); | 33 log.push("throw caught"); |
34 throw new Error("caught"); | 34 throw new Error("caught"); // event |
35 }); | 35 }); |
36 | 36 |
37 function listener(event, exec_state, event_data, data) { | 37 function listener(event, exec_state, event_data, data) { |
38 try { | 38 try { |
39 if (event == Debug.DebugEvent.PendingExceptionInPromise) { | 39 if (event == Debug.DebugEvent.Exception) { |
40 assertEquals(["resolve", "construct", "end main", "throw caught"], log); | 40 assertEquals(["resolve", "construct", "end main", "throw caught"], log); |
41 assertEquals("caught", event_data.exception().message); | 41 assertEquals("undefined is not a function", |
42 } else if (event == Debug.DebugEvent.Exception) { | 42 event_data.exception().message); |
43 assertUnreachable(); | 43 assertEquals(q, event_data.promise()); |
44 } | 44 } |
45 } catch (e) { | 45 } catch (e) { |
46 // Signal a failure with exit code 1. This is necessary since the | 46 // Signal a failure with exit code 1. This is necessary since the |
47 // debugger swallows exceptions and we expect the chained function | 47 // debugger swallows exceptions and we expect the chained function |
48 // and this listener to be executed after the main script is finished. | 48 // and this listener to be executed after the main script is finished. |
49 print("Unexpected exception: " + e + "\n" + e.stack); | 49 print("Unexpected exception: " + e + "\n" + e.stack); |
50 quit(1); | 50 quit(1); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 Debug.setBreakOnUncaughtException(); | 54 Debug.setBreakOnUncaughtException(); |
55 Debug.setListener(listener); | 55 Debug.setListener(listener); |
56 | 56 |
57 log.push("end main"); | 57 log.push("end main"); |
OLD | NEW |