Realm.h 1.1 KB

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