diff options
author | Linus Groh <mail@linusgroh.de> | 2022-08-16 00:20:49 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-23 13:58:30 +0100 |
commit | 5dd5896588b0e5a7bc7bdadeaa7dd4865f663b79 (patch) | |
tree | b8c099aac88ad59a9fb06624fd6245f9662a9796 /Userland/Libraries/LibJS/Heap | |
parent | ecd163bdf1cbf8c9bca9e209a385a41ff5ca4f81 (diff) | |
download | serenity-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.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Heap/Heap.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Heap/Heap.h | 5 |
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; } |