summaryrefslogtreecommitdiff
path: root/deps/v8/test/debugger/debug/es6/debug-promises/proxy-as-promise.js
blob: 431837ceba70672d0ba473a625d0ac45aad6b8eb (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
// 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 debug events when we listen to all exceptions and
// there is a catch handler for the exception thrown in a Promise.
// We expect a normal Exception debug event to be triggered.

Debug = debug.Debug;

var expected_events = 1;
var log = [];


class P extends Promise {
    constructor(...args) {
        super(...args);
        return new Proxy(this, {
            get(target, property, receiver) {
                if (property in target) {
                    return Reflect.get(target, property, receiver);
                } else {
                    return (...args) =>
                        new Promise((resolve, reject) =>
                            target.then(v => resolve(v[property](...args)))
                                .catch(reject)
                        );
                }
            }
        });
    }
}

P.resolve({doStuff(){log.push(1)}}).doStuff()

function listener(event, exec_state, event_data, data) {}

Debug.setBreakOnUncaughtException();
Debug.setListener(listener);

%PerformMicrotaskCheckpoint();