mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:47:46 +00:00
Tests: Port test-wasm to Core::Stream
This commit is contained in:
parent
aca28f00de
commit
7ff99c3972
1 changed files with 13 additions and 5 deletions
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/Stream.h>
|
||||||
#include <LibTest/JavaScriptTestRunner.h>
|
#include <LibTest/JavaScriptTestRunner.h>
|
||||||
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
|
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
|
||||||
#include <LibWasm/Types.h>
|
#include <LibWasm/Types.h>
|
||||||
|
@ -15,12 +15,20 @@ TEST_ROOT("Userland/Libraries/LibWasm/Tests");
|
||||||
TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile)
|
TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile)
|
||||||
{
|
{
|
||||||
auto filename = TRY(vm.argument(0).to_string(global_object));
|
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())
|
if (file.is_error())
|
||||||
return vm.throw_completion<JS::TypeError>(global_object, strerror(file.error().code()));
|
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()));
|
auto file_size = file.value()->size();
|
||||||
contents.span().copy_to(array->data());
|
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);
|
return JS::Value(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue