From 3cc7118bf4a024ecb6a57c5c650956d26f1a594a Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 1 Nov 2024 10:17:42 -0400 Subject: [PATCH] LibWeb: Insert newlines around WebDriver scripts This allows the script to end with a comment, which is tested by WPT. Otherwise, an ending comment would create a function of the form: function() { return 1; // comment } And the script would fail to parse. --- Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp index f6314a40c97..6f58b1d020a 100644 --- a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp @@ -268,7 +268,12 @@ JS::ThrowCompletionOr execute_a_function_body(HTML::Window const& win if (environment_override_object) scope = JS::new_object_environment(*environment_override_object, true, &global_scope); - auto source_text = ByteString::formatted("function() {{ {} }}", body); + auto source_text = ByteString::formatted( + R"~~~(function() {{ + {} + }})~~~", + body); + auto parser = JS::Parser { JS::Lexer { source_text } }; auto function_expression = parser.parse_function_node();