diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2023-04-26 20:44:50 -0400 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2023-05-27 06:48:25 -0600 |
commit | e78d1ec03a5c5a8b5945fd41016b8931b9de38c2 (patch) | |
tree | 115170b3c0a8557beac15d3767688679caa1639a /Userland/Libraries/LibJS/Runtime | |
parent | edbc7327855314d8ead724c65c2b1bbebd87e438 (diff) | |
download | serenity-e78d1ec03a5c5a8b5945fd41016b8931b9de38c2.zip |
LibJS/Runtime: Use `Core::File` in `VM::resolve_imported_module`
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/VM.cpp | 13 |
1 files 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<NonnullGCPtr<Module>> 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<SyntaxError>(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<JS::InternalError>(error_message(::JS::VM::ErrorMessage::OutOfMemory)); + return throw_completion<SyntaxError>(ErrorType::ModuleNotFound, module_request.module_specifier); + } + + StringView const content_view { file_content_or_error.value().bytes() }; auto module = TRY([&]() -> ThrowCompletionOr<NonnullGCPtr<Module>> { // If assertions has an entry entry such that entry.[[Key]] is "type", let type be entry.[[Value]]. The following requirements apply: |