mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-06 10:22:57 +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
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
|
@ -95,6 +96,29 @@ WebIDL::ExceptionOr<Vector<ModuleExportDescriptor>> Module::exports(JS::VM&, GC:
|
|||
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)
|
||||
: Bindings::PlatformObject(realm)
|
||||
, m_compiled_module(move(compiled_module))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue