From e5c99b475aba6a2a4a957f2adc8398a1693aade6 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 26 Nov 2024 19:46:55 +0000 Subject: [PATCH] IDLGenerators: Set reflected unsigned long value according to spec Setting an unsigned long attribute with IDL to a value outside the range 0 to 2147483647, the value should be set to the default value. --- .../BindingsGenerator/IDLGenerators.cpp | 16 +++++++++++ .../HTML/unsigned-long-reflection.txt | 16 +++++++++++ .../input/HTML/unsigned-long-reflection.html | 27 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt create mode 100644 Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 317ff1d2fc6..eef52432e8e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -3833,6 +3833,22 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@) impl->remove_attribute(HTML::AttributeNames::@attribute.reflect_name@); else MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String {})); +)~~~"); + } else if (attribute.type->name() == "unsigned long") { + // The setter steps are: + // FIXME: 1. If the reflected IDL attribute is limited to only positive numbers and the given value is 0, then throw an "IndexSizeError" DOMException. + // 2. Let minimum be 0. + // FIXME: 3. If the reflected IDL attribute is limited to only positive numbers or limited to only positive numbers with fallback, then set minimum to 1. + // 4. Let newValue be minimum. + // FIXME: 5. If the reflected IDL attribute has a default value, then set newValue to defaultValue. + // 6. If the given value is in the range minimum to 2147483647, inclusive, then set newValue to it. + // 7. Run this's set the content attribute with newValue converted to the shortest possible string representing the number as a valid non-negative integer. + attribute_generator.append(R"~~~( + u32 minimum = 0; + u32 new_value = minimum; + if (cpp_value >= minimum && cpp_value <= 2147483647) + new_value = cpp_value; + MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String::number(new_value))); )~~~"); } else if (attribute.type->is_integer() && !attribute.type->is_nullable()) { attribute_generator.append(R"~~~( diff --git a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt new file mode 100644 index 00000000000..4d99f6bfd21 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt @@ -0,0 +1,16 @@ +img.getAttribute("hspace") after img.setAttribute("hspace", "1"): 1 +img.hspace after img.setAttribute("hspace", "1"): 1 +img.getAttribute("hspace") after img.hspace = 1: 1 +img.hspace after img.hspace = 1: 1 +img.getAttribute("hspace") after img.setAttribute("hspace", "2147483647"): 2147483647 +img.hspace after img.setAttribute("hspace", "2147483647"): 2147483647 +img.getAttribute("hspace") after img.hspace = 2147483647: 2147483647 +img.hspace after img.hspace = 2147483647: 2147483647 +img.getAttribute("hspace") after img.setAttribute("hspace", "2147483648"): 2147483648 +img.hspace after img.setAttribute("hspace", "2147483648"): 0 +img.getAttribute("hspace") after img.hspace = 2147483648: 0 +img.hspace after img.hspace = 2147483648: 0 +img.getAttribute("hspace") after img.setAttribute("hspace", "4294967295"): 4294967295 +img.hspace after img.setAttribute("hspace", "4294967295"): 0 +img.getAttribute("hspace") after img.hspace = 4294967295: 0 +img.hspace after img.hspace = 4294967295: 0 diff --git a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html new file mode 100644 index 00000000000..b012b14c14b --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html @@ -0,0 +1,27 @@ + + +