mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-29 04:37:55 +00:00
LibWeb: Add WebAssembly.Global and exports support for global instances
This commit is contained in:
committed by
Ali Mohammad Pur
parent
910ff8b694
commit
44e3817219
@@ -11,6 +11,7 @@
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Bindings/InstancePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/WebAssembly/Global.h>
|
||||
#include <LibWeb/WebAssembly/Instance.h>
|
||||
#include <LibWeb/WebAssembly/Memory.h>
|
||||
#include <LibWeb/WebAssembly/Module.h>
|
||||
@@ -45,6 +46,9 @@ void Instance::initialize(JS::Realm& realm)
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE_WITH_CUSTOM_NAME(Instance, WebAssembly.Instance);
|
||||
|
||||
auto& cache = Detail::get_cache(realm);
|
||||
|
||||
// https://webassembly.github.io/spec/js-api/#create-an-exports-object
|
||||
for (auto& export_ : m_module_instance->exports()) {
|
||||
export_.value().visit(
|
||||
[&](Wasm::FunctionAddress const& address) {
|
||||
@@ -56,6 +60,14 @@ void Instance::initialize(JS::Realm& realm)
|
||||
|
||||
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
},
|
||||
[&](Wasm::GlobalAddress const& address) {
|
||||
Optional<GC::Ptr<Global>> object = cache.get_global_instance(address);
|
||||
if (!object.has_value()) {
|
||||
object = realm.create<Global>(realm, address);
|
||||
}
|
||||
|
||||
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
},
|
||||
[&](Wasm::MemoryAddress const& address) {
|
||||
Optional<GC::Ptr<Memory>> object = m_memory_instances.get(address);
|
||||
if (!object.has_value()) {
|
||||
@@ -73,9 +85,6 @@ void Instance::initialize(JS::Realm& realm)
|
||||
}
|
||||
|
||||
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||
},
|
||||
[&](auto const&) {
|
||||
// FIXME: Implement other exports!
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user