mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Add WebAssembly.Global and exports support for global instances
This commit is contained in:
parent
910ff8b694
commit
44e3817219
Notes:
github-actions[bot]
2024-12-24 14:21:40 +00:00
Author: https://github.com/ADKaster
Commit: 44e3817219
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3028
10 changed files with 268 additions and 4 deletions
|
@ -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!
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue