Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / html / parser / speculative_mock_element.lucb

#==============================================================================================
#
#   speculative_mock_element - HTML::SpeculativeMockElement: what the speculative parser sees
#                              of an element
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/Parser/SpeculativeMockElement.cpp (lines 1-38): an attribute lookup
#       and creating a speculative mock element (a local name and the token's attributes).
#
#==============================================================================================

## Ported from SpeculativeMockElement.cpp:11 Web::HTML::SpeculativeMockElement::attribute.
pub func html_speculative_mock_element_attribute(this: const HtmlSpeculativeMockElement*, name: ak.FlyString) -> ak.String?:
    for attribute in &ak.vector_span_const(&this.attribute_list):
        if ak.fly_string_eq_fly_string(&attribute.local_name, &name):
            return attribute.value
    return none

## Ported from SpeculativeMockElement.cpp:21 Web::HTML::create_a_speculative_mock_element.
# https://html.spec.whatwg.org/multipage/parsing.html#create-a-speculative-mock-element
pub func html_create_a_speculative_mock_element(tag_name: ak.FlyString, attributes: ak.Vector[html_syntax.HtmlTokenAttribute]) -> HtmlSpeculativeMockElement:
    # 1. Let element be a new speculative mock element.
    # 2. FIXME: Set element's namespace to namespace.
    # 3. Set element's local name to tagName.
    # 4. Set element's attribute list to attributes.
    # 5. FIXME: Set element's children to a new empty list.
    # 6. Optionally, perform a speculative fetch for element.
    # The speculative fetch is performed by the caller (see SpeculativeHTMLParser::process_start_tag).

    # 7. Return element.
    return HtmlSpeculativeMockElement(local_name = tag_name, attribute_list = attributes)