From e96451edc936e102315bc47f1c3c48dc3a9caf0a Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 12 May 2021 07:13:12 -0600 Subject: [PATCH] Tests: Don't use TestRunners after their scope ends in test-js The TestRunner objects at the end of test-js are destroyed after the if/else that chooses whether to run the 262 parser tests or the standard tests. Accessing TestRunner::the() after the lifetime of the TestRunners ends is UB, so return the Test::Counts from run() instead. Also, fix the destructor of TestRunner to set s_the to nullptr so that if anyone tries this type of shenanigains again, they'll get a crash :^). --- Tests/LibJS/test-js.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Tests/LibJS/test-js.cpp b/Tests/LibJS/test-js.cpp index 5fffce5831..095e927584 100644 --- a/Tests/LibJS/test-js.cpp +++ b/Tests/LibJS/test-js.cpp @@ -79,9 +79,9 @@ public: s_the = this; } - virtual ~TestRunner() = default; + virtual ~TestRunner() { s_the = nullptr; }; - void run(); + Test::Counts run(); const Test::Counts& counts() const { return m_counts; } @@ -197,7 +197,7 @@ Vector TestRunner::get_test_paths() const return paths; } -void TestRunner::run() +Test::Counts TestRunner::run() { size_t progress_counter = 0; auto test_paths = get_test_paths(); @@ -212,6 +212,8 @@ void TestRunner::run() warn("\033]9;-1;\033\\"); print_test_results(); + + return m_counts; } static Result, ParserError> parse_file(const String& file_path) @@ -739,12 +741,13 @@ int main(int argc, char** argv) vm = JS::VM::create(); + Test::Counts result_counts; if (test262_parser_tests) - Test262ParserTestRunner(test_root, print_times, print_progress).run(); + result_counts = Test262ParserTestRunner(test_root, print_times, print_progress).run(); else - TestRunner(test_root, print_times, print_progress).run(); + result_counts = TestRunner(test_root, print_times, print_progress).run(); vm = nullptr; - return TestRunner::the()->counts().tests_failed > 0 ? 1 : 0; + return result_counts.tests_failed > 0 ? 1 : 0; }