OLD | NEW |
| (Empty) |
1 // Copyright 2016 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-async-await | |
6 | |
7 var Debug = debug.Debug; | |
8 | |
9 function assertEqualsAsync(expected, run, msg) { | |
10 var actual; | |
11 var hadValue = false; | |
12 var hadError = false; | |
13 var promise = run(); | |
14 | |
15 if (typeof promise !== "object" || typeof promise.then !== "function") { | |
16 throw new MjsUnitAssertionError( | |
17 "Expected " + run.toString() + | |
18 " to return a Promise, but it returned " + promise); | |
19 } | |
20 | |
21 promise.then(function(value) { hadValue = true; actual = value; }, | |
22 function(error) { hadError = true; actual = error; }); | |
23 | |
24 assertFalse(hadValue || hadError); | |
25 | |
26 %RunMicrotasks(); | |
27 | |
28 if (hadError) throw actual; | |
29 | |
30 assertTrue( | |
31 hadValue, "Expected '" + run.toString() + "' to produce a value"); | |
32 | |
33 assertEquals(expected, actual, msg); | |
34 } | |
35 | |
36 var break_count = 0; | |
37 var exception = null; | |
38 | |
39 function listener(event, exec_state, event_data, data) { | |
40 if (event != Debug.DebugEvent.Break) return; | |
41 try { | |
42 break_count++; | |
43 var line = exec_state.frame(0).sourceLineText(); | |
44 print(line); | |
45 assertTrue(line.indexOf(`B${break_count}`) > 0); | |
46 } catch (e) { | |
47 exception = e; | |
48 } | |
49 } | |
50 | |
51 | |
52 async function g() { | |
53 setbreaks(); | |
54 throw 1; // B1 | |
55 } | |
56 | |
57 async function f() { | |
58 try { | |
59 await g(); | |
60 } catch (e) {} | |
61 return 2; // B2 | |
62 } | |
63 | |
64 function setbreaks() { | |
65 Debug.setListener(listener); | |
66 Debug.setBreakPoint(g, 2); | |
67 Debug.setBreakPoint(f, 4); | |
68 } | |
69 | |
70 f(); | |
71 | |
72 %RunMicrotasks(); | |
73 | |
74 assertEqualsAsync(2, async () => break_count); | |
75 assertEqualsAsync(null, async () => exception); | |
76 | |
77 Debug.setListener(null); | |
OLD | NEW |