LibWeb: Isolate WebAssembly cache by global object

This change moves WebAssembly related data that was previously globally
accessible into the `WebAssemblyCache` object and creates one of these
per global object. This ensures that WebAssembly data cannot be
accessed across realms.
This commit is contained in:
Tim Ledbetter 2024-04-25 19:09:34 +01:00 committed by Ali Mohammad Pur
parent 5e75afd549
commit 6d4b8bde55
Notes: sideshowbarker 2024-07-17 02:57:43 +09:00
9 changed files with 121 additions and 116 deletions

View file

@ -21,13 +21,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Module>> Module::construct_impl(JS::Realm&
{
auto& vm = realm.vm();
auto index = TRY(Detail::parse_module(vm, bytes->raw_object()));
return vm.heap().allocate<Module>(realm, realm, index);
auto compiled_module = TRY(Detail::parse_module(vm, bytes->raw_object()));
return vm.heap().allocate<Module>(realm, realm, move(compiled_module));
}
Module::Module(JS::Realm& realm, size_t index)
Module::Module(JS::Realm& realm, NonnullRefPtr<Detail::CompiledWebAssemblyModule> compiled_module)
: Bindings::PlatformObject(realm)
, m_index(index)
, m_compiled_module(move(compiled_module))
{
}
@ -37,9 +37,4 @@ void Module::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE_WITH_CUSTOM_NAME(Module, WebAssembly.Module);
}
Wasm::Module const& Module::module() const
{
return Detail::s_compiled_modules.at(index())->module;
}
}