Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / bindings / intrinsics.lucb

#==============================================================================================
#
#   intrinsics - Bindings::Intrinsics: a realm's web namespaces, prototypes and constructors
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/Bindings/Intrinsics.cpp (lines 1-58) and Intrinsics.h (lines
#       1-133). The Intrinsics cell of a realm holds the interface prototype objects, interface
#       objects and namespace objects created on first use. Those are JS objects made by the
#       generated bindings (phase 3, DESIGN.md ยง3.6); in phase 1 the tables stay empty and the
#       cell is data: created for every realm, reached through its HostDefined, visited.
#
#       Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
#       Copyright (c) 2026, Shannon Booth <shannon@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: Intrinsics ==============================================================================

## Ported from Libraries/LibWeb/Bindings/Intrinsics.h:47 Web::Bindings::Intrinsics::Intrinsics.
pub func bind_intrinsics_construct(this: BindIntrinsics*, realm: Realm*):
    this.m_realm = realm

## Ported from Libraries/LibWeb/Bindings/Intrinsics.h:53 Web::Bindings::Intrinsics::ensure_web_namespace:
## the namespace object of `namespace_name`, created on first use by the generated namespace
## class (phase 3).
pub func bind_intrinsics_ensure_web_namespace[TNamespaceType](this: BindIntrinsics*, namespace_name: ak.FlyString) -> JsObject*:
    if let it = ak.hash_map_get_k(&this.m_namespaces, namespace_name):
        return *it

    bind_intrinsics_create_web_namespace[TNamespaceType](this, this.m_realm)
    return *(ak.hash_map_get_k(&this.m_namespaces, namespace_name) else trap("VERIFY: namespace created"))

## Ported from Libraries/LibWeb/Bindings/Intrinsics.h:63 Web::Bindings::Intrinsics::ensure_web_prototype:
## the interface prototype object of `class_name`, created on first use (phase 3).
pub func bind_intrinsics_ensure_web_prototype[TPrototypeType](this: BindIntrinsics*, class_name: ak.FlyString) -> JsObject*:
    if let it = ak.hash_map_get_k(&this.m_prototypes, class_name):
        return *it

    # create_web_prototype_and_constructor<PrototypeType>(*m_realm): generated per interface by
    # the bindings generator (phase 3).
    trap("unported (P3): Web::Bindings::Intrinsics::create_web_prototype_and_constructor")

## Ported from Libraries/LibWeb/Bindings/Intrinsics.h:73 Web::Bindings::Intrinsics::ensure_web_constructor:
## the interface object of `class_name`, created on first use (phase 3).
pub func bind_intrinsics_ensure_web_constructor[TPrototypeType](this: BindIntrinsics*, class_name: ak.FlyString) -> JsNativeFunction*:
    if let it = ak.hash_map_get_k(&this.m_constructors, class_name):
        return *it else trap("VERIFY: constructor")

    # create_web_prototype_and_constructor<PrototypeType>(*m_realm): phase 3.
    trap("unported (P3): Web::Bindings::Intrinsics::create_web_prototype_and_constructor")

## Ported from Libraries/LibWeb/Bindings/Intrinsics.cpp:34 Web::Bindings::Intrinsics::ensure_web_unforgeable_function:
## the getter or setter function of an [LegacyUnforgeable] attribute, one per realm.
pub func bind_intrinsics_ensure_web_unforgeable_function(this: BindIntrinsics*, interface_name: ak.Utf16FlyString, attribute_name: ak.Utf16FlyString, behaviour: ak.Function1[Vm*, JsValue], type_: BindUnforgeableKeyType) -> JsNativeFunction*:
    let key = BindUnforgeableKey(interface_name = interface_name, attribute_name = attribute_name, type_ = type_)
    if let it = ak.hash_map_get_k(&this.m_unforgeable_functions, key):
        return *it

    # JS::NativeFunction::create(*m_realm, move(behaviour), type == Setter ? 1 : 0, attribute_name,
    # m_realm, type == Setter ? "set"sv : "get"sv): a JS function (phase 3).
    trap("unported (P3): Web::Bindings::Intrinsics::ensure_web_unforgeable_function (JS::NativeFunction::create)")

## Ported from Libraries/LibWeb/Bindings/Intrinsics.cpp:18 Web::Bindings::Intrinsics::visit_edges (override).
pub func bind_intrinsics_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (BindIntrinsics*)base
    gc.cell_visit_edges_impl(base, visitor)
    for entry in ak.hash_map_begin(&this.m_namespaces):
        js_visit_object(visitor, entry.value)
    for entry in ak.hash_map_begin(&this.m_prototypes):
        js_visit_object(visitor, entry.value)
    for entry in ak.hash_map_begin(&this.m_constructors):
        gc.cell_visitor_visit_cell(visitor, (gc.Cell*?)entry.value)
    gc.cell_visitor_visit_t_2(visitor, this.m_realm)
    for entry in ak.hash_map_begin(&this.m_unforgeable_functions):
        gc.cell_visitor_visit_cell(visitor, (gc.Cell*?)entry.value)

## Ported from Libraries/LibWeb/Bindings/Intrinsics.h:92 Web::Bindings::Intrinsics::create_web_namespace:
## generated per namespace by the bindings generator (phase 3).
pub func bind_intrinsics_create_web_namespace[TNamespaceType](this: BindIntrinsics*, realm: Realm*):
    trap("unported (P3): Web::Bindings::Intrinsics::create_web_namespace")

## Ported from Libraries/LibWeb/Bindings/Intrinsics.cpp:28 Web::Bindings::host_defined_intrinsics.
pub func bind_host_defined_intrinsics(realm: Realm*) -> BindIntrinsics*:
    let host_defined = realm_host_defined(realm) else trap("ASSERT: realm.host_defined()")
    return host_defined.intrinsics

## Ported from Libraries/LibWeb/Bindings/Intrinsics.h:107 Web::Bindings::ensure_web_namespace.
pub func bind_ensure_web_namespace[T](realm: Realm*, namespace_name: ak.FlyString) -> JsObject*:
    return bind_intrinsics_ensure_web_namespace[T](bind_host_defined_intrinsics(realm), namespace_name)

## Ported from Libraries/LibWeb/Bindings/Intrinsics.h:113 Web::Bindings::ensure_web_prototype.
pub func bind_ensure_web_prototype[T](realm: Realm*, class_name: ak.FlyString) -> JsObject*:
    return bind_intrinsics_ensure_web_prototype[T](bind_host_defined_intrinsics(realm), class_name)

## Ported from Libraries/LibWeb/Bindings/Intrinsics.h:119 Web::Bindings::ensure_web_constructor.
pub func bind_ensure_web_constructor[T](realm: Realm*, class_name: ak.FlyString) -> JsNativeFunction*:
    return bind_intrinsics_ensure_web_constructor[T](bind_host_defined_intrinsics(realm), class_name)

# mark: Traits<UnforgeableKey> ==================================================================

## Ported from Libraries/LibWeb/Bindings/Intrinsics.cpp:53 AK::Traits<Web::Bindings::UnforgeableKey>::hash.
pub func bind_unforgeable_key_hash(key: const BindUnforgeableKey*) -> u32:
    return ak.pair_int_hash(ak.pair_int_hash(ak.utf16_fly_string_hash(&key.attribute_name), ak.utf16_fly_string_hash(&key.interface_name)), (u32)key.type_)

## UnforgeableKey::operator== (defaulted, Intrinsics.h:39).
pub func bind_unforgeable_key_equals(a: const BindUnforgeableKey*, b: const BindUnforgeableKey*) -> bool:
    return ak.utf16_fly_string_eq_utf16_fly_string(&a.interface_name, &b.interface_name) and ak.utf16_fly_string_eq_utf16_fly_string(&a.attribute_name, &b.attribute_name) and a.type_ == b.type_