mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
LibTest: Port JavaScriptTestRunner to Core::Stream
This commit is contained in:
parent
82605e2dff
commit
cc874f2b82
1 changed files with 13 additions and 6 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <AK/Tuple.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Lexer.h>
|
||||
|
@ -210,14 +211,20 @@ inline void TestRunnerGlobalObject::initialize_global_object()
|
|||
|
||||
inline ByteBuffer load_entire_file(StringView path)
|
||||
{
|
||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Failed to open the following file: \"{}\"", path);
|
||||
auto try_load_entire_file = [](StringView const& path) -> ErrorOr<ByteBuffer> {
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
auto file_size = TRY(file->size());
|
||||
auto content = TRY(ByteBuffer::create_uninitialized(file_size));
|
||||
TRY(file->read(content.bytes()));
|
||||
return content;
|
||||
};
|
||||
|
||||
auto buffer_or_error = try_load_entire_file(path);
|
||||
if (buffer_or_error.is_error()) {
|
||||
warnln("Failed to open the following file: \"{}\", error: {}", path, buffer_or_error.release_error());
|
||||
cleanup_and_exit();
|
||||
}
|
||||
|
||||
auto file = file_or_error.release_value();
|
||||
return file->read_all();
|
||||
return buffer_or_error.release_value();
|
||||
}
|
||||
|
||||
inline AK::Result<NonnullRefPtr<JS::Script>, ParserError> parse_script(StringView path, JS::Realm& realm)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue