• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8var Debug = debug.Debug;
9
10function 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
37var break_count = 0;
38var exception = null;
39
40function 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
51Debug.setListener(listener);
52
53async function g() {
54  throw 1;
55}
56
57async function f() {
58  try {
59    await g();                   // B1
60  } catch (e) {}
61  assertEquals(2, break_count);  // B2
62  return 1;                      // B3
63}
64
65Debug.setBreakPoint(f, 2);
66Debug.setBreakPoint(f, 4);
67Debug.setBreakPoint(f, 5);
68
69f();
70
71%RunMicrotasks();
72
73assertEqualsAsync(3, async () => break_count);
74assertEqualsAsync(null, async () => exception);
75
76Debug.setListener(null);
77