diff options
author | Linus Groh <mail@linusgroh.de> | 2021-09-11 19:20:07 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-12 11:10:20 +0100 |
commit | d9c3bafcd9997ef49925af13dca2c9db3a13df44 (patch) | |
tree | a1043d38d7767e0e70b9ac7b5b19fe0431f510df /Userland/Libraries | |
parent | 8d0dbdeaac4fa1d38ce9b1c467fc3865fb3685e2 (diff) | |
download | serenity-d9c3bafcd9997ef49925af13dca2c9db3a13df44.zip |
LibJS: Start adding a JS::Realm class (spec's "Realm Record")
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Forward.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Realm.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Realm.h | 37 |
4 files changed, 56 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index a2585a6479..1bbccd8d89 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -116,6 +116,7 @@ set(SOURCES Runtime/PropertyDescriptor.cpp Runtime/ProxyConstructor.cpp Runtime/ProxyObject.cpp + Runtime/Realm.cpp Runtime/Reference.cpp Runtime/ReflectObject.cpp Runtime/RegExpConstructor.cpp diff --git a/Userland/Libraries/LibJS/Forward.h b/Userland/Libraries/LibJS/Forward.h index 234456b15b..11458da86f 100644 --- a/Userland/Libraries/LibJS/Forward.h +++ b/Userland/Libraries/LibJS/Forward.h @@ -167,6 +167,7 @@ class PromiseResolveThenableJob; class PropertyAttributes; class PropertyDescriptor; class PropertyName; +class Realm; class Reference; class ScopeNode; class Shape; diff --git a/Userland/Libraries/LibJS/Runtime/Realm.cpp b/Userland/Libraries/LibJS/Runtime/Realm.cpp new file mode 100644 index 0000000000..7d832905f5 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Realm.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibJS/Runtime/Realm.h> + +namespace JS { + +void Realm::visit_edges(Visitor& visitor) +{ + visitor.visit(m_global_object); + visitor.visit(m_global_environment); +} + +} diff --git a/Userland/Libraries/LibJS/Runtime/Realm.h b/Userland/Libraries/LibJS/Runtime/Realm.h new file mode 100644 index 0000000000..56571729cf --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Realm.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibJS/Heap/Cell.h> +#include <LibJS/Runtime/GlobalEnvironment.h> +#include <LibJS/Runtime/GlobalObject.h> + +namespace JS { + +// 9.3 Realms, https://tc39.es/ecma262/#realm-record +class Realm final : public Cell { +public: + Realm() = default; + + // 9.3.1 CreateRealm ( ), https://tc39.es/ecma262/#sec-createrealm + static Realm* create(VM& vm) + { + return vm.heap().allocate_without_global_object<Realm>(); + } + + [[nodiscard]] GlobalObject& global_object() const { return *m_global_object; } + [[nodiscard]] GlobalEnvironment& global_environment() const { return *m_global_environment; } + +private: + virtual char const* class_name() const override { return "Realm"; } + virtual void visit_edges(Visitor&) override; + + GlobalObject* m_global_object { nullptr }; // [[GlobalObject]] + GlobalEnvironment* m_global_environment { nullptr }; // [[GlobalEnv]] +}; + +} |