LibWeb: Remove data from WebAssembly cache when namespace is finalized

Previously, the cache held on to data for objects that had already been
garbage collected.
This commit is contained in:
Tim Ledbetter 2024-04-25 19:09:34 +01:00 committed by Ali Mohammad Pur
commit fcf1a2a287
Notes: sideshowbarker 2024-07-17 20:22:04 +09:00
3 changed files with 8 additions and 1 deletions

View file

@ -48,6 +48,12 @@ void visit_edges(JS::Object& object, JS::Cell::Visitor& visitor)
} }
} }
void finalize(JS::Object& object)
{
auto& global_object = HTML::relevant_global_object(object);
Detail::s_caches.remove(global_object);
}
// https://webassembly.github.io/spec/js-api/#dom-webassembly-validate // https://webassembly.github.io/spec/js-api/#dom-webassembly-validate
bool validate(JS::VM& vm, JS::Handle<WebIDL::BufferSource>& bytes) bool validate(JS::VM& vm, JS::Handle<WebIDL::BufferSource>& bytes)
{ {

View file

@ -19,6 +19,7 @@
namespace Web::WebAssembly { namespace Web::WebAssembly {
void visit_edges(JS::Object&, JS::Cell::Visitor&); void visit_edges(JS::Object&, JS::Cell::Visitor&);
void finalize(JS::Object&);
bool validate(JS::VM&, JS::Handle<WebIDL::BufferSource>& bytes); bool validate(JS::VM&, JS::Handle<WebIDL::BufferSource>& bytes);
WebIDL::ExceptionOr<JS::Value> compile(JS::VM&, JS::Handle<WebIDL::BufferSource>& bytes); WebIDL::ExceptionOr<JS::Value> compile(JS::VM&, JS::Handle<WebIDL::BufferSource>& bytes);

View file

@ -7,7 +7,7 @@ dictionary WebAssemblyInstantiatedSource {
}; };
// https://webassembly.github.io/spec/js-api/#webassembly-namespace // https://webassembly.github.io/spec/js-api/#webassembly-namespace
[Exposed=*, WithGCVisitor] [Exposed=*, WithGCVisitor, WithFinalizer]
namespace WebAssembly { namespace WebAssembly {
boolean validate(BufferSource bytes); boolean validate(BufferSource bytes);
Promise<Module> compile(BufferSource bytes); Promise<Module> compile(BufferSource bytes);