FunctionObject.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Optional.h>
  9. #include <AK/StringView.h>
  10. #include <LibJS/Runtime/Object.h>
  11. #include <LibJS/Runtime/PrivateEnvironment.h>
  12. #include <LibJS/Runtime/PropertyKey.h>
  13. namespace JS {
  14. class FunctionObject : public Object {
  15. JS_OBJECT(Function, Object);
  16. public:
  17. virtual ~FunctionObject() = default;
  18. virtual void initialize(Realm&) override { }
  19. // Table 7: Additional Essential Internal Methods of Function Objects, https://tc39.es/ecma262/#table-additional-essential-internal-methods-of-function-objects
  20. virtual ThrowCompletionOr<Value> internal_call(Value this_argument, MarkedVector<Value> arguments_list) = 0;
  21. virtual ThrowCompletionOr<Object*> internal_construct([[maybe_unused]] MarkedVector<Value> arguments_list, [[maybe_unused]] FunctionObject& new_target) { VERIFY_NOT_REACHED(); }
  22. virtual FlyString const& name() const = 0;
  23. void set_function_name(Variant<PropertyKey, PrivateName> const& name_arg, Optional<StringView> const& prefix = {});
  24. void set_function_length(double length);
  25. virtual bool is_strict_mode() const { return false; }
  26. virtual bool has_constructor() const { return false; }
  27. // [[Realm]]
  28. virtual Realm* realm() const { return nullptr; }
  29. protected:
  30. explicit FunctionObject(Realm&, Object* prototype);
  31. explicit FunctionObject(Object& prototype);
  32. private:
  33. virtual bool is_function() const override { return true; }
  34. };
  35. }