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