mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
LibJS: Start adding a JS::Realm class (spec's "Realm Record")
This commit is contained in:
parent
8d0dbdeaac
commit
d9c3bafcd9
4 changed files with 56 additions and 0 deletions
|
@ -116,6 +116,7 @@ set(SOURCES
|
||||||
Runtime/PropertyDescriptor.cpp
|
Runtime/PropertyDescriptor.cpp
|
||||||
Runtime/ProxyConstructor.cpp
|
Runtime/ProxyConstructor.cpp
|
||||||
Runtime/ProxyObject.cpp
|
Runtime/ProxyObject.cpp
|
||||||
|
Runtime/Realm.cpp
|
||||||
Runtime/Reference.cpp
|
Runtime/Reference.cpp
|
||||||
Runtime/ReflectObject.cpp
|
Runtime/ReflectObject.cpp
|
||||||
Runtime/RegExpConstructor.cpp
|
Runtime/RegExpConstructor.cpp
|
||||||
|
|
|
@ -167,6 +167,7 @@ class PromiseResolveThenableJob;
|
||||||
class PropertyAttributes;
|
class PropertyAttributes;
|
||||||
class PropertyDescriptor;
|
class PropertyDescriptor;
|
||||||
class PropertyName;
|
class PropertyName;
|
||||||
|
class Realm;
|
||||||
class Reference;
|
class Reference;
|
||||||
class ScopeNode;
|
class ScopeNode;
|
||||||
class Shape;
|
class Shape;
|
||||||
|
|
17
Userland/Libraries/LibJS/Runtime/Realm.cpp
Normal file
17
Userland/Libraries/LibJS/Runtime/Realm.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
Userland/Libraries/LibJS/Runtime/Realm.h
Normal file
37
Userland/Libraries/LibJS/Runtime/Realm.h
Normal file
|
@ -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]]
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue