Coverage Report

Created: 2025-09-05 06:52

/src/serenity/Userland/Libraries/LibJS/Runtime/WrappedFunction.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibJS/Runtime/FunctionObject.h>
10
#include <LibJS/Runtime/Realm.h>
11
12
namespace JS {
13
14
class WrappedFunction final : public FunctionObject {
15
    JS_OBJECT(WrappedFunction, FunctionObject);
16
    JS_DECLARE_ALLOCATOR(WrappedFunction);
17
18
public:
19
    static ThrowCompletionOr<NonnullGCPtr<WrappedFunction>> create(Realm&, Realm& caller_realm, FunctionObject& target_function);
20
21
    virtual ~WrappedFunction() = default;
22
23
    virtual ThrowCompletionOr<Value> internal_call(Value this_argument, ReadonlySpan<Value> arguments_list) override;
24
25
    // FIXME: Remove this (and stop inventing random internal slots that shouldn't exist, jeez)
26
0
    virtual DeprecatedFlyString const& name() const override { return m_wrapped_target_function->name(); }
27
28
0
    virtual Realm* realm() const override { return m_realm; }
29
30
0
    FunctionObject const& wrapped_target_function() const { return m_wrapped_target_function; }
31
0
    FunctionObject& wrapped_target_function() { return m_wrapped_target_function; }
32
33
private:
34
    WrappedFunction(Realm&, FunctionObject&, Object& prototype);
35
36
    virtual void visit_edges(Visitor&) override;
37
38
    // Internal Slots of Wrapped Function Exotic Objects, https://tc39.es/proposal-shadowrealm/#table-internal-slots-of-wrapped-function-exotic-objects
39
    NonnullGCPtr<FunctionObject> m_wrapped_target_function; // [[WrappedTargetFunction]]
40
    NonnullGCPtr<Realm> m_realm;                            // [[Realm]]
41
};
42
43
ThrowCompletionOr<Value> ordinary_wrapped_function_call(WrappedFunction const&, Value this_argument, ReadonlySpan<Value> arguments_list);
44
void prepare_for_wrapped_function_call(WrappedFunction const&, ExecutionContext& callee_context);
45
46
}