Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / dom / element_9.lucb

#==============================================================================================
#
#   element_9 - DOM::Element: accessibility queries and custom element reactions
#
#   DESCRIPTION:
#       Port of LibWeb/DOM/Element.cpp (lines 2981-3359): hidden and referenced elements,
#       the accessibility tree exclusion and inclusion rules, enqueueing an element on the
#       appropriate element queue, the custom element upgrade and callback reactions,
#       upgrading an element, trying to upgrade, the defined/custom states and the HTML
#       element constructors' setup. The JavaScript operations these steps use (values,
#       native functions, construct) are phase-3 seams in stubs/stub_closure.lucb.
#
#==============================================================================================

# mark: Hidden and referenced elements ==========================================================

## `aria_hidden() == "true"` through the ARIAMixin virtual.
func dom_element_aria_hidden_is_true(element: DomElement*) -> bool:
    let aria_hidden = aria_mixin_aria_hidden(&element.aria_mixin) else return false
    return ak.string_eq_string_view(&aria_hidden, ak.sv("true"))

## Ported from Element.cpp:2981 Web::DOM::Element::is_hidden.
pub func dom_element_is_hidden(this: DomElement*) -> bool:
    let layout_node = dom_element_layout_node(this) else return true
    let computed_values = layout_node_with_style_computed_values(layout_node)
    let visibility = css_computed_values_visibility(&computed_values.computed_values)
    if visibility == css_data.Visibility.hidden or visibility == css_data.Visibility.collapse or css_computed_values_content_visibility(&computed_values.computed_values) == css_data.ContentVisibility.hidden:
        return true
    var self_or_ancestor: DomParentNode*? = this.dom_parent_node()
    while let current = self_or_ancestor:
        if let element = as_if_dom_element(current):
            if dom_element_aria_hidden_is_true(element):
                return true
        self_or_ancestor = dom_node_parent_or_shadow_host(current.dom_node())
    return false

## Ported from Element.cpp:2994 Web::DOM::Element::has_hidden_ancestor.
pub func dom_element_has_hidden_ancestor(this: DomElement*) -> bool:
    var self_or_ancestor: DomParentNode*? = this.dom_parent_node()
    while let current = self_or_ancestor:
        if let element = as_if_dom_element(current):
            if dom_element_is_hidden(element):
                return true
        self_or_ancestor = dom_node_parent_or_shadow_host(current.dom_node())
    return false

## Ported from Element.cpp:3003 Web::DOM::Element::is_referenced.
pub func dom_element_is_referenced(this: DomElement*) -> bool:
    var is_referenced = false
    if let id = dom_element_id(this):
        # root().for_each_in_subtree_of_type<HTML::HTMLElement>
        for node in dom_node_subtree(tree_node_root(this.dom_node())):
            let element = as_if_html_element(node) else continue
            let aria_data = aria_data_build_data(&element.dom_element().aria_mixin) else trap("MUST: AriaData::build_data")
            var labelled_by = aria_data_aria_labelled_by_or_default(aria_data)
            var found = false
            for label in ak.vector_span(&labelled_by):
                if ak.string_eq_fly_string(&label, &id):
                    found = true
                    break
            if found:
                is_referenced = true
                break
    return is_referenced

## Ported from Element.cpp:3019 Web::DOM::Element::has_referenced_and_hidden_ancestor.
pub func dom_element_has_referenced_and_hidden_ancestor(this: DomElement*) -> bool:
    var ancestor = dom_node_parent_or_shadow_host(this.dom_node())
    while let current = ancestor:
        if let element = as_if_dom_element(current):
            if dom_element_is_referenced(element) and dom_element_is_hidden(element):
                return true
        ancestor = dom_node_parent_or_shadow_host(current.dom_node())
    return false

# mark: The accessibility tree ==================================================================

## Ported from Element.cpp:3030 Web::DOM::Element::exclude_from_accessibility_tree (override).
# https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion
pub func dom_element_exclude_from_accessibility_tree_impl(base: AriaMixin*) -> bool:
    let this = dom_element_from_aria_mixin(base)
    # The following elements are not exposed via the accessibility API and user agents MUST NOT include them in the accessibility tree:

    # Elements, including their descendent elements, that have host language semantics specifying that the element is not displayed, such as CSS display:none, visibility:hidden, or the HTML hidden attribute.
    if dom_element_layout_node(this) == none:
        return true

    # Elements with none or presentation as the first role in the role attribute. However, their exclusion is conditional. In addition, the element's descendants and text content are generally included. These exceptions and conditions are documented in the presentation (role) section.
    # FIXME: Handle exceptions to excluding presentation role
    let role = aria_mixin_role_or_default(base)
    if role == AriaRole.none_ or role == AriaRole.presentation:
        return true

    # TODO: If not already excluded from the accessibility tree per the above rules, user agents SHOULD NOT include the following elements in the accessibility tree:
    #    Elements, including their descendants, that have aria-hidden set to true. In other words, aria-hidden="true" on a parent overrides aria-hidden="false" on descendants.
    #    Any descendants of elements that have the characteristic "Children Presentational: True" unless the descendant is not allowed to be presentational because it meets one of the conditions for exception described in Presentational Roles Conflict Resolution. However, the text content of any excluded descendants is included.
    #    Elements with the following roles have the characteristic "Children Presentational: True":
    #      button
    #      checkbox
    #      img
    #      menuitemcheckbox
    #      menuitemradio
    #      meter
    #      option
    #      progressbar
    #      radio
    #      scrollbar
    #      separator
    #      slider
    #      switch
    #      tab
    return false

## Ported from Element.cpp:3066 Web::DOM::Element::include_in_accessibility_tree (override).
# https://www.w3.org/TR/wai-aria-1.2/#tree_inclusion
pub func dom_element_include_in_accessibility_tree_impl(base: AriaMixin*) -> bool:
    let this = dom_element_from_aria_mixin(base)
    # If not excluded from or marked as hidden in the accessibility tree per the rules above in Excluding Elements in the Accessibility Tree, user agents MUST provide an accessible object in the accessibility tree for DOM elements that meet any of the following criteria:
    if aria_mixin_exclude_from_accessibility_tree(base):
        return false
    # Elements that are not hidden and may fire an accessibility API event, including:
    # Elements that are currently focused, even if the element or one of its ancestor elements has its aria-hidden attribute set to true.
    if dom_element_is_focused(this):
        return true
    # TODO: Elements that are a valid target of an aria-activedescendant attribute.

    # Elements that have an explicit role or a global WAI-ARIA attribute and do not have aria-hidden set to true. (See Excluding Elements in the Accessibility Tree for additional guidance on aria-hidden.)
    # NOTE: The spec says only explicit roles count, but playing around in other browsers, this does not seem to be true in practice (for example button elements are always exposed with their implicit role if none is set)
    #       This issue https://github.com/w3c/aria/issues/1851 seeks clarification on this point
    if (aria_mixin_role_or_default(base) != none or aria_mixin_has_global_aria_attribute(base)) and not dom_element_aria_hidden_is_true(this):
        return true

    # TODO: Elements that are not hidden and have an ID that is referenced by another element via a WAI-ARIA property.

    return false

# mark: Element queues ==========================================================================

## The captures of Element::enqueue_an_element_on_the_appropriate_element_queue's microtask.
struct DomElementEnqueueAnElementOnTheAppropriateElementQueueMicrotask:
    var this: DomElement*

## The microtask that invokes the backup element queue's reactions.
func dom_element_enqueue_an_element_on_the_appropriate_element_queue_microtask(context: void*?):
    let captures = (DomElementEnqueueAnElementOnTheAppropriateElementQueueMicrotask*)(context else trap("no captures"))
    let this = captures.this
    let reactions_stack = &html_relevant_similar_origin_window_agent((JsObject*)this).custom_element_reactions_stack

    # 1. Invoke custom element reactions in reactionsStack's backup element queue.
    bind_invoke_custom_element_reactions(&reactions_stack.backup_element_queue)

    # 2. Unset reactionsStack's processing the backup element queue flag.
    reactions_stack.processing_the_backup_element_queue = false

## Ported from Element.cpp:3089 Web::DOM::Element::enqueue_an_element_on_the_appropriate_element_queue.
# https://html.spec.whatwg.org/multipage/custom-elements.html#enqueue-an-element-on-the-appropriate-element-queue
func dom_element_enqueue_an_element_on_the_appropriate_element_queue(this: DomElement*):
    # 1. Let reactionsStack be element's relevant agent's custom element reactions stack.
    let relevant_agent = html_relevant_similar_origin_window_agent((JsObject*)this)
    let reactions_stack = &relevant_agent.custom_element_reactions_stack

    # 2. If reactionsStack is empty, then:
    if ak.vector_is_empty(&reactions_stack.element_queue_stack):
        # 1. Add element to reactionsStack's backup element queue.
        ak.vector_append_t(&reactions_stack.backup_element_queue, gc.make_weak[DomElement](this))

        # 2. If reactionsStack's processing the backup element queue flag is set, then return.
        if reactions_stack.processing_the_backup_element_queue:
            return

        # 3. Set reactionsStack's processing the backup element queue flag.
        reactions_stack.processing_the_backup_element_queue = true

        # 4. Queue a microtask to perform the following steps:
        # NOTE: `this` is protected by GC::Function
        let captures = new DomElementEnqueueAnElementOnTheAppropriateElementQueueMicrotask(this = this) else trap("out of memory")
        html_queue_a_microtask(dom_element_document(this), gc.create_function0(gc.cell_heap(this.cell()), ak.Function0[unit](call = dom_element_enqueue_an_element_on_the_appropriate_element_queue_microtask, context = captures)))

        return

    # 3. Otherwise, add element to element's relevant agent's current element queue.
    ak.vector_append_t(html_similar_origin_window_agent_current_element_queue(relevant_agent), gc.make_weak[DomElement](this))

# mark: Custom element reactions ================================================================

## Ported from Element.cpp:3127 Web::DOM::Element::enqueue_a_custom_element_upgrade_reaction.
# https://html.spec.whatwg.org/multipage/custom-elements.html#enqueue-a-custom-element-upgrade-reaction
pub func dom_element_enqueue_a_custom_element_upgrade_reaction(this: DomElement*, custom_element_definition: HtmlCustomElementDefinition*):
    # 1. Add a new upgrade reaction to element's custom element reaction queue, with custom element definition definition.
    ak.vector_append_t(dom_element_ensure_custom_element_reaction_queue(this), DomCustomElementUpgradeReactionOrDomCustomElementCallbackReaction.dom_custom_element_upgrade_reaction(DomCustomElementUpgradeReaction(custom_element_definition = custom_element_definition)))

    # 2. Enqueue an element on the appropriate element queue given element.
    dom_element_enqueue_an_element_on_the_appropriate_element_queue(this)

## `definition->lifecycle_callbacks().find(name)`: the callback stored under `name`, or null.
func dom_element_lifecycle_callback(definition: HtmlCustomElementDefinition*, name: ak.FlyString) -> IdlCallbackType*?:
    let callback = ak.ordered_hash_map_get_k_const(html_custom_element_definition_lifecycle_callbacks(definition), name) else return none
    return *callback

## The captures of Element::enqueue_a_custom_element_callback_reaction's connectedMoveCallback steps.
struct DomElementEnqueueACustomElementCallbackReactionMoveSteps:
    var this: DomElement*
    var disconnected_callback: IdlCallbackType*?
    var connected_callback: IdlCallbackType*?

## The native function Element::enqueue_a_custom_element_callback_reaction makes for a definition
## without a connectedMoveCallback.
func dom_element_enqueue_a_custom_element_callback_reaction_move_steps(context: void*?, vm: Vm*) -> JsValue:
    let captures = (DomElementEnqueueACustomElementCallbackReactionMoveSteps*)(context else trap("no captures"))
    let this_value = bind_platform_object_wrapper(captures.this.bind_platform_object())
    var no_arguments: ak.Vector[JsValue]

    # 1. If disconnectedCallback is not null, then call disconnectedCallback with no arguments.
    if let disconnected_callback = captures.disconnected_callback:
        _ = idl_invoke_callback_idl_exception_behavior(disconnected_callback, this_value, IdlExceptionBehavior.report, ak.vector_span(&no_arguments))

    # 2. If connectedCallback is not null, then call connectedCallback with no arguments.
    if let connected_callback = captures.connected_callback:
        _ = idl_invoke_callback_idl_exception_behavior(connected_callback, this_value, IdlExceptionBehavior.report, ak.vector_span(&no_arguments))

    return js_undefined()

## Ported from Element.cpp:3137 Web::DOM::Element::enqueue_a_custom_element_callback_reaction.
# https://html.spec.whatwg.org/multipage/custom-elements.html#enqueue-a-custom-element-callback-reaction
pub func dom_element_enqueue_a_custom_element_callback_reaction(this: DomElement*, callback_name: ak.FlyString, arguments: ak.Vector[JsValue]):
    # 1. Let definition be element's custom element definition.
    let definition = this.m_custom_element_definition else trap("enqueue a custom element callback reaction: no definition")

    # 2. Let callback be the value of the entry in definition's lifecycle callbacks with key callbackName.
    var callback = dom_element_lifecycle_callback(definition, callback_name)

    # 3. If callbackName is "connectedMoveCallback" and callback is null:
    if ak.fly_string_eq_fly_string(&callback_name, &html_custom_element_reaction_names_connected_move_callback) and callback == none:
        # 1. Let disconnectedCallback be the value of the entry in definition's lifecycle callbacks with key "disconnectedCallback".
        let disconnected_callback = dom_element_lifecycle_callback(definition, html_custom_element_reaction_names_disconnected_callback)

        # 2. Let connectedCallback be the value of the entry in definition's lifecycle callbacks with key "connectedCallback".
        let connected_callback = dom_element_lifecycle_callback(definition, html_custom_element_reaction_names_connected_callback)

        # 3. If connectedCallback and disconnectedCallback are null, then return.
        if connected_callback == none and disconnected_callback == none:
            return

        # 4. Set callback to the following steps:
        let captures = new DomElementEnqueueACustomElementCallbackReactionMoveSteps(this = this, disconnected_callback = disconnected_callback, connected_callback = connected_callback) else trap("out of memory")
        let steps = js_native_function_create(dom_element_realm(this), JsNativeFunctionBehaviour(call = dom_element_enqueue_a_custom_element_callback_reaction_move_steps, context = captures), 0, ak.utf16_fly_string_new(), dom_element_realm(this))
        callback = realm_create_idl_callback_type_realm(dom_element_realm(this), (JsObject*)steps, dom_element_realm(this), IdlOperationReturnsPromise.no)

    # 3. If callback is null, then return.
    if callback == none:
        return

    # 5. If callbackName is "attributeChangedCallback":
    if ak.fly_string_eq_fly_string(&callback_name, &html_custom_element_reaction_names_attribute_changed_callback):
        # 1. Let attributeName be the first element of args.
        assert(not ak.vector_is_empty(&arguments))
        let attribute_name_value = *ak.vector_at_const(&arguments, 0)
        assert(js_value_is_string(attribute_name_value))
        let attribute_name = js_value_as_string_utf8_string(attribute_name_value)

        # 2. If definition's observed attributes does not contain attributeName, then return.
        let observed_attributes = html_custom_element_definition_observed_attributes(definition)
        var observed = false
        for i in 0..<ak.vector_size(observed_attributes):
            if ak.string_equals(ak.vector_at_const(observed_attributes, i), &attribute_name):
                observed = true
                break
        if not observed:
            return

    # 6. Add a new callback reaction to element's custom element reaction queue, with callback function callback and arguments args.
    ak.vector_append_t(dom_element_ensure_custom_element_reaction_queue(this), DomCustomElementUpgradeReactionOrDomCustomElementCallbackReaction.dom_custom_element_callback_reaction(DomCustomElementCallbackReaction(callback = callback, arguments = arguments)))

    # 7. Enqueue an element on the appropriate element queue given element.
    dom_element_enqueue_an_element_on_the_appropriate_element_queue(this)

# mark: Upgrading ===============================================================================

## Element::upgrade_element's `attempt_to_construct_custom_element` lambda.
func dom_element_upgrade_element_attempt_to_construct_custom_element(this: DomElement*, custom_element_definition: HtmlCustomElementDefinition*, constructor: IdlCallbackType*) -> !:
    let realm = dom_element_realm(this)
    let vm = js_cell_vm(this.js_cell())

    # 1. If definition's disable shadow is true and element's shadow root is non-null, then throw a
    #    "NotSupportedError" DOMException.
    if html_custom_element_definition_disable_shadow(custom_element_definition) and dom_element_shadow_root(this) != none:
        try idl_throw(.idl_dom_exception(idl_not_supported_error_create(realm, ak.utf16_string_from_str("Custom element definition disables shadow DOM and the custom element has a shadow root"))))

    # 2. Set element's custom element state to "precustomized".
    dom_element_set_custom_element_state(this, DomCustomElementState.precustomized)

    # 3. Let constructResult be the result of constructing C, with no arguments.
    var no_arguments: ak.Vector[JsValue]
    let construct_result = try js_completion_release_value(idl_construct(constructor, ak.vector_span(&no_arguments)))

    # 4. If SameValue(constructResult, element) is false, then throw a TypeError.
    if not js_same_value(construct_result, bind_platform_object_wrapper(this.bind_platform_object())):
        try vm_throw_completion(vm, IdlSimpleExceptionType.type_error, .string_view(ak.sv("Constructing the custom element returned a different element from the custom element")))

## Ported from Element.cpp:3204 Web::DOM::Element::upgrade_element.
# https://html.spec.whatwg.org/multipage/custom-elements.html#concept-upgrade-an-element
pub func dom_element_upgrade_element(this: DomElement*, custom_element_definition: HtmlCustomElementDefinition*) -> !:
    let vm = js_cell_vm(this.js_cell())

    # 1. If element's custom element state is not "undefined" or "uncustomized", then return.
    if this.m_custom_element_state != DomCustomElementState.undefined and this.m_custom_element_state != DomCustomElementState.uncustomized:
        return

    # 2. Set element's custom element definition to definition.
    this.m_custom_element_definition = custom_element_definition

    # 3. Set element's custom element state to "failed".
    dom_element_set_custom_element_state(this, DomCustomElementState.failed)

    # 4. For each attribute in element's attribute list, in order, enqueue a custom element callback reaction with
    #    element, callback name "attributeChangedCallback", and « attribute's local name, null, attribute's value,
    #    attribute's namespace ».
    var attribute_count: usize = 0
    if let attributes = this.m_attributes:
        attribute_count = dom_named_node_map_length(attributes)
    for attribute_index in 0..<attribute_count:
        let attributes = this.m_attributes else trap("unreachable")
        let attribute = dom_named_node_map_item(attributes, (u32)attribute_index) else trap("VERIFY: attribute")

        var arguments: ak.Vector[JsValue]

        ak.vector_append_t(&arguments, js_primitive_string_create_fly_string(vm, dom_attr_local_name(attribute)))
        ak.vector_append_t(&arguments, js_null())
        ak.vector_append_t(&arguments, js_primitive_string_create_string(vm, dom_attr_value(attribute)))
        if let namespace_uri = dom_attr_namespace_uri(attribute):
            ak.vector_append_t(&arguments, js_primitive_string_create_fly_string(vm, namespace_uri))
        else:
            ak.vector_append_t(&arguments, js_null())

        dom_element_enqueue_a_custom_element_callback_reaction(this, html_custom_element_reaction_names_attribute_changed_callback, arguments)

    # 5. If element is connected, then enqueue a custom element callback reaction with element, callback name
    #    "connectedCallback", and « ».
    if dom_node_is_connected(this.dom_node()):
        var empty_arguments: ak.Vector[JsValue]
        dom_element_enqueue_a_custom_element_callback_reaction(this, html_custom_element_reaction_names_connected_callback, empty_arguments)

    # 6. Add element to the end of definition's construction stack.
    ak.vector_append_t(html_custom_element_definition_construction_stack(custom_element_definition), HtmlCustomElementDefinitionConstructionStackEntry.dom_element(this))

    # 7. Let C be definition's constructor.
    let constructor = html_custom_element_definition_constructor(custom_element_definition)

    # 8. Set the surrounding agent's active custom element constructor map[C] to element's custom element registry.
    let surrounding_agent = html_relevant_similar_origin_window_agent((JsObject*)this)
    _ = ak.hash_map_set(&surrounding_agent.active_custom_element_constructor_map, (JsFunctionObject*)constructor.callback, dom_element_custom_element_registry(this))

    # 9. Run the following steps while catching any exceptions:
    # The exception's message is copied: its handler gives the original back when it finishes
    # (luce-base base.md §11.3).
    var threw = false
    var thrown_code: ErrorCode? = none
    var thrown_room: u8[1024]
    var thrown_message = ""
    dom_element_upgrade_element_attempt_to_construct_custom_element(this, custom_element_definition, constructor) catch failure:
        threw = true
        thrown_code = failure.code
        thrown_message = copy_into(thrown_room, failure.message)
        recover ()

    # Then, perform the following steps, regardless of whether the above steps threw an exception or not:
    # 1. Remove the surrounding agent's active custom element constructor map[C].
    _ = ak.hash_map_remove_k(&surrounding_agent.active_custom_element_constructor_map, (JsFunctionObject*)constructor.callback)

    # 2. Remove the last entry from the end of definition's construction stack.
    _ = ak.vector_take_last(html_custom_element_definition_construction_stack(custom_element_definition))

    # Finally, if the above steps threw an exception, then:
    if threw:
        # 1. Set element's custom element definition to null.
        this.m_custom_element_definition = none

        # 2. Empty element's custom element reaction queue.
        if let reaction_queue = this.m_custom_element_reaction_queue:
            ak.vector_clear(reaction_queue)

        # 3. Rethrow the exception (thus terminating this algorithm).
        let code = thrown_code else trap("unreachable")
        error(code, thrown_message)

    # 10. If element is a form-associated custom element, then:
    if let html_element = as_if_html_element(this):
        if html_element_is_form_associated_custom_element(html_element):
            let form_associated_element = as_if_form_associated_element(this) else trap("HTMLElement is a FormAssociatedElement")
            # 1. Reset the form owner of element.
            # FIXME: If element is associated with a form element, then enqueue a custom element callback reaction with element, callback name "formAssociatedCallback", and « the associated form ».
            # AD-HOC: We don't do the second part of this step here, because it's inside reset_form_owner.
            html_form_associated_element_reset_form_owner(form_associated_element)

            # 2. If element is disabled, then enqueue a custom element callback reaction with element, callback name "formDisabledCallback", and « true ».
            html_form_associated_element_update_face_disabled_state(form_associated_element)

    # 11. Set element's custom element state to "custom".
    dom_element_set_custom_element_state(this, DomCustomElementState.custom)

## Ported from Element.cpp:3314 Web::DOM::Element::try_to_upgrade.
# https://html.spec.whatwg.org/multipage/custom-elements.html#concept-try-upgrade
pub func dom_element_try_to_upgrade(this: DomElement*):
    # 1. Let definition be the result of looking up a custom element definition given element's custom element
    #    registry, element's namespace, element's local name, and element's is value.
    let definition = html_look_up_a_custom_element_definition(dom_element_custom_element_registry(this), dom_element_namespace_uri(this), dom_element_local_name(this), dom_element_is_value(this))

    # 2. If definition is not null, then enqueue a custom element upgrade reaction given element and definition.
    if let found = definition:
        dom_element_enqueue_a_custom_element_upgrade_reaction(this, found)

## Ported from Element.cpp:3326 Web::DOM::Element::is_defined.
# https://dom.spec.whatwg.org/#concept-element-defined
pub func dom_element_is_defined(this: DomElement*) -> bool:
    # An element whose custom element state is "uncustomized" or "custom" is said to be defined.
    return this.m_custom_element_state == DomCustomElementState.uncustomized or this.m_custom_element_state == DomCustomElementState.custom

## Ported from Element.cpp:3333 Web::DOM::Element::is_custom.
# https://dom.spec.whatwg.org/#concept-element-custom
pub func dom_element_is_custom(this: DomElement*) -> bool:
    # An element whose custom element state is "custom" is said to be custom.
    return this.m_custom_element_state == DomCustomElementState.custom

## Ported from Element.cpp:3339 Web::DOM::Element::set_custom_element_state.
pub func dom_element_set_custom_element_state(this: DomElement*, state: DomCustomElementState):
    if this.m_custom_element_state == state:
        return
    this.m_custom_element_state = state

    css_invalidation_invalidate_style_after_custom_element_state_change(this)

## Ported from Element.cpp:3349 Web::DOM::Element::setup_custom_element_from_constructor.
# https://html.spec.whatwg.org/multipage/dom.html#html-element-constructors
pub func dom_element_setup_custom_element_from_constructor(this: DomElement*, custom_element_definition: HtmlCustomElementDefinition*, is_value: ak.String?):
    # 7.6. Set element's custom element state to "custom".
    dom_element_set_custom_element_state(this, DomCustomElementState.custom)

    # 7.7. Set element's custom element definition to definition.
    this.m_custom_element_definition = custom_element_definition

    # 7.8. Set element's is value to is value.
    this.m_is_value = is_value