1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 01:54:57 +00:00

LibWasm: Port the parser to Core::Stream

This commit is contained in:
Tim Schumacher 2023-01-21 11:44:19 +01:00 committed by Ali Mohammad Pur
parent 409fb0fe79
commit 982ebbc304
6 changed files with 292 additions and 263 deletions

View file

@ -12,6 +12,7 @@
#include "WebAssemblyTableObject.h"
#include "WebAssemblyTablePrototype.h"
#include <AK/ScopeGuard.h>
#include <LibCore/MemoryStream.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/BigInt.h>
@ -118,13 +119,8 @@ JS::ThrowCompletionOr<size_t> parse_module(JS::VM& vm, JS::Object* buffer_object
} else {
return vm.throw_completion<JS::TypeError>("Not a BufferSource");
}
InputMemoryStream stream { data };
auto module_result = Wasm::Module::parse(stream);
ScopeGuard drain_errors {
[&] {
stream.handle_any_error();
}
};
auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors();
auto module_result = Wasm::Module::parse(*stream);
if (module_result.is_error()) {
// FIXME: Throw CompileError instead.
return vm.throw_completion<JS::TypeError>(Wasm::parse_error_to_deprecated_string(module_result.error()));