HTMLLIElement.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLLIElementPrototype.h>
  7. #include <LibWeb/HTML/HTMLLIElement.h>
  8. #include <LibWeb/HTML/Numbers.h>
  9. #include <LibWeb/HTML/Window.h>
  10. namespace Web::HTML {
  11. GC_DEFINE_ALLOCATOR(HTMLLIElement);
  12. HTMLLIElement::HTMLLIElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLLIElement::~HTMLLIElement() = default;
  17. void HTMLLIElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLLIElement);
  21. }
  22. // https://html.spec.whatwg.org/multipage/grouping-content.html#dom-li-value
  23. WebIDL::Long HTMLLIElement::value()
  24. {
  25. // The value IDL attribute must reflect the value of the value content attribute.
  26. // NOTE: This is equivalent to the code that would be generated by the IDL generator if we used [Reflect] on the value attribute.
  27. // We don't do that in this case, since this method is used elsewhere.
  28. auto content_attribute_value = get_attribute(AttributeNames::value).value_or("0"_string);
  29. if (auto maybe_number = HTML::parse_integer(content_attribute_value); maybe_number.has_value())
  30. return *maybe_number;
  31. return 0;
  32. }
  33. }