Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / window_proxy.lucb

#==============================================================================================
#
#   window_proxy - HTML::WindowProxy: the exotic object that is a browsing context's global
#   this value and forwards to its current Window
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/WindowProxy.cpp (lines 1-282) with the inline functions
#       of WindowProxy.h. The exotic object's internal methods ([[GetOwnProperty]] and the rest)
#       work on JS property keys and descriptors, which only a script reaches: they come with
#       the JS objects in phase 3 and trap until then. The two that answer a constant are
#       ported, as are the [[Window]] slot and the associated browsing context.
#
#       Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: Construction ============================================================================

## Ported from WindowProxy.cpp:28 Web::HTML::WindowProxy::WindowProxy.
# 7.4 The WindowProxy exotic object, https://html.spec.whatwg.org/multipage/window-object.html#the-windowproxy-exotic-object
pub func html_window_proxy_construct(this: HtmlWindowProxy*, realm: Realm*):
    dom_event_target_construct(this.dom_event_target(), realm, JsObjectMayInterfereWithIndexedPropertyAccess.yes)

# mark: The exotic object's internal methods ====================================================

## Ported from WindowProxy.cpp:34 Web::HTML::WindowProxy::internal_get_prototype_of (virtual).
# 7.4.1 [[GetPrototypeOf]] ( ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-getprototypeof
pub func html_window_proxy_internal_get_prototype_of_impl(this: HtmlWindowProxy*) -> JsObject*?!:
    # 1. Let W be the value of the [[Window]] internal slot of this.
    # 2. If IsPlatformObjectSameOrigin(W) is true, then return ! OrdinaryGetPrototypeOf(W).
    # 3. Return null.
    trap("unported (P3): Web::HTML::WindowProxy::internal_get_prototype_of (OrdinaryGetPrototypeOf)")

## Ported from WindowProxy.cpp:47 Web::HTML::WindowProxy::internal_set_prototype_of (virtual).
# 7.4.2 [[SetPrototypeOf]] ( V ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-setprototypeof
pub func html_window_proxy_internal_set_prototype_of_impl(this: HtmlWindowProxy*, prototype: JsObject*?) -> bool!:
    # 1. Return ! SetImmutablePrototype(this, V).
    trap("unported (P3): Web::HTML::WindowProxy::internal_set_prototype_of (SetImmutablePrototype)")

## Ported from WindowProxy.cpp:54 Web::HTML::WindowProxy::internal_is_extensible (virtual).
# 7.4.3 [[IsExtensible]] ( ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-isextensible
pub func html_window_proxy_internal_is_extensible_impl(this: HtmlWindowProxy*) -> bool!:
    # 1. Return true.
    return true

## Ported from WindowProxy.cpp:61 Web::HTML::WindowProxy::internal_prevent_extensions (override).
# 7.4.4 [[PreventExtensions]] ( ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-preventextensions
pub func html_window_proxy_internal_prevent_extensions_impl(base: BindPlatformObject*) -> bool!:
    # 1. Return false.
    return false

## Ported from WindowProxy.cpp:68 Web::HTML::WindowProxy::internal_get_own_property (override).
# 7.4.5 [[GetOwnProperty]] ( P ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-getownproperty
pub func html_window_proxy_internal_get_own_property_impl(base: BindPlatformObject*, property_key: JsPropertyKey) -> (JsPropertyDescriptor?)!:
    # Steps 1-7: index properties name the document-tree child navigables' WindowProxies, the rest
    # forward to the Window's ordinary or cross-origin [[GetOwnProperty]] (JS property keys and
    # descriptors).
    trap("unported (P3): Web::HTML::WindowProxy::internal_get_own_property")

## Ported from WindowProxy.cpp:138 Web::HTML::WindowProxy::internal_define_own_property (override).
# 7.4.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-defineownproperty
pub func html_window_proxy_internal_define_own_property_impl(base: BindPlatformObject*, property_key: JsPropertyKey, descriptor: JsPropertyDescriptor*, precomputed_get_own_property: (JsPropertyDescriptor?)*?) -> bool!:
    # Steps 1-3: refuse index properties, forward the rest to the Window's
    # [[DefineOwnProperty]] when same origin, else throw a SecurityError (JS property keys).
    trap("unported (P3): Web::HTML::WindowProxy::internal_define_own_property")

## Ported from WindowProxy.cpp:159 Web::HTML::WindowProxy::internal_get (virtual).
# 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-get
pub func html_window_proxy_internal_get_impl(this: HtmlWindowProxy*, property_key: JsPropertyKey, receiver: JsValue, arg2: JsCacheableGetPropertyMetadata*?, arg3: JsObjectPropertyLookupPhase) -> JsValue!:
    # Steps 1-4: OrdinaryGet on the Window when same origin, else CrossOriginGet.
    trap("unported (P3): Web::HTML::WindowProxy::internal_get")

## Ported from WindowProxy.cpp:180 Web::HTML::WindowProxy::internal_set (override).
# 7.4.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-set
pub func html_window_proxy_internal_set_impl(base: BindPlatformObject*, property_key: JsPropertyKey, value: JsValue, receiver: JsValue, arg3: JsCacheableSetPropertyMetadata*?, arg4: JsObjectPropertyLookupPhase) -> bool!:
    # Steps 1-4: OrdinarySet on the Window when same origin, else CrossOriginSet.
    trap("unported (P3): Web::HTML::WindowProxy::internal_set")

## Ported from WindowProxy.cpp:205 Web::HTML::WindowProxy::internal_delete (override).
# 7.4.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-delete
pub func html_window_proxy_internal_delete_impl(base: BindPlatformObject*, property_key: JsPropertyKey) -> bool!:
    # Steps 1-4: index properties of existing child navigables cannot be deleted, the rest forward
    # to OrdinaryDelete on the Window when same origin, else throw a SecurityError.
    trap("unported (P3): Web::HTML::WindowProxy::internal_delete")

## Ported from WindowProxy.cpp:233 Web::HTML::WindowProxy::internal_own_property_keys (override).
# 7.4.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-ownpropertykeys
pub func html_window_proxy_internal_own_property_keys_impl(base: BindPlatformObject*) -> ak.Vector[JsValue]!:
    # Steps 1-7: the child navigables' indices as strings, then the Window's ordinary or
    # cross-origin own property keys (JS property keys).
    trap("unported (P3): Web::HTML::WindowProxy::internal_own_property_keys")

# mark: The [[Window]] slot =====================================================================

## Ported from WindowProxy.cpp:266 Web::HTML::WindowProxy::visit_edges (override).
pub func html_window_proxy_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (HtmlWindowProxy*)base
    dom_event_target_visit_edges_impl(base, visitor)
    gc.cell_visitor_visit_t(visitor, this.m_window)

## Ported from WindowProxy.cpp:272 Web::HTML::WindowProxy::set_window.
pub func html_window_proxy_set_window(this: HtmlWindowProxy*, window: HtmlWindow*):
    this.m_window = window

## Ported from WindowProxy.cpp:277 Web::HTML::WindowProxy::associated_browsing_context.
pub func html_window_proxy_associated_browsing_context(this: HtmlWindowProxy*) -> HtmlBrowsingContext*:
    return dom_document_browsing_context(html_window_associated_document(this.m_window else trap("no window"))) else trap("no browsing context")

## Ported from WindowProxy.h:37 Web::HTML::WindowProxy::window.
pub func html_window_proxy_window(this: HtmlWindowProxy*) -> HtmlWindow*?:
    return this.m_window

## Ported from WindowProxy.h:45 Web::HTML::WindowProxy::is_universal_global_scope_mixin (override).
pub func html_window_proxy_is_universal_global_scope_mixin_impl(base: DomEventTarget*) -> bool:
    return true

## Ported from WindowProxy.h:47 Web::HTML::WindowProxy::is_html_window_proxy (virtual).
pub func html_window_proxy_is_html_window_proxy_impl(this: HtmlWindowProxy*) -> bool:
    return true