OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --expose-debug-as debug --allow-natives-syntax | |
6 | |
7 // Test debug events when we only listen to uncaught exceptions and a | |
8 // Promise p3 created by Promise.all has no catch handler, and is rejected | |
9 // because one of the Promises p2 passed to Promise.all is rejected. | |
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 | |
12 // an additional rejection. | |
13 | |
14 var Debug = debug.Debug; | |
15 | |
16 var expected_events = 1; | |
17 var log = []; | |
18 | |
19 function listener(event, exec_state, event_data, data) { | |
20 if (event != Debug.DebugEvent.Exception) return; | |
21 try { | |
22 expected_events--; | |
23 assertTrue(expected_events >= 0); | |
24 assertEquals("uncaught", event_data.exception().message); | |
25 assertTrue(event_data.promise() instanceof Promise); | |
26 // Assert that the debug event is triggered at the throw site. | |
27 assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); | |
28 assertEquals("p2", event_data.promise().name); | |
29 assertTrue(event_data.uncaught()); | |
30 } catch (e) { | |
31 %AbortJS(e + "\n" + e.stack); | |
32 } | |
33 } | |
34 | |
35 Debug.setBreakOnUncaughtException(); | |
36 Debug.setListener(listener); | |
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.all([p2]); | |
49 p3.name = "p3"; | |
50 | |
51 log.push("end main"); | |
52 | |
53 function testDone(iteration) { | |
54 function checkResult() { | |
55 try { | |
56 assertTrue(iteration < 10); | |
57 if (expected_events === 0) { | |
58 assertEquals(["end main", "throw"], log); | |
59 } else { | |
60 testDone(iteration + 1); | |
61 } | |
62 } catch (e) { | |
63 %AbortJS(e + "\n" + e.stack); | |
64 } | |
65 } | |
66 | |
67 %EnqueueMicrotask(checkResult); | |
68 } | |
69 | |
70 testDone(0); | |
OLD | NEW |