Function.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2020, 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 Function : public Object {
  11. JS_OBJECT(Function, Object);
  12. public:
  13. enum class ConstructorKind {
  14. Base,
  15. Derived,
  16. };
  17. virtual ~Function();
  18. virtual void initialize(GlobalObject&) override { }
  19. virtual Value call() = 0;
  20. virtual Value construct(Function& new_target) = 0;
  21. virtual const FlyString& name() const = 0;
  22. virtual LexicalEnvironment* create_environment() = 0;
  23. BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);
  24. Value bound_this() const { return m_bound_this; }
  25. const Vector<Value>& bound_arguments() const { return m_bound_arguments; }
  26. Value home_object() const { return m_home_object; }
  27. void set_home_object(Value home_object) { m_home_object = home_object; }
  28. ConstructorKind constructor_kind() const { return m_constructor_kind; };
  29. void set_constructor_kind(ConstructorKind constructor_kind) { m_constructor_kind = constructor_kind; }
  30. virtual bool is_strict_mode() const { return false; }
  31. protected:
  32. virtual void visit_edges(Visitor&) override;
  33. explicit Function(Object& prototype);
  34. Function(Object& prototype, Value bound_this, Vector<Value> bound_arguments);
  35. private:
  36. virtual bool is_function() const override { return true; }
  37. Value m_bound_this;
  38. Vector<Value> m_bound_arguments;
  39. Value m_home_object;
  40. ConstructorKind m_constructor_kind = ConstructorKind::Base;
  41. };
  42. }