ScopeObject.h 895 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/Object.h>
  8. namespace JS {
  9. struct Variable {
  10. Value value;
  11. DeclarationKind declaration_kind;
  12. };
  13. class ScopeObject : public Object {
  14. JS_OBJECT(ScopeObject, Object);
  15. public:
  16. virtual Optional<Variable> get_from_scope(const FlyString&) const = 0;
  17. virtual void put_to_scope(const FlyString&, Variable) = 0;
  18. virtual bool has_this_binding() const = 0;
  19. virtual Value get_this_binding(GlobalObject&) const = 0;
  20. ScopeObject* parent() { return m_parent; }
  21. const ScopeObject* parent() const { return m_parent; }
  22. protected:
  23. explicit ScopeObject(ScopeObject* parent);
  24. explicit ScopeObject(GlobalObjectTag);
  25. virtual void visit_edges(Visitor&) override;
  26. private:
  27. ScopeObject* m_parent { nullptr };
  28. };
  29. }