Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / event_handler.lucb

#==============================================================================================
#
#   event_handler - HTML::EventHandler: the value and listener of an event handler
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/EventHandler.cpp (lines 1-37) and EventHandler.h. The
#       class was outside the skeleton's phase-1 closure; region r19 ported it because
#       DOM::EventTarget's event handler map holds these cells.
#
#       Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## heap.allocate<HTML::EventHandler>(...): a cell of EventHandler's own allocator, for the
## constructor to fill under DeferGC (LibGC's Heap::allocate, DESIGN.md ยง2.3). The caller
## constructs it and then calls gc.heap_undefer_gc.
func heap_allocate_html_event_handler(heap: gc.Heap*) -> HtmlEventHandler*:
    let this = (HtmlEventHandler*)web_heap_allocate_cell(heap, &html_event_handler_class)
    gc.heap_defer_gc(heap)
    return this

## heap.allocate<HTML::EventHandler>(ByteString).
pub func heap_allocate_html_event_handler_byte_string(heap: gc.Heap*, s: ak.ByteString) -> HtmlEventHandler*:
    let this = heap_allocate_html_event_handler(heap)
    html_event_handler_construct_byte_string(this, s)
    gc.heap_undefer_gc(heap)
    return this

## heap.allocate<HTML::EventHandler>(WebIDL::CallbackType&).
pub func heap_allocate_html_event_handler_callback_type(heap: gc.Heap*, c: IdlCallbackType*) -> HtmlEventHandler*:
    let this = heap_allocate_html_event_handler(heap)
    html_event_handler_construct_callback_type(this, c)
    gc.heap_undefer_gc(heap)
    return this

## Ported from Libraries/LibWeb/HTML/EventHandler.cpp:15 Web::HTML::EventHandler::EventHandler(ByteString).
pub func html_event_handler_construct_byte_string(this: HtmlEventHandler*, s: ak.ByteString):
    this.value = .byte_string(s)

## Ported from Libraries/LibWeb/HTML/EventHandler.cpp:20 Web::HTML::EventHandler::EventHandler(WebIDL::CallbackType&).
pub func html_event_handler_construct_callback_type(this: HtmlEventHandler*, c: IdlCallbackType*):
    this.value = .idl_callback_type(c)

## Ported from Libraries/LibWeb/HTML/EventHandler.cpp:25 Web::HTML::EventHandler::visit_edges (override).
pub func html_event_handler_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (HtmlEventHandler*)base
    gc.cell_visit_edges_impl(base, visitor)
    gc.cell_visitor_visit_t(visitor, this.listener)

    match this.value:
        .idl_callback_type(callback):
            gc.cell_visitor_visit_t(visitor, callback)
        .byte_string(_):
            return

## GC_CELL(EventHandler, JS::Cell)'s class_name.
func html_event_handler_class_name_impl(this: gc.Cell*) -> ak.StringView:
    return ak.sv("EventHandler")