Просмотр исходного кода

LibWeb: Correct attributes on IDL interface 'operations'

This fixes four tests for the IDL harness for URL under:

https://wpt.live/url/idlharness.any.html
and https://wpt.live/url/idlharness.any.worker.html

But probably some tests in other places too :^)
Shannon Booth 10 месяцев назад
Родитель
Сommit
e9dd05b2b5

+ 7 - 1
Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp

@@ -4415,8 +4415,14 @@ static void define_the_operations(SourceGenerator& generator, HashMap<ByteString
         function_generator.set("function.name:snakecase", make_input_acceptable_cpp(operation.key.to_snakecase()));
         function_generator.set("function.length", ByteString::number(get_shortest_function_length(operation.value)));
 
+        // NOTE: This assumes that every function in the overload set has the same attribute set.
+        if (operation.value[0].extended_attributes.contains("LegacyUnforgable"sv))
+            function_generator.set("function.attributes", "JS::Attribute::Enumerable");
+        else
+            function_generator.set("function.attributes", "JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable");
+
         function_generator.append(R"~~~(
-    define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, default_attributes);
+    define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, @function.attributes@);
 )~~~");
     }
 }

+ 4 - 0
Tests/LibWeb/Text/expected/URL/URL-operations-properties.txt

@@ -0,0 +1,4 @@
+writable: true
+configurable: true
+enumerable: true
+value (the function itself): function canParse() { [native code] }

+ 10 - 0
Tests/LibWeb/Text/input/URL/URL-operations-properties.html

@@ -0,0 +1,10 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        const descriptor = Object.getOwnPropertyDescriptor(URL, "canParse");
+        println(`writable: ${descriptor.writable}`);
+        println(`configurable: ${descriptor.configurable}`);
+        println(`enumerable: ${descriptor.enumerable}`);
+        println(`value (the function itself): ${descriptor.value}`);
+    });
+</script>