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: --harmony-promises --expose-debug-as debug | |
6 | |
7 Debug = debug.Debug; | |
8 | |
9 var resolve_fun; | |
10 var log = []; | |
11 var step = 0; | |
12 var exception = undefined; | |
13 | |
14 var p = new Promise(function(resolve, reject) { | |
15 log.push("resolve"); | |
16 resolve(); | |
17 }); | |
18 | |
19 var q = p.chain( | |
20 function() { | |
21 log.push("throw"); | |
22 throw new Error("uncaught"); | |
23 }); | |
24 | |
25 function listener(event, exec_state, event_data, data) { | |
26 try { | |
27 // Ignore exceptions during startup in stress runs. | |
28 if (step > 1) return; | |
29 assertEquals(["resolve", "end main", "throw"], log); | |
30 if (event == Debug.DebugEvent.Exception) { | |
yurys
2014/04/24 08:49:50
Would be nice to also test that this branch is not
| |
31 assertEquals(0, step); | |
32 exception = event_data.exception(); | |
33 assertEquals(undefined, event_data.promise()); | |
34 } else if (event == Debug.DebugEvent.PendingExceptionInPromise) { | |
35 assertEquals(1, step); | |
36 assertEquals(exception, event_data.exception()); | |
37 assertEquals("uncaught", exception.message); | |
38 assertTrue(event_data.promise() instanceof Promise); | |
39 assertTrue(event_data.uncaught()); | |
40 } else { | |
41 return; | |
42 } | |
43 step++; | |
44 } catch (e) { | |
45 // Signal a failure with exit code 1. This is necessary since the | |
46 // debugger swallows exceptions and we expect the chained function | |
47 // and this listener to be executed after the main script is finished. | |
48 print("Unexpected exception:"); | |
rossberg
2014/04/24 08:08:38
Nit: don't need a newline after this
Yang
2014/04/24 10:42:04
Done.
| |
49 print(e + "\n" + e.stack); | |
50 quit(1); | |
51 } | |
52 } | |
53 | |
54 Debug.setBreakOnException(); | |
55 Debug.setListener(listener); | |
56 | |
57 log.push("end main"); | |
OLD | NEW |