mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
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.
This commit is contained in:
parent
40e7f46ac8
commit
458af2d2a9
Notes:
github-actions[bot]
2024-12-13 13:27:35 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/458af2d2a99 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2889
1 changed files with 14 additions and 8 deletions
|
@ -145,20 +145,19 @@ static ErrorOr<StringView, TestError> read_harness_file(StringView harness_file)
|
|||
return cache.value();
|
||||
}
|
||||
|
||||
static ErrorOr<GC::Ref<JS::Script>, TestError> parse_harness_files(JS::Realm& realm, StringView harness_file)
|
||||
static ErrorOr<GC::Ref<JS::Script>, 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<JS::Script>(realm, source_or_error.value(), harness_file);
|
||||
auto program_or_error = parse_program<JS::Script>(realm, harness_contents, "<harness>"sv);
|
||||
|
||||
if (program_or_error.is_error()) {
|
||||
return TestError {
|
||||
NegativePhase::Harness,
|
||||
program_or_error.error().type,
|
||||
program_or_error.error().details,
|
||||
harness_file
|
||||
"<harness>"sv
|
||||
};
|
||||
}
|
||||
|
||||
return program_or_error.release_value().get<GC::Ref<JS::Script>>();
|
||||
}
|
||||
|
||||
|
@ -228,15 +227,22 @@ static ErrorOr<void, TestError> 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
|
||||
"<harness>"sv
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue