mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:08:12 +00:00
LibWasm: Port the parser to Core::Stream
This commit is contained in:
parent
409fb0fe79
commit
982ebbc304
6 changed files with 292 additions and 263 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/MemoryStream.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibTest/JavaScriptTestRunner.h>
|
||||
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
|
||||
|
@ -105,19 +106,11 @@ TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
|
|||
if (!is<JS::Uint8Array>(object))
|
||||
return vm.throw_completion<JS::TypeError>("Expected a Uint8Array argument to parse_webassembly_module");
|
||||
auto& array = static_cast<JS::Uint8Array&>(*object);
|
||||
InputMemoryStream stream { array.data() };
|
||||
ScopeGuard handle_stream_error {
|
||||
[&] {
|
||||
stream.handle_any_error();
|
||||
}
|
||||
};
|
||||
auto result = Wasm::Module::parse(stream);
|
||||
auto stream = Core::Stream::FixedMemoryStream::construct(array.data()).release_value_but_fixme_should_propagate_errors();
|
||||
auto result = Wasm::Module::parse(*stream);
|
||||
if (result.is_error())
|
||||
return vm.throw_completion<JS::SyntaxError>(Wasm::parse_error_to_deprecated_string(result.error()));
|
||||
|
||||
if (stream.handle_any_error())
|
||||
return vm.throw_completion<JS::SyntaxError>("Binary stream contained errors");
|
||||
|
||||
HashMap<Wasm::Linker::Name, Wasm::ExternValue> imports;
|
||||
auto import_value = vm.argument(1);
|
||||
if (import_value.is_object()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue