1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:07:34 +00:00

LibCore: Use ErrorOr<T> for Core::File::open()

This commit is contained in:
Andreas Kling 2021-11-07 02:15:10 +01:00
parent fac2550143
commit a7f1f1c34b
24 changed files with 42 additions and 48 deletions

View file

@ -8,6 +8,7 @@
#include <LibTest/JavaScriptTestRunner.h>
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
#include <LibWasm/Types.h>
#include <string.h>
TEST_ROOT("Userland/Libraries/LibWasm/Tests");
@ -16,7 +17,7 @@ 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);
if (file.is_error())
return vm.throw_completion<JS::TypeError>(global_object, file.error().string());
return vm.throw_completion<JS::TypeError>(global_object, strerror(file.error().code()));
auto contents = file.value()->read_all();
auto array = JS::Uint8Array::create(global_object, contents.size());
contents.span().copy_to(array->data());