From 458af2d2a9903528f643365441993c8a0fefcfdd Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 12 Dec 2024 13:10:03 -0500 Subject: [PATCH] LibJS: Concatenate all included test262 harness files to a single script For example, for the following `includes` line in a test262 file: includes: [sm/non262-TypedArray-shell.js, sm/non262.js] We currently parse and execute each file in this list as its own script, in the order they appear in the list. Tests have recently been imported test262 from SpiderMonkey which fail with this behavior. In the above example, if the first script references some function from the second script, we will currently fail to execute that harness file. This patch changes our behavior to concatenate all harness files into a single script, which satisfies the behavior required by these new tests. This is how test262.fyi and other test262 runners already behave. --- Tests/LibJS/test262-runner.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Tests/LibJS/test262-runner.cpp b/Tests/LibJS/test262-runner.cpp index 7af0445b234..a83a565dc49 100644 --- a/Tests/LibJS/test262-runner.cpp +++ b/Tests/LibJS/test262-runner.cpp @@ -145,20 +145,19 @@ static ErrorOr read_harness_file(StringView harness_file) return cache.value(); } -static ErrorOr, TestError> parse_harness_files(JS::Realm& realm, StringView harness_file) +static ErrorOr, TestError> parse_harness_contents(JS::Realm& realm, StringView harness_contents) { - auto source_or_error = read_harness_file(harness_file); - if (source_or_error.is_error()) - return source_or_error.release_error(); - auto program_or_error = parse_program(realm, source_or_error.value(), harness_file); + auto program_or_error = parse_program(realm, harness_contents, ""sv); + if (program_or_error.is_error()) { return TestError { NegativePhase::Harness, program_or_error.error().type, program_or_error.error().details, - harness_file + ""sv }; } + return program_or_error.release_value().get>(); } @@ -228,15 +227,22 @@ static ErrorOr run_test(StringView source, StringView filepath, auto program = TRY(parse_program(*realm, source, filepath, metadata.program_type)); + StringBuilder harness_builder; + for (auto harness_file : metadata.harness_files) { - ScriptOrModuleProgram harness_program { TRY(parse_harness_files(*realm, harness_file)) }; + auto harness_contents = TRY(read_harness_file(harness_file)); + harness_builder.appendff("{}\n", harness_contents); + } + + if (!harness_builder.is_empty()) { + ScriptOrModuleProgram harness_program { TRY(parse_harness_contents(*realm, harness_builder.string_view())) }; if (auto result = run_program(vm->bytecode_interpreter(), harness_program); result.is_error()) { return TestError { NegativePhase::Harness, result.error().type, result.error().details, - harness_file + ""sv }; } }