Module.h 908 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Heap/Handle.h>
  8. #include <LibJS/Runtime/Realm.h>
  9. namespace JS {
  10. // 16.2.1.4 Abstract Module Records, https://tc39.es/ecma262/#sec-abstract-module-records
  11. class Module : public RefCounted<Module> {
  12. public:
  13. virtual ~Module();
  14. Realm& realm() { return *m_realm.cell(); }
  15. Realm const& realm() const { return *m_realm.cell(); }
  16. Environment* environment() { return m_environment.cell(); }
  17. Object* namespace_() { return m_namespace.cell(); }
  18. protected:
  19. explicit Module(Realm&);
  20. private:
  21. // Handles are not safe unless we keep the VM alive.
  22. NonnullRefPtr<VM> m_vm;
  23. Handle<Realm> m_realm; // [[Realm]]
  24. Handle<Environment> m_environment; // [[Environment]]
  25. Handle<Object> m_namespace; // [[Namespace]]
  26. };
  27. }