Realm.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Heap/Cell.h>
  8. #include <LibJS/Runtime/GlobalEnvironment.h>
  9. #include <LibJS/Runtime/GlobalObject.h>
  10. namespace JS {
  11. // 9.3 Realms, https://tc39.es/ecma262/#realm-record
  12. class Realm final : public Cell {
  13. public:
  14. Realm() = default;
  15. // 9.3.1 CreateRealm ( ), https://tc39.es/ecma262/#sec-createrealm
  16. static Realm* create(VM& vm)
  17. {
  18. return vm.heap().allocate_without_global_object<Realm>();
  19. }
  20. void set_global_object(GlobalObject&, Object* this_value = nullptr);
  21. [[nodiscard]] GlobalObject& global_object() const { return *m_global_object; }
  22. [[nodiscard]] GlobalEnvironment& global_environment() const { return *m_global_environment; }
  23. private:
  24. virtual char const* class_name() const override { return "Realm"; }
  25. virtual void visit_edges(Visitor&) override;
  26. GlobalObject* m_global_object { nullptr }; // [[GlobalObject]]
  27. GlobalEnvironment* m_global_environment { nullptr }; // [[GlobalEnv]]
  28. };
  29. }