Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / performance_timeline / performance_entry.lucb

#==============================================================================================
#
#   performance_entry - PerformanceTimeline::PerformanceEntry, its buffer tuples and names
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.cpp (lines 1-29),
#       PerformanceEntryTuple.h (is_full, visit_edges), and the entry type and event names
#       (EntryTypes.cpp, EventNames.cpp) that the resource timing buffer uses.
#
#       Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from EntryTypes.cpp and EventNames.cpp: the names, interned once.
pub func performance_timeline_initialize_strings():
    performance_timeline_entry_types_mark = ak.fly_string_from_str("mark")
    performance_timeline_entry_types_measure = ak.fly_string_from_str("measure")
    performance_timeline_entry_types_resource = ak.fly_string_from_str("resource")
    performance_timeline_event_names_resourcetimingbufferfull = ak.fly_string_from_str("resourcetimingbufferfull")

## Ported from PerformanceEntry.cpp:13 Web::PerformanceTimeline::PerformanceEntry::PerformanceEntry.
pub func performance_timeline_performance_entry_construct(this: PerformanceTimelinePerformanceEntry*, realm: Realm*, name: ak.String, start_time: f64, duration: f64):
    bind_platform_object_construct_realm(this.bind_platform_object(), realm)
    this.m_name = name
    this.m_start_time = start_time
    this.m_duration = duration

## Ported from PerformanceEntry.cpp:23 Web::PerformanceTimeline::PerformanceEntry::initialize (override).
pub func performance_timeline_performance_entry_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.performance_entry)
    js_cell_initialize_impl(base, realm)

## Web::PerformanceTimeline::PerformanceEntry::entry_type (pure virtual).
pub func performance_timeline_performance_entry_entry_type_impl(this: PerformanceTimelinePerformanceEntry*) -> ak.FlyString:
    trap("pure virtual: Web::PerformanceTimeline::PerformanceEntry::entry_type")

## Web::PerformanceTimeline::PerformanceEntry::should_add_entry (pure virtual).
pub func performance_timeline_performance_entry_should_add_entry_impl(this: PerformanceTimelinePerformanceEntry*) -> PerformanceTimelineShouldAddEntry:
    trap("pure virtual: Web::PerformanceTimeline::PerformanceEntry::should_add_entry")

## Ported from PerformanceEntry.h:33 Web::PerformanceTimeline::PerformanceEntry::name.
pub func performance_timeline_performance_entry_name(this: PerformanceTimelinePerformanceEntry*) -> ak.String:
    return this.m_name

## Ported from PerformanceEntryTuple.h:33 Web::PerformanceTimeline::PerformanceEntryTuple::is_full.
## https://www.w3.org/TR/performance-timeline/#dfn-determine-if-a-performance-entry-buffer-is-full
pub func performance_timeline_performance_entry_tuple_is_full(this: PerformanceTimelinePerformanceEntryTuple*) -> bool:
    # 1. Let num current entries be the size of tuple's performance entry buffer.
    let num_current_entries = (u64)ak.vector_size(&this.performance_entry_buffer)

    # 2. If num current entries is less than tuples's maxBufferSize, return false.
    let max_buffer_size = this.max_buffer_size else return false
    if num_current_entries < max_buffer_size:
        return false

    # 3. Increase tuple's dropped entries count by 1.
    this.dropped_entries_count += 1

    # 4. Return true.
    return true

## Ported from PerformanceEntryTuple.h:47 Web::PerformanceTimeline::PerformanceEntryTuple::visit_edges.
pub func performance_timeline_performance_entry_tuple_visit_edges(this: PerformanceTimelinePerformanceEntryTuple*, visitor: gc.CellVisitor*):
    for entry in ak.vector_span(&this.performance_entry_buffer):
        gc.cell_visitor_visit_t(visitor, entry)