LibWeb: Implement the WebAssembly "Memory object cache" + other changes

This cache is referenced by a few parts of the JS API spec, including
the threads spec (such as in toFixedLengthBuffer), as well as the
"refresh the Memory buffer" algorithm, which was implemented as a method
of Memory before this change.

Now, this algorithm can be implemented in a spec-like fashion (though it
mostly seems to add extra complexity). This change also fixes a bug
where memories that were re-exported from an imported WebAssembly.Memory
were given a distinct WebAssembly.Memory object, since the caching that
existed in Instance.cpp was instance-local, not global to the realm.

We also make Memory::m_buffer non-lazy, since we have to implement
"initialize a memory object" correctly anyway.
This commit is contained in:
CountBleck 2025-08-18 21:13:58 -07:00 committed by Ali Mohammad Pur
commit f2a170bcfb
Notes: github-actions[bot] 2025-08-23 06:27:54 +00:00
6 changed files with 55 additions and 33 deletions

View file

@ -63,6 +63,7 @@ void visit_edges(JS::Object& object, JS::Cell::Visitor& visitor)
visitor.visit(cache.imported_objects());
visitor.visit(cache.extern_values());
visitor.visit(cache.global_instances());
visitor.visit(cache.memory_instances());
cache.abstract_machine().visit_external_resources({ .visit_trap = [&visitor](Wasm::ExternallyManagedTrap const& trap) {
auto& completion = trap.unsafe_external_object_as<JS::Completion>();
visitor.visit(completion.value());