summaryrefslogtreecommitdiff
path: root/deps/v8/test/debugger/debug/es6/debug-promises/reject-in-constructor-opt.js
blob: 2b8ebb1c0b516d0c3b02759f6b95eb5e094ab772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


// Test exercises code paths for catching exceptions in the promise constructor
// in conjunction with deoptimization.

Debug = debug.Debug;

var expected_events = 4;

function listener(event, exec_state, event_data, data) {
  try {
    if (event == Debug.DebugEvent.Exception) {
      expected_events--;
      assertTrue(expected_events >= 0);
      assertEquals("uncaught", event_data.exception().message);
      assertTrue(event_data.uncaught());
      // The frame comes from the Promise.reject call
      assertNotNull(/\/\/ EXCEPTION/.exec(event_data.sourceLineText()));
      assertTrue(event_data.uncaught());
    }
  } catch (e) {
    %AbortJS(e + "\n" + e.stack);
  }
}

Debug.setBreakOnException();
Debug.setListener(listener);

function foo(a,b) {
    let P = new Promise((resolve, reject) => { bar(a,b); resolve()})
    return P;
}

function bar(a,b) {
  %DeoptimizeFunction(foo);
  throw new Error("uncaught"); // EXCEPTION
}

foo();
%PerformMicrotaskCheckpoint();

foo();
%PerformMicrotaskCheckpoint();

%OptimizeFunctionOnNextCall(foo);

// bar likely gets inlined into foo.
foo();
%PerformMicrotaskCheckpoint();

%NeverOptimizeFunction(bar);
%OptimizeFunctionOnNextCall(foo);

// bar does not get inlined into foo.
foo();
%PerformMicrotaskCheckpoint();

assertEquals(0, expected_events);