From e78d1ec03a5c5a8b5945fd41016b8931b9de38c2 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Wed, 26 Apr 2023 20:44:50 -0400 Subject: LibJS/Runtime: Use `Core::File` in `VM::resolve_imported_module` --- Userland/Libraries/LibJS/Runtime/VM.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 7a7d244405..79d660539c 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -938,15 +938,22 @@ ThrowCompletionOr> VM::resolve_imported_module(ScriptOrModu dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] reading and parsing module {}", filename); - auto file_or_error = Core::DeprecatedFile::open(filename, Core::OpenMode::ReadOnly); + auto file_or_error = Core::File::open(filename, Core::File::OpenMode::Read); if (file_or_error.is_error()) { return throw_completion(ErrorType::ModuleNotFound, module_request.module_specifier); } // FIXME: Don't read the file in one go. - auto file_content = file_or_error.value()->read_all(); - StringView content_view { file_content.data(), file_content.size() }; + auto file_content_or_error = file_or_error.value()->read_until_eof(); + + if (file_content_or_error.is_error()) { + if (file_content_or_error.error().code() == ENOMEM) + return throw_completion(error_message(::JS::VM::ErrorMessage::OutOfMemory)); + return throw_completion(ErrorType::ModuleNotFound, module_request.module_specifier); + } + + StringView const content_view { file_content_or_error.value().bytes() }; auto module = TRY([&]() -> ThrowCompletionOr> { // If assertions has an entry entry such that entry.[[Key]] is "type", let type be entry.[[Value]]. The following requirements apply: -- cgit v1.2.3