OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 --allow-natives-syntax | 5 // Flags: --expose-debug-as debug --allow-natives-syntax |
6 | 6 |
7 // Test debug events when we only listen to uncaught exceptions and a | 7 // Test debug events when we only listen to uncaught exceptions and a |
8 // Promise p3 created by Promise.race has no catch handler, and is rejected | 8 // Promise p3 created by Promise.race has no catch handler, and is rejected |
9 // because one of the Promises p2 passed to Promise.race is rejected. | 9 // because one of the Promises p2 passed to Promise.race is rejected. |
10 // We expect one event for p2; the system recognizes the rejection of p3 | 10 // We expect one event for p2; the system recognizes the rejection of p3 |
11 // to be redundant and based on the rejection of p2 and does not trigger | 11 // to be redundant and based on the rejection of p2 and does not trigger |
12 // an additional rejection. | 12 // an additional rejection. |
13 | 13 |
14 var Debug = debug.Debug; | 14 var Debug = debug.Debug; |
15 | 15 |
16 var expected_events = 1; | 16 var expected_events = 1; |
17 var log = []; | 17 var log = []; |
18 | 18 |
19 var p1 = Promise.resolve(); | |
20 p1.name = "p1"; | |
21 | |
22 var p2 = p1.then(function() { | |
23 log.push("throw"); | |
24 throw new Error("uncaught"); // event | |
25 }); | |
26 | |
27 p2.name = "p2"; | |
28 | |
29 var p3 = Promise.race([p2]); | |
30 p3.name = "p3"; | |
31 | |
32 function listener(event, exec_state, event_data, data) { | 19 function listener(event, exec_state, event_data, data) { |
33 if (event != Debug.DebugEvent.Exception) return; | 20 if (event != Debug.DebugEvent.Exception) return; |
34 try { | 21 try { |
35 expected_events--; | 22 expected_events--; |
36 assertTrue(expected_events >= 0); | 23 assertTrue(expected_events >= 0); |
37 assertEquals("uncaught", event_data.exception().message); | 24 assertEquals("uncaught", event_data.exception().message); |
38 assertTrue(event_data.promise() instanceof Promise); | 25 assertTrue(event_data.promise() instanceof Promise); |
39 // Assert that the debug event is triggered at the throw site. | 26 // Assert that the debug event is triggered at the throw site. |
40 assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); | 27 assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); |
41 assertEquals("p2", event_data.promise().name); | 28 assertEquals("p2", event_data.promise().name); |
42 assertTrue(event_data.uncaught()); | 29 assertTrue(event_data.uncaught()); |
43 } catch (e) { | 30 } catch (e) { |
44 %AbortJS(e + "\n" + e.stack); | 31 %AbortJS(e + "\n" + e.stack); |
45 } | 32 } |
46 } | 33 } |
47 | 34 |
48 Debug.setBreakOnUncaughtException(); | 35 Debug.setBreakOnUncaughtException(); |
49 Debug.setListener(listener); | 36 Debug.setListener(listener); |
50 | 37 |
| 38 var p1 = Promise.resolve(); |
| 39 p1.name = "p1"; |
| 40 |
| 41 var p2 = p1.then(function() { |
| 42 log.push("throw"); |
| 43 throw new Error("uncaught"); // event |
| 44 }); |
| 45 |
| 46 p2.name = "p2"; |
| 47 |
| 48 var p3 = Promise.race([p2]); |
| 49 p3.name = "p3"; |
| 50 |
51 log.push("end main"); | 51 log.push("end main"); |
52 | 52 |
53 function testDone(iteration) { | 53 function testDone(iteration) { |
54 function checkResult() { | 54 function checkResult() { |
55 try { | 55 try { |
56 assertTrue(iteration < 10); | 56 assertTrue(iteration < 10); |
57 if (expected_events === 0) { | 57 if (expected_events === 0) { |
58 assertEquals(["end main", "throw"], log); | 58 assertEquals(["end main", "throw"], log); |
59 } else { | 59 } else { |
60 testDone(iteration + 1); | 60 testDone(iteration + 1); |
61 } | 61 } |
62 } catch (e) { | 62 } catch (e) { |
63 %AbortJS(e + "\n" + e.stack); | 63 %AbortJS(e + "\n" + e.stack); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 %EnqueueMicrotask(checkResult); | 67 %EnqueueMicrotask(checkResult); |
68 } | 68 } |
69 | 69 |
70 testDone(0); | 70 testDone(0); |
OLD | NEW |