From 99662975eddbd8f6d37eb32506e7f0cfdd7ab577 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 20 Jul 2021 17:53:48 +0100 Subject: [PATCH] LibJS: Partially revert e3fa32b This was causing some syntactically wrong inputs to crash and subsequently broke CI (test262 parser tests). --- Userland/Libraries/LibJS/Parser.h | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/Userland/Libraries/LibJS/Parser.h b/Userland/Libraries/LibJS/Parser.h index f0bb76d0ca..a34a059357 100644 --- a/Userland/Libraries/LibJS/Parser.h +++ b/Userland/Libraries/LibJS/Parser.h @@ -107,26 +107,15 @@ public: { if (!position.has_value()) return {}; - - StringBuilder builder; + // We need to modify the source to match what the lexer considers one line - normalizing + // line terminators to \n is easier than splitting using all different LT characters. String source_string { source }; - GenericLexer lexer(source_string); - // Skip to the line we want - size_t current_line = 0; - while (current_line < position.value().line - 1) { - if (lexer.consume_specific("\n") || lexer.consume_specific("\r\n") || lexer.consume_specific(LINE_SEPARATOR) || lexer.consume_specific(PARAGRAPH_SEPARATOR)) - current_line++; - else - lexer.ignore(); - VERIFY(!lexer.is_eof()); - } - // We are at the line, now add the chars to the string - while (!lexer.is_eof()) { - if (lexer.consume_specific("\n") || lexer.consume_specific("\r\n") || lexer.consume_specific(LINE_SEPARATOR) || lexer.consume_specific(PARAGRAPH_SEPARATOR)) - break; - else - builder.append(lexer.consume()); - } + source_string.replace("\r\n", "\n"); + source_string.replace("\r", "\n"); + source_string.replace(LINE_SEPARATOR, "\n"); + source_string.replace(PARAGRAPH_SEPARATOR, "\n"); + StringBuilder builder; + builder.append(source_string.split_view('\n', true)[position.value().line - 1]); builder.append('\n'); for (size_t i = 0; i < position.value().column - 1; ++i) builder.append(spacer);