/src/serenity/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibJS/Runtime/GlobalObject.h> |
8 | | #include <LibJS/Runtime/NativeFunction.h> |
9 | | #include <LibJS/Runtime/Promise.h> |
10 | | #include <LibJS/Runtime/PromiseResolvingFunction.h> |
11 | | |
12 | | namespace JS { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(AlreadyResolved); |
15 | | JS_DEFINE_ALLOCATOR(PromiseResolvingFunction); |
16 | | |
17 | | NonnullGCPtr<PromiseResolvingFunction> PromiseResolvingFunction::create(Realm& realm, Promise& promise, AlreadyResolved& already_resolved, FunctionType function) |
18 | 0 | { |
19 | 0 | return realm.heap().allocate<PromiseResolvingFunction>(realm, promise, already_resolved, move(function), realm.intrinsics().function_prototype()); |
20 | 0 | } |
21 | | |
22 | | PromiseResolvingFunction::PromiseResolvingFunction(Promise& promise, AlreadyResolved& already_resolved, FunctionType native_function, Object& prototype) |
23 | 0 | : NativeFunction(prototype) |
24 | 0 | , m_promise(promise) |
25 | 0 | , m_already_resolved(already_resolved) |
26 | 0 | , m_native_function(move(native_function)) |
27 | 0 | { |
28 | 0 | } |
29 | | |
30 | | void PromiseResolvingFunction::initialize(Realm& realm) |
31 | 0 | { |
32 | 0 | Base::initialize(realm); |
33 | 0 | define_direct_property(vm().names.length, Value(1), Attribute::Configurable); |
34 | 0 | } |
35 | | |
36 | | ThrowCompletionOr<Value> PromiseResolvingFunction::call() |
37 | 0 | { |
38 | 0 | return m_native_function(vm(), m_promise, m_already_resolved); |
39 | 0 | } |
40 | | |
41 | | void PromiseResolvingFunction::visit_edges(Cell::Visitor& visitor) |
42 | 0 | { |
43 | 0 | Base::visit_edges(visitor); |
44 | 0 | visitor.visit(m_promise); |
45 | 0 | visitor.visit(m_already_resolved); |
46 | 0 | } |
47 | | |
48 | | } |