Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/StringView.h>
10
#include <LibJS/Runtime/NativeFunction.h>
11
12
namespace JS {
13
14
struct AlreadyResolved final : public Cell {
15
    JS_CELL(AlreadyResolved, Cell);
16
    JS_DECLARE_ALLOCATOR(AlreadyResolved);
17
18
    bool value { false };
19
20
protected:
21
    // Allocated cells must be >= sizeof(FreelistEntry), which is 24 bytes -
22
    // but AlreadyResolved is only 16 bytes without this.
23
    u8 dummy[8];
24
};
25
26
class PromiseResolvingFunction final : public NativeFunction {
27
    JS_OBJECT(PromiseResolvingFunction, NativeFunction);
28
    JS_DECLARE_ALLOCATOR(PromiseResolvingFunction);
29
30
public:
31
    using FunctionType = Function<Value(VM&, Promise&, AlreadyResolved&)>;
32
33
    static NonnullGCPtr<PromiseResolvingFunction> create(Realm&, Promise&, AlreadyResolved&, FunctionType);
34
35
    virtual void initialize(Realm&) override;
36
0
    virtual ~PromiseResolvingFunction() override = default;
37
38
    virtual ThrowCompletionOr<Value> call() override;
39
40
private:
41
    explicit PromiseResolvingFunction(Promise&, AlreadyResolved&, FunctionType, Object& prototype);
42
43
    virtual void visit_edges(Visitor&) override;
44
45
    NonnullGCPtr<Promise> m_promise;
46
    NonnullGCPtr<AlreadyResolved> m_already_resolved;
47
    FunctionType m_native_function;
48
};
49
50
}