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 return Promise.reject(new Error("123")); | 22 return Promise.reject(new Error("123")); |
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, with the error from the Promise.reject line |
47 // p1 is rejected, uncaught, with the error from the Promise.reject line | 47 assertNotNull(event_data.sourceLineText().match("Promise.reject")); |
48 assertNotNull(event_data.sourceLineText().match("Promise.reject")); | 48 assertSame(p1, event_data.promise()); |
49 assertSame(p1, event_data.promise()); | |
50 } else { | |
51 // p2 is rejected by p1's default reject handler. | |
52 assertEquals(0, exec_state.frameCount()); | |
53 assertSame(p2, event_data.promise()); | |
54 } | |
55 } | 49 } |
56 } catch (e) { | 50 } catch (e) { |
57 %AbortJS(e + "\n" + e.stack); | 51 %AbortJS(e + "\n" + e.stack); |
58 } | 52 } |
59 } | 53 } |
60 | 54 |
61 Debug.setBreakOnUncaughtException(); | 55 Debug.setBreakOnUncaughtException(); |
62 Debug.setListener(listener); | 56 Debug.setListener(listener); |
63 | 57 |
64 log.push("end main"); | 58 log.push("end main"); |
65 | 59 |
66 function testDone(iteration) { | 60 function testDone(iteration) { |
67 function checkResult() { | 61 function checkResult() { |
68 try { | 62 try { |
69 assertTrue(iteration < 10); | 63 assertTrue(iteration < 10); |
70 if (expected_events === 0) { | 64 if (expected_events === 0) { |
71 assertEquals(["resolve q", "end main", "resolve p", "p0.then"], log); | 65 assertEquals(["resolve q", "end main", "resolve p", "p0.then"], log); |
72 } else { | 66 } else { |
73 testDone(iteration + 1); | 67 testDone(iteration + 1); |
74 } | 68 } |
75 } catch (e) { | 69 } catch (e) { |
76 %AbortJS(e + "\n" + e.stack); | 70 %AbortJS(e + "\n" + e.stack); |
77 } | 71 } |
78 } | 72 } |
79 | 73 |
80 %EnqueueMicrotask(checkResult); | 74 %EnqueueMicrotask(checkResult); |
81 } | 75 } |
82 | 76 |
83 testDone(0); | 77 testDone(0); |
OLD | NEW |