Browse Source

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.
Timothy Flynn 1 year ago
parent
commit
a7073c3f1f

+ 1 - 0
Meta/gn/secondary/Userland/Libraries/LibJS/BUILD.gn

@@ -58,6 +58,7 @@ shared_library("LibJS") {
     "ParserError.cpp",
     "ParserError.cpp",
     "Print.cpp",
     "Print.cpp",
     "Runtime/AbstractOperations.cpp",
     "Runtime/AbstractOperations.cpp",
+    "Runtime/Agent.cpp",
     "Runtime/AggregateError.cpp",
     "Runtime/AggregateError.cpp",
     "Runtime/AggregateErrorConstructor.cpp",
     "Runtime/AggregateErrorConstructor.cpp",
     "Runtime/AggregateErrorPrototype.cpp",
     "Runtime/AggregateErrorPrototype.cpp",

+ 15 - 0
Tests/LibJS/test262-runner.cpp

@@ -18,6 +18,7 @@
 #include <LibJS/Bytecode/Interpreter.h>
 #include <LibJS/Bytecode/Interpreter.h>
 #include <LibJS/Contrib/Test262/GlobalObject.h>
 #include <LibJS/Contrib/Test262/GlobalObject.h>
 #include <LibJS/Parser.h>
 #include <LibJS/Parser.h>
+#include <LibJS/Runtime/Agent.h>
 #include <LibJS/Runtime/VM.h>
 #include <LibJS/Runtime/VM.h>
 #include <LibJS/Runtime/ValueInlines.h>
 #include <LibJS/Runtime/ValueInlines.h>
 #include <LibJS/Script.h>
 #include <LibJS/Script.h>
@@ -169,6 +170,11 @@ enum class StrictMode {
     OnlyStrict
     OnlyStrict
 };
 };
 
 
+enum class SkipTest {
+    No,
+    Yes,
+};
+
 static constexpr auto sta_harness_file = "sta.js"sv;
 static constexpr auto sta_harness_file = "sta.js"sv;
 static constexpr auto assert_harness_file = "assert.js"sv;
 static constexpr auto assert_harness_file = "assert.js"sv;
 static constexpr auto async_include = "doneprintHandle.js"sv;
 static constexpr auto async_include = "doneprintHandle.js"sv;
@@ -176,6 +182,8 @@ static constexpr auto async_include = "doneprintHandle.js"sv;
 struct TestMetadata {
 struct TestMetadata {
     Vector<StringView> harness_files { sta_harness_file, assert_harness_file };
     Vector<StringView> harness_files { sta_harness_file, assert_harness_file };
 
 
+    SkipTest skip_test { SkipTest::No };
+
     StrictMode strict_mode { StrictMode::Both };
     StrictMode strict_mode { StrictMode::Both };
     JS::Program::Type program_type { JS::Program::Type::Script };
     JS::Program::Type program_type { JS::Program::Type::Script };
     bool is_async { false };
     bool is_async { false };
@@ -364,6 +372,9 @@ static Result<TestMetadata, DeprecatedString> extract_metadata(StringView source
                 } else if (flag == "async"sv) {
                 } else if (flag == "async"sv) {
                     metadata.harness_files.append(async_include);
                     metadata.harness_files.append(async_include);
                     metadata.is_async = true;
                     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)) {
         } else if (line.starts_with("includes:"sv)) {
@@ -733,6 +744,10 @@ int main(int argc, char** argv)
         }
         }
 
 
         auto& metadata = metadata_or_error.value();
         auto& metadata = metadata_or_error.value();
+        if (metadata.skip_test == SkipTest::Yes) {
+            result_object.set("result", "skipped");
+            continue;
+        }
 
 
         bool passed = true;
         bool passed = true;
 
 

+ 1 - 0
Userland/Libraries/LibJS/CMakeLists.txt

@@ -35,6 +35,7 @@ set(SOURCES
     Print.cpp
     Print.cpp
     Runtime/AbstractOperations.cpp
     Runtime/AbstractOperations.cpp
     Runtime/Accessor.cpp
     Runtime/Accessor.cpp
+    Runtime/Agent.cpp
     Runtime/AggregateError.cpp
     Runtime/AggregateError.cpp
     Runtime/AggregateErrorConstructor.cpp
     Runtime/AggregateErrorConstructor.cpp
     Runtime/AggregateErrorPrototype.cpp
     Runtime/AggregateErrorPrototype.cpp

+ 19 - 0
Userland/Libraries/LibJS/Runtime/Agent.cpp

@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibJS/Runtime/Agent.h>
+
+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;
+}
+
+}

+ 13 - 0
Userland/Libraries/LibJS/Runtime/Agent.h

@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+namespace JS {
+
+bool agent_can_suspend();
+
+}