Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / webview / roots.lucb

#==============================================================================================
#
#   roots - C-heap memory the collector scans
#
#   DESCRIPTION:
#       What the embedding keeps for the life of the process or of a view (the event loop, a
#       view's state) lives in the C heap, where the collector does not look, yet it refers to
#       managed values: the loop's timer list and deferred queue, a view's page client, the
#       URL and title it last heard. A root region is LibGC's ConservativeVector used the way
#       LibJS keeps its values outside the heap: a registered vector whose words are possible
#       pointers, here the words of the region itself, so everything it points at stays alive
#       for as long as the region is registered (DESIGN.md ยง3.3 rule 4).
#
#       Copyright (c) 2026 the luce-browser authors.
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## A registered region: GC::ConservativeVectorBase first, then the words it lends the scan.
struct WebViewRootRegion:
    var base: gc.ConservativeVectorBase
    var words: const u64[]

## The regions' vtable: their possible values are the region's words.
let webview_root_region_vtable: gc.ConservativeVectorBaseVTable = gc.ConservativeVectorBaseVTable(class_info = &gc.conservative_vector_base_class,
                                                                                                  possible_values = webview_root_region_possible_values)

func webview_root_region_possible_values(this: gc.ConservativeVectorBase*) -> const u64[]:
    return ((WebViewRootRegion*)this).words

## Registers the `size` bytes at `start` (C-heap memory, 8-byte aligned, that outlives the
## registration) with `heap` as possible pointers. Answers the registration, for
## webview_root_region_destroy.
pub func webview_root_region_create(heap: gc.Heap*, start: const void*, size: usize) -> WebViewRootRegion*:
    with memory.heap:
        let words: const u64[] = u64[]((u64*)(void*)start, size // 8)
        let region = new WebViewRootRegion(base = gc.ConservativeVectorBase(vtable = &webview_root_region_vtable, class_id = 0, m_heap = none, m_list_node = gc.ListNode()),
                                           words = words) else trap("out of memory")
        gc.conservative_vector_base_construct(&region.base, heap)
        return region

## Unregisters `region` and frees it (not the memory it lent).
pub func webview_root_region_destroy(region: WebViewRootRegion*):
    gc.conservative_vector_base_destroy(&region.base)
    free(region) in memory.heap