Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / html / custom_elements / custom_element_registry.lucb

#==============================================================================================
#
#   custom_element_registry - what phase 1 needs of HTML::CustomElementRegistry: the registry
#   cell every new Document gets, and looking definitions up in its (empty) definition set
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp lines 36-54
#       (the constructor, initialize, visit_edges) and 463-475 (append_scoped_document,
#       get_definition_with_name_and_local_name), with is_scoped of CustomElementRegistry.h,
#       taken by region r28 for Document::create_and_initialize. Defining custom elements (and
#       the rest of the file) needs scripts: phase 3.
#
#       Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from CustomElementRegistry.cpp:36 Web::HTML::CustomElementRegistry::CustomElementRegistry.
pub func html_custom_element_registry_construct(this: HtmlCustomElementRegistry*, realm: Realm*):
    bind_platform_object_construct_realm(this.bind_platform_object(), realm)

## Ported from CustomElementRegistry.cpp:43 Web::HTML::CustomElementRegistry::initialize (override).
pub func html_custom_element_registry_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.custom_element_registry)
    # Base::initialize(realm): PlatformObject inherits JS::Cell's.
    js_cell_initialize_impl(base, realm)

## Ported from CustomElementRegistry.cpp:49 Web::HTML::CustomElementRegistry::visit_edges (override).
pub func html_custom_element_registry_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (HtmlCustomElementRegistry*)base
    gc.cell_visit_edges_impl(base, visitor)
    for definition in ak.vector_span(&this.m_custom_element_definitions):
        gc.cell_visitor_visit_cell(visitor, (gc.Cell*?)definition)  # opaque in phase 1
    for entry in ak.ordered_hash_map_begin(&this.m_when_defined_promise_map):
        gc.cell_visitor_visit_t_2(visitor, entry.value)

## Ported from CustomElementRegistry.h:38 Web::HTML::CustomElementRegistry::is_scoped.
pub func html_custom_element_registry_is_scoped(this: HtmlCustomElementRegistry*) -> bool:
    return this.m_is_scoped

## Ported from CustomElementRegistry.cpp:463 Web::HTML::CustomElementRegistry::append_scoped_document.
pub func html_custom_element_registry_append_scoped_document(this: HtmlCustomElementRegistry*, document: DomDocument*):
    gc.weak_hash_set_set(&this.m_scoped_documents, document)

## Ported from CustomElementRegistry.cpp:468 Web::HTML::CustomElementRegistry::get_definition_with_name_and_local_name.
pub func html_custom_element_registry_get_definition_with_name_and_local_name(this: HtmlCustomElementRegistry*, name: ak.String, local_name: ak.String) -> HtmlCustomElementDefinition*?:
    for definition in ak.vector_span(&this.m_custom_element_definitions):
        let definition_name = html_custom_element_definition_name(definition)
        let definition_local_name = html_custom_element_definition_local_name(definition)
        if ak.string_equals(&definition_name, &name) and ak.string_equals(&definition_local_name, &local_name):
            return definition

    return none