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