summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Heap
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-08-16 00:20:49 +0100
committerLinus Groh <mail@linusgroh.de>2022-08-23 13:58:30 +0100
commit5dd5896588b0e5a7bc7bdadeaa7dd4865f663b79 (patch)
treeb8c099aac88ad59a9fb06624fd6245f9662a9796 /Userland/Libraries/LibJS/Heap
parentecd163bdf1cbf8c9bca9e209a385a41ff5ca4f81 (diff)
downloadserenity-5dd5896588b0e5a7bc7bdadeaa7dd4865f663b79.zip
LibJS+LibWeb: Replace GlobalObject with Realm in initialize() functions
This is a continuation of the previous commit. Calling initialize() is the first thing that's done after allocating a cell on the JS heap - and in the common case of allocating an object, that's where properties are assigned and intrinsics occasionally accessed. Since those are supposed to live on the realm eventually, this is another step into that direction.
Diffstat (limited to 'Userland/Libraries/LibJS/Heap')
-rw-r--r--Userland/Libraries/LibJS/Heap/Cell.h2
-rw-r--r--Userland/Libraries/LibJS/Heap/Heap.cpp7
-rw-r--r--Userland/Libraries/LibJS/Heap/Heap.h5
3 files changed, 12 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Heap/Cell.h b/Userland/Libraries/LibJS/Heap/Cell.h
index b03f0dd960..b467af79be 100644
--- a/Userland/Libraries/LibJS/Heap/Cell.h
+++ b/Userland/Libraries/LibJS/Heap/Cell.h
@@ -19,7 +19,7 @@ class Cell {
AK_MAKE_NONMOVABLE(Cell);
public:
- virtual void initialize(GlobalObject&) { }
+ virtual void initialize(Realm&) { }
virtual ~Cell() = default;
bool is_marked() const { return m_mark; }
diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp
index 1fef87d439..53bcc1de4b 100644
--- a/Userland/Libraries/LibJS/Heap/Heap.cpp
+++ b/Userland/Libraries/LibJS/Heap/Heap.cpp
@@ -349,4 +349,11 @@ void Heap::uproot_cell(Cell* cell)
m_uprooted_cells.append(cell);
}
+// Temporary helper function as we can't pass a realm directly until Heap::allocate<T>() receives one.
+// Heap.h only has a forward declaration of the GlobalObject, so no inlined member access possible.
+Realm& realm_from_global_object(GlobalObject& global_object)
+{
+ return *global_object.associated_realm();
+}
+
}
diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h
index 752a2a97d8..110109860c 100644
--- a/Userland/Libraries/LibJS/Heap/Heap.h
+++ b/Userland/Libraries/LibJS/Heap/Heap.h
@@ -25,6 +25,8 @@
namespace JS {
+Realm& realm_from_global_object(GlobalObject&);
+
class Heap {
AK_MAKE_NONCOPYABLE(Heap);
AK_MAKE_NONMOVABLE(Heap);
@@ -47,7 +49,8 @@ public:
auto* memory = allocate_cell(sizeof(T));
new (memory) T(forward<Args>(args)...);
auto* cell = static_cast<T*>(memory);
- cell->initialize(global_object);
+ auto& realm = realm_from_global_object(global_object);
+ memory->initialize(realm);
return cell;
}