mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:27:36 +00:00
LibWeb: Add support for accessing exported wasm table instances
This commit is contained in:
parent
0d1471e72f
commit
af511a64cd
3 changed files with 13 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <LibWeb/WebAssembly/WebAssemblyInstanceObject.h>
|
#include <LibWeb/WebAssembly/WebAssemblyInstanceObject.h>
|
||||||
#include <LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h>
|
#include <LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h>
|
||||||
#include <LibWeb/WebAssembly/WebAssemblyObject.h>
|
#include <LibWeb/WebAssembly/WebAssemblyObject.h>
|
||||||
|
#include <LibWeb/WebAssembly/WebAssemblyTableObject.h>
|
||||||
|
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
|
||||||
|
@ -51,6 +52,14 @@ void WebAssemblyInstanceObject::initialize(JS::Realm& realm)
|
||||||
}
|
}
|
||||||
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||||
},
|
},
|
||||||
|
[&](Wasm::TableAddress const& address) {
|
||||||
|
Optional<WebAssemblyTableObject*> object = cache.table_instances.get(address);
|
||||||
|
if (!object.has_value()) {
|
||||||
|
object = heap().allocate<Web::Bindings::WebAssemblyTableObject>(realm, realm, address);
|
||||||
|
cache.table_instances.set(address, *object);
|
||||||
|
}
|
||||||
|
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||||
|
},
|
||||||
[&](auto const&) {
|
[&](auto const&) {
|
||||||
// FIXME: Implement other exports!
|
// FIXME: Implement other exports!
|
||||||
});
|
});
|
||||||
|
|
|
@ -84,6 +84,8 @@ void WebAssemblyObject::visit_edges(Visitor& visitor)
|
||||||
visitor.visit(entry.value);
|
visitor.visit(entry.value);
|
||||||
for (auto& entry : module_cache.memory_instances)
|
for (auto& entry : module_cache.memory_instances)
|
||||||
visitor.visit(entry.value);
|
visitor.visit(entry.value);
|
||||||
|
for (auto& entry : module_cache.table_instances)
|
||||||
|
visitor.visit(entry.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
|
||||||
class WebAssemblyMemoryObject;
|
class WebAssemblyMemoryObject;
|
||||||
|
class WebAssemblyTableObject;
|
||||||
JS::ThrowCompletionOr<size_t> parse_module(JS::VM&, JS::Object* buffer);
|
JS::ThrowCompletionOr<size_t> parse_module(JS::VM&, JS::Object* buffer);
|
||||||
JS::NativeFunction* create_native_function(JS::VM&, Wasm::FunctionAddress address, String const& name);
|
JS::NativeFunction* create_native_function(JS::VM&, Wasm::FunctionAddress address, String const& name);
|
||||||
JS::Value to_js_value(JS::VM&, Wasm::Value& wasm_value);
|
JS::Value to_js_value(JS::VM&, Wasm::Value& wasm_value);
|
||||||
|
@ -47,6 +48,7 @@ public:
|
||||||
struct ModuleCache {
|
struct ModuleCache {
|
||||||
HashMap<Wasm::FunctionAddress, JS::FunctionObject*> function_instances;
|
HashMap<Wasm::FunctionAddress, JS::FunctionObject*> function_instances;
|
||||||
HashMap<Wasm::MemoryAddress, WebAssemblyMemoryObject*> memory_instances;
|
HashMap<Wasm::MemoryAddress, WebAssemblyMemoryObject*> memory_instances;
|
||||||
|
HashMap<Wasm::TableAddress, WebAssemblyTableObject*> table_instances;
|
||||||
};
|
};
|
||||||
struct GlobalModuleCache {
|
struct GlobalModuleCache {
|
||||||
HashMap<Wasm::FunctionAddress, JS::NativeFunction*> function_instances;
|
HashMap<Wasm::FunctionAddress, JS::NativeFunction*> function_instances;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue