summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-03-10 16:20:40 +0000
committerTim Flynn <trflynn89@pm.me>2022-03-10 12:04:22 -0500
commit7ff99c397219abe2354971c847efe7052b0558ca (patch)
treecf3404235432224fc62def86bc96d4c6219cc37b /Tests
parentaca28f00deba672c02fdb8732f10763e198b1cfc (diff)
downloadserenity-7ff99c397219abe2354971c847efe7052b0558ca.zip
Tests: Port test-wasm to Core::Stream
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibWasm/test-wasm.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp
index 926ddfdabe..f6e14a7d9e 100644
--- a/Tests/LibWasm/test-wasm.cpp
+++ b/Tests/LibWasm/test-wasm.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibCore/File.h>
+#include <LibCore/Stream.h>
#include <LibTest/JavaScriptTestRunner.h>
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
#include <LibWasm/Types.h>
@@ -15,12 +15,20 @@ TEST_ROOT("Userland/Libraries/LibWasm/Tests");
TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile)
{
auto filename = TRY(vm.argument(0).to_string(global_object));
- auto file = Core::File::open(filename, Core::OpenMode::ReadOnly);
+ auto file = Core::Stream::File::open(filename, Core::Stream::OpenMode::Read);
if (file.is_error())
return vm.throw_completion<JS::TypeError>(global_object, strerror(file.error().code()));
- auto contents = file.value()->read_all();
- auto* array = TRY(JS::Uint8Array::create(global_object, contents.size()));
- contents.span().copy_to(array->data());
+
+ auto file_size = file.value()->size();
+ if (file_size.is_error())
+ return vm.throw_completion<JS::TypeError>(global_object, strerror(file_size.error().code()));
+
+ auto* array = TRY(JS::Uint8Array::create(global_object, file_size.value()));
+
+ auto read = file.value()->read(array->data());
+ if (read.is_error())
+ return vm.throw_completion<JS::TypeError>(global_object, strerror(read.error().code()));
+
return JS::Value(array);
}