Skip to content

Commit

Permalink
LibWeb: Use correct integer parsing rules in HTMLLIElement::value()
Browse files Browse the repository at this point in the history
(cherry picked from commit a61883ae88eb3fd4b35cc51db77a4c9405480fb5)
  • Loading branch information
tcl3 authored and nico committed Nov 26, 2024
1 parent f5a2881 commit 5ea38ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLLIElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <LibWeb/Bindings/HTMLLIElementPrototype.h>
#include <LibWeb/HTML/HTMLLIElement.h>
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/Window.h>

namespace Web::HTML {
Expand All @@ -25,4 +26,16 @@ void HTMLLIElement::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLLIElement);
}

// https://html.spec.whatwg.org/multipage/grouping-content.html#dom-li-value
WebIDL::Long HTMLLIElement::value()
{
// The value IDL attribute must reflect the value of the value content attribute.
// NOTE: This is equivalent to the code that would be generated by the IDL generator if we used [Reflect] on the value attribute.
// We don't do that in this case, since this method is used elsewhere.
auto content_attribute_value = get_attribute(AttributeNames::value).value_or("0"_string);
if (auto maybe_number = HTML::parse_integer(content_attribute_value); maybe_number.has_value())
return *maybe_number;
return 0;
}

}
5 changes: 3 additions & 2 deletions Userland/Libraries/LibWeb/HTML/HTMLLIElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <LibWeb/ARIA/Roles.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/WebIDL/Types.h>

namespace Web::HTML {

Expand All @@ -21,8 +22,8 @@ class HTMLLIElement final : public HTMLElement {
// https://www.w3.org/TR/html-aria/#el-li
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::listitem; }

i32 value() { return get_attribute(AttributeNames::value).value_or("0"_string).to_number<i32>().value_or(0); }
void set_value(i32 value)
WebIDL::Long value();
void set_value(WebIDL::Long value)
{
set_attribute(AttributeNames::value, MUST(String::number(value))).release_value_but_fixme_should_propagate_errors();
}
Expand Down

0 comments on commit 5ea38ea

Please sign in to comment.