FunctionObject.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // Table 7: Additional Essential Internal Methods of Function Objects, https://tc39.es/ecma262/#table-additional-essential-internal-methods-of-function-objects
  16. virtual ThrowCompletionOr<Value> internal_call(Value this_argument, MarkedValueList arguments_list) = 0;
  17. virtual ThrowCompletionOr<Object*> internal_construct([[maybe_unused]] MarkedValueList arguments_list, [[maybe_unused]] FunctionObject& new_target) { VERIFY_NOT_REACHED(); }
  18. virtual const FlyString& name() const = 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. }