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
commit 6d4b8bde55
Notes: sideshowbarker 2024-07-17 02:57:43 +09:00
9 changed files with 121 additions and 116 deletions

View file

@ -11,8 +11,10 @@
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibJS/Heap/Handle.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/WebAssembly/WebAssembly.h>
namespace Web::WebAssembly {
@ -26,13 +28,16 @@ public:
Object const* exports() const { return m_exports.ptr(); }
private:
Instance(JS::Realm&, size_t index);
Instance(JS::Realm&, NonnullOwnPtr<Wasm::ModuleInstance>);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Visitor&) override;
JS::NonnullGCPtr<Object> m_exports;
size_t m_index { 0 };
NonnullOwnPtr<Wasm::ModuleInstance> m_module_instance;
HashMap<Wasm::FunctionAddress, JS::GCPtr<JS::FunctionObject>> m_function_instances;
HashMap<Wasm::MemoryAddress, JS::GCPtr<WebAssembly::Memory>> m_memory_instances;
HashMap<Wasm::TableAddress, JS::GCPtr<WebAssembly::Table>> m_table_instances;
};
}