diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 4752ec9e96..88640f7ed1 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -388,7 +388,7 @@ if (BUILD_LAGOM) list(REMOVE_ITEM LIBJS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibJS/SyntaxHighlighter.cpp") lagom_lib(JS js SOURCES ${LIBJS_SOURCES} ${LIBJS_SUBDIR_SOURCES} ${LIBJS_SUBSUBDIR_SOURCES} - LIBS m LagomCrypto LagomRegex LagomUnicode + LIBS m LagomCrypto LagomRegex LagomUnicode LagomTextCodec ) # Line diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 622d0f3f22..d6026c07ec 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -122,7 +122,7 @@ target_link_libraries(ifconfig LibMain) target_link_libraries(ini LibMain) target_link_libraries(install-bin LibMain) target_link_libraries(jp LibMain) -target_link_libraries(js LibJS LibLine LibMain) +target_link_libraries(js LibJS LibLine LibMain LibTextCodec) link_with_unicode_data(js) target_link_libraries(kcov-example LibMain) target_link_libraries(keymap LibKeyboard LibMain) diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 961b6e5449..56f0a306aa 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -71,6 +71,7 @@ #include #include #include +#include #include #include #include @@ -1653,7 +1654,16 @@ ErrorOr serenity_main(Main::Arguments arguments) auto file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly)); auto file_contents = file->read_all(); auto source = StringView { file_contents }; - builder.append(source); + + if (Utf8View { file_contents }.validate()) { + builder.append(source); + } else { + auto* decoder = TextCodec::decoder_for("windows-1252"); + VERIFY(decoder); + + auto utf8_source = TextCodec::convert_input_to_utf8_using_given_decoder_unless_there_is_a_byte_order_mark(*decoder, source); + builder.append(utf8_source); + } } source_name = script_paths[0];