summaryrefslogtreecommitdiffstats
path: root/util/wasm/batchedtestrunner/util.js
blob: a297baf6b29b21a1d7aec4b2c9c2f2aceb2406e0 (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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

export function parseQuery() {
    const trimmed = window.location.search.substring(1);
    return new Map(
        trimmed.length === 0 ?
            [] :
            trimmed.split('&').map(paramNameAndValue => {
                const [name, value] = paramNameAndValue.split('=');
                return [decodeURIComponent(name), value ? decodeURIComponent(value) : ''];
            }));
}

export class EventSource {
    #listeners = [];

    constructor(receivePrivateInterface) {
        receivePrivateInterface({
            fireEvent: (arg0, arg1) => this.#fireEvent(arg0, arg1)
        });
    }

    addEventListener(listener) {
        this.#listeners.push(listener);
    }

    #fireEvent(arg0, arg1) {
        this.#listeners.forEach(listener => listener(arg0, arg1));
    }
}