BoundFunction.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2020, Jack Karamanian <karamanian.jack@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/FunctionObject.h>
  8. namespace JS {
  9. class BoundFunction final : public FunctionObject {
  10. JS_OBJECT(BoundFunction, FunctionObject);
  11. public:
  12. BoundFunction(GlobalObject&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments, i32 length, Object* constructor_prototype);
  13. virtual void initialize(GlobalObject&) override;
  14. virtual ~BoundFunction();
  15. virtual Value call() override;
  16. virtual Value construct(FunctionObject& new_target) override;
  17. virtual FunctionEnvironment* new_function_environment(Object* new_target) override;
  18. virtual const FlyString& name() const override { return m_name; }
  19. virtual bool is_strict_mode() const override { return m_bound_target_function->is_strict_mode(); }
  20. virtual bool has_constructor() const override { return true; }
  21. FunctionObject& bound_target_function() const { return *m_bound_target_function; }
  22. Value bound_this() const { return m_bound_this; }
  23. Vector<Value> const& bound_arguments() const { return m_bound_arguments; }
  24. private:
  25. virtual void visit_edges(Visitor&) override;
  26. FunctionObject* m_bound_target_function { nullptr }; // [[BoundTargetFunction]]
  27. Value m_bound_this; // [[BoundThis]]
  28. Vector<Value> m_bound_arguments; // [[BoundArguments]]
  29. Object* m_constructor_prototype { nullptr };
  30. FlyString m_name;
  31. i32 m_length { 0 };
  32. };
  33. }