From a7073c3f1f7645beb753c99a09c021a31ddf7039 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 15 Nov 2023 15:31:51 -0500 Subject: [PATCH] LibJS: Skip test262 tests with the CanBlockIsFalse flag From test262 documentation, this flag means: The test file should only be run when the [[CanBlock]] property of the Agent Record executing the file is `false`. This patch stubs out the accessor for that internal slot and skips tests with the CanBlockIsFalse if that internal slot is true. --- .../Userland/Libraries/LibJS/BUILD.gn | 1 + Tests/LibJS/test262-runner.cpp | 15 +++++++++++++++ Userland/Libraries/LibJS/CMakeLists.txt | 1 + Userland/Libraries/LibJS/Runtime/Agent.cpp | 19 +++++++++++++++++++ Userland/Libraries/LibJS/Runtime/Agent.h | 13 +++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 Userland/Libraries/LibJS/Runtime/Agent.cpp create mode 100644 Userland/Libraries/LibJS/Runtime/Agent.h diff --git a/Meta/gn/secondary/Userland/Libraries/LibJS/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibJS/BUILD.gn index 8bd76837293..116135dd9ef 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibJS/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibJS/BUILD.gn @@ -58,6 +58,7 @@ shared_library("LibJS") { "ParserError.cpp", "Print.cpp", "Runtime/AbstractOperations.cpp", + "Runtime/Agent.cpp", "Runtime/AggregateError.cpp", "Runtime/AggregateErrorConstructor.cpp", "Runtime/AggregateErrorPrototype.cpp", diff --git a/Tests/LibJS/test262-runner.cpp b/Tests/LibJS/test262-runner.cpp index 31e1c752390..a3856448e7d 100644 --- a/Tests/LibJS/test262-runner.cpp +++ b/Tests/LibJS/test262-runner.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -169,6 +170,11 @@ enum class StrictMode { OnlyStrict }; +enum class SkipTest { + No, + Yes, +}; + static constexpr auto sta_harness_file = "sta.js"sv; static constexpr auto assert_harness_file = "assert.js"sv; static constexpr auto async_include = "doneprintHandle.js"sv; @@ -176,6 +182,8 @@ static constexpr auto async_include = "doneprintHandle.js"sv; struct TestMetadata { Vector harness_files { sta_harness_file, assert_harness_file }; + SkipTest skip_test { SkipTest::No }; + StrictMode strict_mode { StrictMode::Both }; JS::Program::Type program_type { JS::Program::Type::Script }; bool is_async { false }; @@ -364,6 +372,9 @@ static Result extract_metadata(StringView source } else if (flag == "async"sv) { metadata.harness_files.append(async_include); metadata.is_async = true; + } else if (flag == "CanBlockIsFalse"sv) { + if (JS::agent_can_suspend()) + metadata.skip_test = SkipTest::Yes; } } } else if (line.starts_with("includes:"sv)) { @@ -733,6 +744,10 @@ int main(int argc, char** argv) } auto& metadata = metadata_or_error.value(); + if (metadata.skip_test == SkipTest::Yes) { + result_object.set("result", "skipped"); + continue; + } bool passed = true; diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index 1b02737384a..bb3ac3f087f 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -35,6 +35,7 @@ set(SOURCES Print.cpp Runtime/AbstractOperations.cpp Runtime/Accessor.cpp + Runtime/Agent.cpp Runtime/AggregateError.cpp Runtime/AggregateErrorConstructor.cpp Runtime/AggregateErrorPrototype.cpp diff --git a/Userland/Libraries/LibJS/Runtime/Agent.cpp b/Userland/Libraries/LibJS/Runtime/Agent.cpp new file mode 100644 index 00000000000..76877b86ff5 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Agent.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace JS { + +// 9.7.2 AgentCanSuspend ( ), https://tc39.es/ecma262/#sec-agentcansuspend +bool agent_can_suspend() +{ + // FIXME: 1. Let AR be the Agent Record of the surrounding agent. + // FIXME: 2. Return AR.[[CanBlock]]. + return true; +} + +} diff --git a/Userland/Libraries/LibJS/Runtime/Agent.h b/Userland/Libraries/LibJS/Runtime/Agent.h new file mode 100644 index 00000000000..8837625309a --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Agent.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace JS { + +bool agent_can_suspend(); + +}