WrappedFunction.h 1.7 KB

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