FunctionObject.h 930 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <LibJS/Runtime/Object.h>
  9. namespace JS {
  10. class FunctionObject : public Object {
  11. JS_OBJECT(Function, Object);
  12. public:
  13. virtual ~FunctionObject();
  14. virtual void initialize(GlobalObject&) override { }
  15. virtual Value call() = 0;
  16. virtual Value construct(FunctionObject& new_target) = 0;
  17. virtual const FlyString& name() const = 0;
  18. virtual FunctionEnvironment* create_environment(FunctionObject&) = 0;
  19. BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);
  20. virtual bool is_strict_mode() const { return false; }
  21. // [[Realm]]
  22. virtual Realm* realm() const { return nullptr; }
  23. protected:
  24. explicit FunctionObject(Object& prototype);
  25. private:
  26. virtual bool is_function() const override { return true; }
  27. };
  28. }