/* * Copyright (c) 2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace JS { class NativeFunction : public FunctionObject { JS_OBJECT(NativeFunction, FunctionObject); public: static NativeFunction* create(GlobalObject&, const FlyString& name, Function); explicit NativeFunction(FlyString name, Function, Object& prototype); virtual void initialize(GlobalObject&) override { } virtual ~NativeFunction() override; virtual Value call() override; virtual Value construct(FunctionObject& new_target) override; virtual const FlyString& name() const override { return m_name; }; virtual bool is_strict_mode() const override; virtual bool has_constructor() const override { return false; } virtual Realm* realm() const override { return m_realm; } protected: NativeFunction(FlyString name, Object& prototype); explicit NativeFunction(Object& prototype); private: virtual FunctionEnvironment* create_environment(FunctionObject&) override final; virtual bool is_native_function() const final { return true; } FlyString m_name; Function m_native_function; Realm* m_realm { nullptr }; }; template<> inline bool Object::fast_is() const { return is_native_function(); } }