FunctionObject.h 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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* new_function_environment(Object* new_target) = 0;
  19. BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);
  20. virtual bool is_strict_mode() const { return false; }
  21. virtual bool has_constructor() const { return false; }
  22. // [[Realm]]
  23. virtual Realm* realm() const { return nullptr; }
  24. protected:
  25. explicit FunctionObject(Object& prototype);
  26. private:
  27. virtual bool is_function() const override { return true; }
  28. };
  29. }