Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / bindings / platform_object.lucb

#==============================================================================================
#
#   platform_object - Bindings::PlatformObject: the base of every object exposed through WebIDL
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/Bindings/PlatformObject.cpp (lines 1-512) and
#       PlatformObject.h (lines 1-131). A platform object is a cell, not a JS object (DESIGN.md
#       §3.6): it keeps its realm (JS::Object reaches it through its shape) and the slot of its
#       one JS wrapper, which phase 3 creates lazily. The legacy platform object algorithms
#       ([[GetOwnProperty]], [[Set]], [[DefineOwnProperty]], [[Delete]], [[PreventExtensions]],
#       [[OwnPropertyKeys]] and named-property visibility) are internal methods of the wrapper
#       and operate on JS property keys and descriptors: they come with luce-js in phase 3. The
#       defaults of the indexed and named property hooks, which interfaces override, are here.
#       WEB_SET_PROTOTYPE_FOR_INTERFACE (Intrinsics.h) is web_set_prototype_for_interface.
#
#       Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: Construction and the realm ==============================================================

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:16 Web::Bindings::PlatformObject::PlatformObject:
## JS::Object(realm, nullptr, may_interfere_with_indexed_property_access). The object has no
## prototype and no wrapper yet; the indexed-access flag is a property of the JS object (phase 3).
pub func bind_platform_object_construct_realm(this: BindPlatformObject*, realm: Realm*, may_interfere_with_indexed_property_access: JsObjectMayInterfereWithIndexedPropertyAccess = JsObjectMayInterfereWithIndexedPropertyAccess.no):
    this.m_realm = realm
    this.m_wrapper = js_undefined()

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:21 Web::Bindings::PlatformObject::PlatformObject:
## JS::Object(ConstructWithPrototypeTag::Tag, prototype, ...), whose realm is the prototype's: a
## JS object (phase 3).
pub func bind_platform_object_construct_js_object(this: BindPlatformObject*, prototype: JsObject*, may_interfere_with_indexed_property_access: JsObjectMayInterfereWithIndexedPropertyAccess = JsObjectMayInterfereWithIndexedPropertyAccess.no):
    trap("unported (P3): Web::Bindings::PlatformObject::PlatformObject(JS::Object& prototype)")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:28 Web::Bindings::PlatformObject::realm.
pub func bind_platform_object_realm(this: BindPlatformObject*) -> Realm*:
    # return shape().realm();
    return this.m_realm

## JS::Object::visit_edges, which PlatformObject inherits: the shape (here the realm) and, from
## phase 3, the wrapper (DESIGN.md §3.6). Every platform object's visit_edges reaches it as its
## Base::visit_edges.
pub func bind_platform_object_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (BindPlatformObject*)base
    gc.cell_visit_edges_impl(base, visitor)
    gc.cell_visitor_visit_t_2(visitor, this.m_realm)

## `JS::Value(platform_object)`: a platform object as a JS value. Before phase 3 the JS objects
## LibWeb meets are cells, so the value holds the cell itself (js_value_from_object, region r19's
## form, which the phase-1 promises and sets carry, DESIGN.md §3.6); phase 3 maps it to its JS
## wrapper, created lazily with its interface's prototype by the bindings.
pub func bind_platform_object_wrapper(this: BindPlatformObject*) -> JsValue:
    return js_value_from_object((JsObject*)this)

## WEB_SET_PROTOTYPE_FOR_INTERFACE(interface_name) (Libraries/LibWeb/Bindings/Intrinsics.h:19),
## the first step of every platform object's initialize: `if (!shape().prototype())
## set_prototype(&ensure_web_prototype<interface_name##Prototype>(realm, name))`. The prototype
## belongs to the JS wrapper, which phase 3 creates with its interface's prototype from the
## realm's intrinsics (DESIGN.md §3.6), so before then there is nothing to set.
pub func web_set_prototype_for_interface(this: JsCell*, realm: Realm*, interface_name: BindInterfaceName):
    return

# mark: Interfaces ==============================================================================

## Ported from Libraries/LibWeb/Bindings/PlatformObject.h:45 Web::Bindings::PlatformObject::implements_interface (virtual).
## https://webidl.spec.whatwg.org/#implements
## This is implemented by overrides that get generated by the WEB_PLATFORM_OBJECT macro.
pub func bind_platform_object_implements_interface_impl(this: BindPlatformObject*, arg0: ak.String) -> bool:
    return false

## Ported from Libraries/LibWeb/Bindings/PlatformObject.h:48 Web::Bindings::PlatformObject::interface_name (virtual).
## Generated by overrides by the WEB_PLATFORM_OBJECT macro. Only valid on platform objects that
## are exposed over IDL.
pub func bind_platform_object_interface_name_impl(this: BindPlatformObject*) -> BindInterfaceName:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.h:62 Web::Bindings::PlatformObject::extract_an_origin (virtual).
## https://html.spec.whatwg.org/multipage/browsers.html#extract-an-origin
## Platform objects have an extract an origin operation, which returns null unless otherwise specified.
pub func bind_platform_object_extract_an_origin_impl(this: BindPlatformObject*) -> web_url.Origin?:
    return none

## Ported from Libraries/LibWeb/Bindings/PlatformObject.h:124 Web::Bindings::PlatformObject::eligible_for_own_property_enumeration_fast_path (virtual).
pub func bind_platform_object_eligible_for_own_property_enumeration_fast_path_impl(this: BindPlatformObject*) -> bool:
    return false

# mark: Legacy platform objects (the wrapper's internal methods, phase 3) =======================

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:34 Web::Bindings::PlatformObject::is_named_property_exposed_on_object.
## https://webidl.spec.whatwg.org/#dfn-named-property-visibility
pub func bind_platform_object_is_named_property_exposed_on_object(this: BindPlatformObject*, property_key: JsPropertyKey) -> bool!:
    trap("unported (P3): Web::Bindings::PlatformObject::is_named_property_exposed_on_object (JS property keys and prototypes)")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:80 Web::Bindings::PlatformObject::legacy_platform_object_get_own_property.
## https://webidl.spec.whatwg.org/#LegacyPlatformObjectGetOwnProperty
pub func bind_platform_object_legacy_platform_object_get_own_property(this: BindPlatformObject*, property_name: JsPropertyKey, ignore_named_props: BindPlatformObjectIgnoreNamedProps) -> (JsPropertyDescriptor?)!:
    trap("unported (P3): Web::Bindings::PlatformObject::legacy_platform_object_get_own_property (JS property descriptors)")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:154 Web::Bindings::PlatformObject::invoke_indexed_property_setter.
## https://webidl.spec.whatwg.org/#invoke-indexed-setter
pub func bind_platform_object_invoke_indexed_property_setter(this: BindPlatformObject*, property_name: JsPropertyKey, value: JsValue) -> !:
    # 1. Let index be the result of calling ? ToUint32(P): property_name.as_number(), a JS
    #    property key (phase 3). Steps 2-7 are invoke_named_property_setter's, by index.
    trap("unported (P3): Web::Bindings::PlatformObject::invoke_indexed_property_setter (JS property keys)")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:182 Web::Bindings::PlatformObject::invoke_named_property_setter.
## https://webidl.spec.whatwg.org/#invoke-named-setter
pub func bind_platform_object_invoke_named_property_setter(this: BindPlatformObject*, property_name: ak.FlyString, value: JsValue) -> !:
    # 1. Let creating be true if P is not a supported property name, and false otherwise.
    let creating = not bind_platform_object_is_supported_property_name(this, property_name)

    # FIXME: We do not have this information at this point, so converting the value is left as an exercise to the inheritor of PlatformObject.
    # 2. Let operation be the operation used to declare the indexed property setter.
    # 3. Let T be the type of the second argument of operation.
    # 4. Let value be the result of converting V to an IDL value of type T.

    let flags = this.m_legacy_platform_object_flags else trap("PlatformObject: no legacy platform object flags")

    # 5. If operation was defined without an identifier, then:
    if flags.named_property_setter_has_identifier == 0:
        # 1. If creating is true, then perform the steps listed in the interface description to set the value of a new named property with P as the name and value as the value.
        if creating:
            return try bind_platform_object_set_value_of_new_named_property(this, ak.fly_string_to_string_const(&property_name), value)

        # 2. Otherwise, creating is false. Perform the steps listed in the interface description to set the value of an existing named property with P as the name and value as the value.
        return try bind_platform_object_set_value_of_existing_named_property(this, ak.fly_string_to_string_const(&property_name), value)

    # 6. Otherwise, operation was defined with an identifier. Perform the method steps of operation with O as this and « P, value » as the argument values.
    return try bind_platform_object_set_value_of_named_property(this, ak.fly_string_to_string_const(&property_name), value)

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:207 Web::Bindings::PlatformObject::internal_get_own_property (virtual).
## https://webidl.spec.whatwg.org/#legacy-platform-object-getownproperty
pub func bind_platform_object_internal_get_own_property_impl(this: BindPlatformObject*, property_name: JsPropertyKey) -> (JsPropertyDescriptor?)!:
    trap("unported (P3): Web::Bindings::PlatformObject::internal_get_own_property (the wrapper's [[GetOwnProperty]])")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:218 Web::Bindings::PlatformObject::internal_set (virtual).
## https://webidl.spec.whatwg.org/#legacy-platform-object-set
pub func bind_platform_object_internal_set_impl(this: BindPlatformObject*, property_name: JsPropertyKey, value: JsValue, receiver: JsValue, metadata: JsCacheableSetPropertyMetadata*?, phase: JsObjectPropertyLookupPhase) -> bool!:
    trap("unported (P3): Web::Bindings::PlatformObject::internal_set (the wrapper's [[Set]])")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:257 Web::Bindings::PlatformObject::internal_define_own_property (virtual).
## https://webidl.spec.whatwg.org/#legacy-platform-object-defineownproperty
pub func bind_platform_object_internal_define_own_property_impl(this: BindPlatformObject*, property_name: JsPropertyKey, property_descriptor: JsPropertyDescriptor*, precomputed_get_own_property: (JsPropertyDescriptor?)*?) -> bool!:
    trap("unported (P3): Web::Bindings::PlatformObject::internal_define_own_property (the wrapper's [[DefineOwnProperty]])")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:326 Web::Bindings::PlatformObject::internal_delete (virtual).
## https://webidl.spec.whatwg.org/#legacy-platform-object-delete
pub func bind_platform_object_internal_delete_impl(this: BindPlatformObject*, property_name: JsPropertyKey) -> bool!:
    trap("unported (P3): Web::Bindings::PlatformObject::internal_delete (the wrapper's [[Delete]])")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:394 Web::Bindings::PlatformObject::internal_prevent_extensions (virtual).
## https://webidl.spec.whatwg.org/#legacy-platform-object-preventextensions
pub func bind_platform_object_internal_prevent_extensions_impl(this: BindPlatformObject*) -> bool!:
    trap("unported (P3): Web::Bindings::PlatformObject::internal_prevent_extensions (the wrapper's [[PreventExtensions]])")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:405 Web::Bindings::PlatformObject::internal_own_property_keys (virtual).
## https://webidl.spec.whatwg.org/#legacy-platform-object-ownpropertykeys
pub func bind_platform_object_internal_own_property_keys_impl(this: BindPlatformObject*) -> ak.Vector[JsValue]!:
    trap("unported (P3): Web::Bindings::PlatformObject::internal_own_property_keys (the wrapper's [[OwnPropertyKeys]])")

# mark: Indexed and named property hooks ========================================================

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:452 Web::Bindings::PlatformObject::set_value_of_new_named_property (virtual).
## NOTE: These will crash if you make has_named_property_setter return true but do not override
## these methods. This is only used if named_property_setter_has_identifier returns false,
## otherwise set_value_of_named_property is used instead.
pub func bind_platform_object_set_value_of_new_named_property_impl(this: BindPlatformObject*, arg0: ak.String, arg1: JsValue) -> !:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:457 Web::Bindings::PlatformObject::set_value_of_existing_named_property (virtual).
pub func bind_platform_object_set_value_of_existing_named_property_impl(this: BindPlatformObject*, arg0: ak.String, arg1: JsValue) -> !:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:462 Web::Bindings::PlatformObject::set_value_of_named_property (virtual).
## NOTE: This is only used if you make named_property_setter_has_identifier return true,
## otherwise set_value_of_{new,existing}_named_property is used instead.
pub func bind_platform_object_set_value_of_named_property_impl(this: BindPlatformObject*, arg0: ak.String, arg1: JsValue) -> !:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:467 Web::Bindings::PlatformObject::set_value_of_new_indexed_property (virtual).
## NOTE: This is only used if indexed_property_setter_has_identifier returns false, otherwise
## set_value_of_indexed_property is used instead.
pub func bind_platform_object_set_value_of_new_indexed_property_impl(this: BindPlatformObject*, arg0: u32, arg1: JsValue) -> !:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:472 Web::Bindings::PlatformObject::set_value_of_existing_indexed_property (virtual).
pub func bind_platform_object_set_value_of_existing_indexed_property_impl(this: BindPlatformObject*, arg0: u32, arg1: JsValue) -> !:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:477 Web::Bindings::PlatformObject::set_value_of_indexed_property (virtual).
## NOTE: This is only used if indexed_property_setter_has_identifier returns true, otherwise
## set_value_of_{new,existing}_indexed_property is used instead.
pub func bind_platform_object_set_value_of_indexed_property_impl(this: BindPlatformObject*, arg0: u32, arg1: JsValue) -> !:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:482 Web::Bindings::PlatformObject::delete_value (virtual).
## NOTE: This will crash if you make has_named_property_deleter return true but do not override this method.
pub func bind_platform_object_delete_value_impl(this: BindPlatformObject*, arg0: ak.String) -> BindPlatformObjectDidDeletionFail!:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:487 Web::Bindings::PlatformObject::item_value (virtual).
pub func bind_platform_object_item_value_impl(this: BindPlatformObject*, index: usize) -> JsValue?:
    return none

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:492 Web::Bindings::PlatformObject::named_item_value (virtual).
pub func bind_platform_object_named_item_value_impl(this: BindPlatformObject*, name: ak.FlyString) -> JsValue:
    return js_undefined()

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:497 Web::Bindings::PlatformObject::supported_property_names (virtual).
pub func bind_platform_object_supported_property_names_impl(this: BindPlatformObject*) -> ak.Vector[ak.FlyString]:
    return ak.Vector[ak.FlyString]()

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:502 Web::Bindings::PlatformObject::is_supported_property_name (virtual).
pub func bind_platform_object_is_supported_property_name_impl(this: BindPlatformObject*, name: ak.FlyString) -> bool:
    let names = bind_platform_object_supported_property_names(this)
    return ak.vector_contains_slow[ak.FlyString, ak.FlyStringTraits](&names, name)

## Ported from Libraries/LibWeb/Bindings/PlatformObject.cpp:507 Web::Bindings::PlatformObject::is_supported_property_index.
pub func bind_platform_object_is_supported_property_index(this: BindPlatformObject*, index: u32) -> bool:
    return bind_platform_object_item_value(this, (usize)index) != none