FunctionObject.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(FunctionObject, Object);
  16. public:
  17. virtual ~FunctionObject() = default;
  18. // Table 7: Additional Essential Internal Methods of Function Objects, https://tc39.es/ecma262/#table-additional-essential-internal-methods-of-function-objects
  19. virtual ThrowCompletionOr<Value> internal_call(Value this_argument, MarkedVector<Value> arguments_list) = 0;
  20. virtual ThrowCompletionOr<NonnullGCPtr<Object>> internal_construct([[maybe_unused]] MarkedVector<Value> arguments_list, [[maybe_unused]] FunctionObject& new_target) { VERIFY_NOT_REACHED(); }
  21. virtual DeprecatedFlyString const& name() const = 0;
  22. void set_function_name(Variant<PropertyKey, PrivateName> const& name_arg, Optional<StringView> const& prefix = {});
  23. void set_function_length(double length);
  24. virtual bool is_strict_mode() const { return false; }
  25. virtual bool has_constructor() const { return false; }
  26. // [[Realm]]
  27. virtual Realm* realm() const { return nullptr; }
  28. virtual Vector<DeprecatedFlyString> const& local_variables_names() const { VERIFY_NOT_REACHED(); }
  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. }