WrappedFunction.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. JS_DECLARE_ALLOCATOR(WrappedFunction);
  13. public:
  14. static ThrowCompletionOr<NonnullGCPtr<WrappedFunction>> create(Realm&, Realm& caller_realm, FunctionObject& target_function);
  15. virtual ~WrappedFunction() = default;
  16. virtual ThrowCompletionOr<Value> internal_call(Value this_argument, ReadonlySpan<Value> arguments_list) override;
  17. // FIXME: Remove this (and stop inventing random internal slots that shouldn't exist, jeez)
  18. virtual DeprecatedFlyString const& name() const override { return m_wrapped_target_function->name(); }
  19. virtual Realm* realm() const override { return m_realm; }
  20. FunctionObject const& wrapped_target_function() const { return m_wrapped_target_function; }
  21. FunctionObject& wrapped_target_function() { return m_wrapped_target_function; }
  22. private:
  23. WrappedFunction(Realm&, FunctionObject&, Object& prototype);
  24. virtual void visit_edges(Visitor&) override;
  25. // Internal Slots of Wrapped Function Exotic Objects, https://tc39.es/proposal-shadowrealm/#table-internal-slots-of-wrapped-function-exotic-objects
  26. NonnullGCPtr<FunctionObject> m_wrapped_target_function; // [[WrappedTargetFunction]]
  27. NonnullGCPtr<Realm> m_realm; // [[Realm]]
  28. };
  29. ThrowCompletionOr<Value> ordinary_wrapped_function_call(WrappedFunction const&, Value this_argument, ReadonlySpan<Value> arguments_list);
  30. void prepare_for_wrapped_function_call(WrappedFunction const&, ExecutionContext& callee_context);
  31. }