mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 08:39:22 +00:00
LibWeb/WebAssembly: Implement Module::customSections(module)
This commit is contained in:
parent
f341bb0522
commit
a786269687
Notes:
github-actions[bot]
2025-04-22 14:44:52 +00:00
Author: https://github.com/alimpfard
Commit: a786269687
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4423
Reviewed-by: https://github.com/ADKaster ✅
3 changed files with 26 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||||
#include <LibJS/Runtime/Realm.h>
|
#include <LibJS/Runtime/Realm.h>
|
||||||
#include <LibJS/Runtime/VM.h>
|
#include <LibJS/Runtime/VM.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
@ -95,6 +96,29 @@ WebIDL::ExceptionOr<Vector<ModuleExportDescriptor>> Module::exports(JS::VM&, GC:
|
||||||
return export_objects;
|
return export_objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://webassembly.github.io/threads/js-api/index.html#dom-module-customsections
|
||||||
|
WebIDL::ExceptionOr<GC::RootVector<GC::Ref<JS::ArrayBuffer>>> Module::custom_sections(JS::VM& vm, GC::Ref<Module> module_object, String section_name)
|
||||||
|
{
|
||||||
|
// 1. Let bytes be moduleObject.[[Bytes]].
|
||||||
|
// 2. Let customSections be « ».
|
||||||
|
GC::RootVector<GC::Ref<JS::ArrayBuffer>> array_buffers { vm.heap() };
|
||||||
|
|
||||||
|
// 3. For each custom section customSection of bytes, interpreted according to the module grammar,
|
||||||
|
auto& custom_sections = module_object->m_compiled_module->module->custom_sections();
|
||||||
|
for (auto& section : custom_sections) {
|
||||||
|
// 3.1. Let name be the name of customSection, decoded as UTF-8.
|
||||||
|
// 3.2. Assert: name is not failure (moduleObject.[[Module]] is valid).
|
||||||
|
auto name = MUST(String::from_utf8(section.name().bytes()));
|
||||||
|
// 3.3. If name equals sectionName as string values,
|
||||||
|
if (section_name == name) {
|
||||||
|
// 3.3.1. Append a new ArrayBuffer containing a copy of the bytes in bytes for the range matched by this customsec production to customSections.
|
||||||
|
array_buffers.append(JS::ArrayBuffer::create(module_object->realm(), section.contents()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 4. Return customSections.
|
||||||
|
return array_buffers;
|
||||||
|
}
|
||||||
|
|
||||||
Module::Module(JS::Realm& realm, NonnullRefPtr<Detail::CompiledWebAssemblyModule> compiled_module)
|
Module::Module(JS::Realm& realm, NonnullRefPtr<Detail::CompiledWebAssemblyModule> compiled_module)
|
||||||
: Bindings::PlatformObject(realm)
|
: Bindings::PlatformObject(realm)
|
||||||
, m_compiled_module(move(compiled_module))
|
, m_compiled_module(move(compiled_module))
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
static WebIDL::ExceptionOr<GC::Ref<Module>> construct_impl(JS::Realm&, GC::Root<WebIDL::BufferSource>& bytes);
|
static WebIDL::ExceptionOr<GC::Ref<Module>> construct_impl(JS::Realm&, GC::Root<WebIDL::BufferSource>& bytes);
|
||||||
static WebIDL::ExceptionOr<Vector<ModuleImportDescriptor>> imports(JS::VM&, GC::Ref<Module>);
|
static WebIDL::ExceptionOr<Vector<ModuleImportDescriptor>> imports(JS::VM&, GC::Ref<Module>);
|
||||||
static WebIDL::ExceptionOr<Vector<ModuleExportDescriptor>> exports(JS::VM&, GC::Ref<Module>);
|
static WebIDL::ExceptionOr<Vector<ModuleExportDescriptor>> exports(JS::VM&, GC::Ref<Module>);
|
||||||
|
static WebIDL::ExceptionOr<GC::RootVector<GC::Ref<JS::ArrayBuffer>>> custom_sections(JS::VM&, GC::Ref<Module>, String section_name);
|
||||||
|
|
||||||
NonnullRefPtr<Detail::CompiledWebAssemblyModule> compiled_module() const { return m_compiled_module; }
|
NonnullRefPtr<Detail::CompiledWebAssemblyModule> compiled_module() const { return m_compiled_module; }
|
||||||
|
|
||||||
|
|
|
@ -23,5 +23,5 @@ interface Module {
|
||||||
|
|
||||||
static sequence<ModuleExportDescriptor> exports(Module moduleObject);
|
static sequence<ModuleExportDescriptor> exports(Module moduleObject);
|
||||||
static sequence<ModuleImportDescriptor> imports(Module moduleObject);
|
static sequence<ModuleImportDescriptor> imports(Module moduleObject);
|
||||||
[FIXME] static sequence<ArrayBuffer> customSections(Module moduleObject, DOMString sectionName);
|
static sequence<ArrayBuffer> customSections(Module moduleObject, DOMString sectionName);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue