| 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 assertTrue(line.indexOf(`B${break_count}`) > 0); | |
| 45 } catch (e) { | |
| 46 exception = e; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 Debug.setListener(listener); | |
| 51 | |
| 52 async function g() { | |
| 53 throw 1; | |
| 54 } | |
| 55 | |
| 56 async function f() { | |
| 57 try { | |
| 58 await g(); // B1 | |
| 59 } catch (e) {} | |
| 60 assertEquals(2, break_count); // B2 | |
| 61 return 1; // B3 | |
| 62 } | |
| 63 | |
| 64 Debug.setBreakPoint(f, 2); | |
| 65 Debug.setBreakPoint(f, 4); | |
| 66 Debug.setBreakPoint(f, 5); | |
| 67 | |
| 68 f(); | |
| 69 | |
| 70 %RunMicrotasks(); | |
| 71 | |
| 72 assertEqualsAsync(3, async () => break_count); | |
| 73 assertEqualsAsync(null, async () => exception); | |
| 74 | |
| 75 Debug.setListener(null); | |
| OLD | NEW |