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 --promise-extra | 5 // Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra |
6 | 6 |
7 // Test debug events when an exception is thrown inside a Promise, which is | 7 // Test debug events when an exception is thrown inside a Promise, which is |
8 // caught by a custom promise, which throws a new exception in its reject | 8 // caught by a custom promise, which throws a new exception in its reject |
9 // handler. We expect two Exception debug events: | 9 // handler. We expect two Exception debug events: |
10 // 1) when the exception is thrown in the promise q. | 10 // 1) when the exception is thrown in the promise q. |
11 // 2) when the custom reject closure in MyPromise throws an exception. | 11 // 2) when the custom reject closure in MyPromise throws an exception. |
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 p = new Promise(function(resolve, reject) { | 18 var p = new Promise(function(resolve, reject) { |
19 log.push("resolve"); | 19 log.push("resolve"); |
20 resolve(); | 20 resolve(); |
21 }); | 21 }); |
22 | 22 |
23 function MyPromise(resolver) { | 23 function MyPromise(resolver) { |
24 var reject = function() { | 24 var reject = function() { |
25 log.push("throw in reject"); | 25 log.push("throw in reject"); |
(...skipping 12 matching lines...) Expand all Loading... | |
38 function() { | 38 function() { |
39 log.push("throw caught"); | 39 log.push("throw caught"); |
40 throw new Error("caught"); // event | 40 throw new Error("caught"); // event |
41 }); | 41 }); |
42 | 42 |
43 function listener(event, exec_state, event_data, data) { | 43 function listener(event, exec_state, event_data, data) { |
44 try { | 44 try { |
45 if (event == Debug.DebugEvent.Exception) { | 45 if (event == Debug.DebugEvent.Exception) { |
46 expected_events--; | 46 expected_events--; |
47 assertTrue(expected_events >= 0); | 47 assertTrue(expected_events >= 0); |
48 if (expected_events == 1) { | 48 if (expected_events == 0) { |
49 assertEquals(["resolve", "construct", "end main", | 49 assertEquals(["resolve", "construct", "end main", |
50 "throw caught"], log); | 50 "throw caught"], log); |
51 assertEquals("caught", event_data.exception().message); | 51 assertEquals("caught", event_data.exception().message); |
52 } else if (expected_events == 0) { | |
53 assertEquals("reject", event_data.exception().message); | |
Dan Ehrenberg
2016/07/21 21:07:33
Nice fix; this really isn't a rejection.
| |
54 } else { | 52 } else { |
55 assertUnreachable(); | 53 assertUnreachable(); |
56 } | 54 } |
57 assertSame(q, event_data.promise()); | 55 assertSame(q, event_data.promise()); |
58 assertTrue(exec_state.frame(0).sourceLineText().indexOf('// event') > 0); | 56 assertTrue(exec_state.frame(0).sourceLineText().indexOf('// event') > 0); |
59 } | 57 } |
60 } catch (e) { | 58 } catch (e) { |
61 %AbortJS(e + "\n" + e.stack); | 59 %AbortJS(e + "\n" + e.stack); |
62 } | 60 } |
63 } | 61 } |
(...skipping 15 matching lines...) Expand all Loading... | |
79 } | 77 } |
80 } catch (e) { | 78 } catch (e) { |
81 %AbortJS(e + "\n" + e.stack); | 79 %AbortJS(e + "\n" + e.stack); |
82 } | 80 } |
83 } | 81 } |
84 | 82 |
85 %EnqueueMicrotask(checkResult); | 83 %EnqueueMicrotask(checkResult); |
86 } | 84 } |
87 | 85 |
88 testDone(0); | 86 testDone(0); |
OLD | NEW |