LibJS+LibWeb: Use realm.create<T> instead of heap.allocate<T>

The main motivation behind this is to remove JS specifics of the Realm
from the implementation of the Heap.

As a side effect of this change, this is a bit nicer to read than the
previous approach, and in my opinion, also makes it a little more clear
that this method is specific to a JavaScript Realm.
This commit is contained in:
Shannon Booth 2024-11-14 05:50:17 +13:00 committed by Tim Flynn
parent 2a5dbedad4
commit 9b79a686eb
Notes: github-actions[bot] 2024-11-13 21:52:48 +00:00
326 changed files with 697 additions and 714 deletions

View file

@ -147,7 +147,7 @@ ThrowCompletionOr<Object*> Module::get_module_namespace(VM& vm)
}
// d. Set namespace to ModuleNamespaceCreate(module, unambiguousNames).
namespace_ = module_namespace_create(vm, unambiguous_names);
namespace_ = module_namespace_create(unambiguous_names);
VERIFY(m_namespace);
// Note: This set the local variable 'namespace' and not the member variable which is done by ModuleNamespaceCreate
}
@ -157,7 +157,7 @@ ThrowCompletionOr<Object*> Module::get_module_namespace(VM& vm)
}
// 10.4.6.12 ModuleNamespaceCreate ( module, exports ), https://tc39.es/ecma262/#sec-modulenamespacecreate
Object* Module::module_namespace_create(VM& vm, Vector<DeprecatedFlyString> unambiguous_names)
Object* Module::module_namespace_create(Vector<DeprecatedFlyString> unambiguous_names)
{
auto& realm = this->realm();
@ -171,7 +171,7 @@ Object* Module::module_namespace_create(VM& vm, Vector<DeprecatedFlyString> unam
// 6. Let sortedExports be a List whose elements are the elements of exports ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using undefined as comparefn.
// 7. Set M.[[Exports]] to sortedExports.
// 8. Create own properties of M corresponding to the definitions in 28.3.
auto module_namespace = vm.heap().allocate<ModuleNamespaceObject>(realm, realm, this, move(unambiguous_names));
auto module_namespace = realm.create<ModuleNamespaceObject>(realm, this, move(unambiguous_names));
// 9. Set module.[[Namespace]] to M.
m_namespace = make_handle(module_namespace);