summaryrefslogtreecommitdiffstats
path: root/src/corelib/platform/wasm/qtcontextfulpromise_injection.js
blob: ce5623171c61212d3afb870f667c8a84af27808f (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
`Copyright (C) 2022 The Qt Company Ltd.
Copyright (C) 2016 Intel Corporation.
SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0`;

if (window.qtContextfulPromiseSupport) {
    ++window.qtContextfulPromiseSupport.refs;
} else {
    window.qtContextfulPromiseSupport = {
        refs: 1,
        removeRef: () => {
            --window.qtContextfulPromiseSupport.refs, 0 === window.qtContextfulPromiseSupport.refs && delete window.qtContextfulPromiseSupport;
        },
        makePromise: (a, b, c) => new window.qtContextfulPromiseSupport.ContextfulPromise(a, b, c),
    };

    window.qtContextfulPromiseSupport.ContextfulPromise = class {
        constructor(a, b, c) {
            (this.wrappedPromise = a), (this.context = b), (this.callbackThunk = c);
        }
        then() {
            return (this.wrappedPromise = this.wrappedPromise.then((a) => { this.callbackThunk("then", this.context, a); })), this;
        }
        catch() {
            return (this.wrappedPromise = this.wrappedPromise.catch((a) => { this.callbackThunk("catch", this.context, a); })), this;
        }
        finally() {
            return (this.wrappedPromise = this.wrappedPromise.finally(() => this.callbackThunk("finally", this.context, undefined))), this;
        }
    };
}

document.querySelector("[qtinjection=contextfulpromise]")?.remove();