OLD | NEW |
| (Empty) |
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 | |
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 | |
8 // there is only a default reject handler for the to-be-rejected Promise. | |
9 // We expect only one debug event: when the first Promise is rejected | |
10 // and only has default reject handlers. No event is triggered when | |
11 // simply forwarding the rejection with .then's default handler. | |
12 | |
13 Debug = debug.Debug; | |
14 | |
15 var expected_events = 1; | |
16 var log = []; | |
17 | |
18 var resolve, reject; | |
19 var p0 = new Promise(function(res, rej) { resolve = res; reject = rej; }); | |
20 var p1 = p0.then(function() { | |
21 log.push("p0.then"); | |
22 throw new Error("123"); // event | |
23 }); | |
24 var p2 = p1.then(function() { | |
25 log.push("p1.then"); | |
26 }); | |
27 | |
28 var q = new Promise(function(res, rej) { | |
29 log.push("resolve q"); | |
30 res(); | |
31 }); | |
32 | |
33 q.then(function() { | |
34 log.push("resolve p"); | |
35 resolve(); | |
36 }) | |
37 | |
38 | |
39 function listener(event, exec_state, event_data, data) { | |
40 try { | |
41 if (event == Debug.DebugEvent.Exception) { | |
42 expected_events--; | |
43 assertTrue(expected_events >= 0); | |
44 assertTrue(event_data.uncaught()); | |
45 assertTrue(event_data.promise() instanceof Promise); | |
46 // p1 is rejected, uncaught except for its default reject handler. | |
47 assertTrue( | |
48 exec_state.frame(0).sourceLineText().indexOf("// event") > 0); | |
49 assertSame(p1, event_data.promise()); | |
50 } | |
51 } catch (e) { | |
52 %AbortJS(e + "\n" + e.stack); | |
53 } | |
54 } | |
55 | |
56 Debug.setBreakOnUncaughtException(); | |
57 Debug.setListener(listener); | |
58 | |
59 log.push("end main"); | |
60 | |
61 function testDone(iteration) { | |
62 function checkResult() { | |
63 try { | |
64 assertTrue(iteration < 10); | |
65 if (expected_events === 0) { | |
66 assertEquals(["resolve q", "end main", "resolve p", "p0.then"], log); | |
67 } else { | |
68 testDone(iteration + 1); | |
69 } | |
70 } catch (e) { | |
71 %AbortJS(e + "\n" + e.stack); | |
72 } | |
73 } | |
74 | |
75 %EnqueueMicrotask(checkResult); | |
76 } | |
77 | |
78 testDone(0); | |
OLD | NEW |