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 an exception is thrown inside a Promise, which is | |
8 // caught by a custom promise, which throws a new exception in its reject | |
9 // handler. We expect two Exception debug events: | |
10 // 1) when the exception is thrown in the promise q. | |
11 // 2) when the custom reject closure in MyPromise throws an exception. | |
12 | |
13 Debug = debug.Debug; | |
14 | |
15 var expected_events = 1; | |
16 var log = []; | |
17 | |
18 var p = new Promise(function(resolve, reject) { | |
19 log.push("resolve"); | |
20 resolve(); | |
21 }); | |
22 | |
23 function MyPromise(resolver) { | |
24 var reject = function() { | |
25 log.push("throw in reject"); | |
26 throw new Error("reject"); // event | |
27 }; | |
28 var resolve = function() { }; | |
29 log.push("construct"); | |
30 resolver(resolve, reject); | |
31 }; | |
32 | |
33 MyPromise.prototype = new Promise(function() {}); | |
34 MyPromise.__proto__ = Promise; | |
35 p.constructor = MyPromise; | |
36 | |
37 var q = p.then( | |
38 function() { | |
39 log.push("throw caught"); | |
40 throw new Error("caught"); // event | |
41 }); | |
42 | |
43 function listener(event, exec_state, event_data, data) { | |
44 try { | |
45 if (event == Debug.DebugEvent.Exception) { | |
46 expected_events--; | |
47 assertTrue(expected_events >= 0); | |
48 if (expected_events == 0) { | |
49 assertEquals(["resolve", "construct", "end main", | |
50 "throw caught"], log); | |
51 assertEquals("caught", event_data.exception().message); | |
52 } else { | |
53 assertUnreachable(); | |
54 } | |
55 assertSame(q, event_data.promise()); | |
56 assertTrue(exec_state.frame(0).sourceLineText().indexOf('// event') > 0); | |
57 } | |
58 } catch (e) { | |
59 %AbortJS(e + "\n" + e.stack); | |
60 } | |
61 } | |
62 | |
63 Debug.setBreakOnUncaughtException(); | |
64 Debug.setListener(listener); | |
65 | |
66 log.push("end main"); | |
67 | |
68 function testDone(iteration) { | |
69 function checkResult() { | |
70 try { | |
71 assertTrue(iteration < 10); | |
72 if (expected_events === 0) { | |
73 assertEquals(["resolve", "construct", "end main", | |
74 "throw caught", "throw in reject"], log); | |
75 } else { | |
76 testDone(iteration + 1); | |
77 } | |
78 } catch (e) { | |
79 %AbortJS(e + "\n" + e.stack); | |
80 } | |
81 } | |
82 | |
83 %EnqueueMicrotask(checkResult); | |
84 } | |
85 | |
86 testDone(0); | |
OLD | NEW |