/* * Copyright (c) 2020-2021, Andreas Kling * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace JS { class FunctionObject : public Object { JS_OBJECT(FunctionObject, Object); public: virtual ~FunctionObject() = default; // Table 5: Additional Essential Internal Methods of Function Objects, https://tc39.es/ecma262/#table-additional-essential-internal-methods-of-function-objects virtual ThrowCompletionOr internal_call(Value this_argument, ReadonlySpan arguments_list) = 0; virtual ThrowCompletionOr> internal_construct([[maybe_unused]] ReadonlySpan arguments_list, [[maybe_unused]] FunctionObject& new_target) { VERIFY_NOT_REACHED(); } void set_function_name(Variant const& name_arg, Optional const& prefix = {}); void set_function_length(double length); virtual bool is_strict_mode() const { return false; } virtual bool has_constructor() const { return false; } // [[Realm]] virtual Realm* realm() const { return nullptr; } virtual Vector const& local_variables_names() const { VERIFY_NOT_REACHED(); } virtual FunctionParameters const& formal_parameters() const { VERIFY_NOT_REACHED(); } protected: explicit FunctionObject(Realm&, Object* prototype, MayInterfereWithIndexedPropertyAccess = MayInterfereWithIndexedPropertyAccess::No); explicit FunctionObject(Object& prototype, MayInterfereWithIndexedPropertyAccess = MayInterfereWithIndexedPropertyAccess::No); [[nodiscard]] GC::Ref make_function_name(Variant const&, Optional const& prefix); private: virtual bool is_function() const override { return true; } }; template<> inline bool Object::fast_is() const { return is_function(); } }