Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / fetch / infrastructure / fetch_algorithms.lucb

#==============================================================================================
#
#   fetch_algorithms - Fetch::Infrastructure::FetchAlgorithms: the six algorithms a fetch
#   reports to (process request body chunk length, ..., process response consume body)
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp (lines 15-57) with
#       the inline accessors of FetchAlgorithms.h (lines 52-57). FetchAlgorithms::Input is
#       FetchAlgorithmsInput (types_fetch_algorithms): six AK::Functions, each empty unless a
#       caller sets it, so `FetchAlgorithms::create(vm, {})` is
#       `fetch_algorithms_create(vm, FetchAlgorithmsInput())` and C++'s designated initializers
#       are named arguments. The two `create_with_*` helpers name the Inputs most callers build.
#
#       Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp:15 Web::Fetch::Infrastructure::FetchAlgorithms::create.
pub func fetch_algorithms_create(vm: Vm*, input: FetchAlgorithmsInput) -> FetchAlgorithms*:
    let heap = vm_heap(vm)
    let process_request_body_chunk_length = gc.create_function1(heap, input.process_request_body_chunk_length)
    let process_request_end_of_body = gc.create_function0(heap, input.process_request_end_of_body)
    let process_early_hints_response = gc.create_function1(heap, input.process_early_hints_response)
    let process_response = gc.create_function1(heap, input.process_response)
    let process_response_end_of_body = gc.create_function1(heap, input.process_response_end_of_body)
    let process_response_consume_body = gc.create_function2(heap, input.process_response_consume_body)

    # vm.heap().allocate<FetchAlgorithms>(...)
    let algorithms = (FetchAlgorithms*)web_heap_allocate_cell(heap, &fetch_algorithms_class)
    gc.heap_defer_gc(heap)
    fetch_algorithms_construct(algorithms, process_request_body_chunk_length, process_request_end_of_body, process_early_hints_response, process_response, process_response_end_of_body, process_response_consume_body)
    gc.heap_undefer_gc(heap)
    return algorithms

## `FetchAlgorithms::create(vm, { .process_response_consume_body = ... })`.
pub func fetch_algorithms_create_with_process_response_consume_body(vm: Vm*, process_response_consume_body: ak.Function2[FetchResponse*, FetchAlgorithmsBodyBytes, unit]) -> FetchAlgorithms*:
    return fetch_algorithms_create(vm, FetchAlgorithmsInput(process_response_consume_body = process_response_consume_body))

## `FetchAlgorithms::create(vm, { .process_response = ... })`.
pub func fetch_algorithms_create_with_process_response(vm: Vm*, process_response: ak.Function1[FetchResponse*, unit]) -> FetchAlgorithms*:
    return fetch_algorithms_create(vm, FetchAlgorithmsInput(process_response = process_response))

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp:32 Web::Fetch::Infrastructure::FetchAlgorithms::FetchAlgorithms (private).
func fetch_algorithms_construct(this: FetchAlgorithms*, process_request_body_chunk_length: gc.Function1[u64, unit]*, process_request_end_of_body: gc.Function0[unit]*, process_early_hints_response: gc.Function1[FetchResponse*, unit]*, process_response: gc.Function1[FetchResponse*, unit]*, process_response_end_of_body: gc.Function1[FetchResponse*, unit]*, process_response_consume_body: gc.Function2[FetchResponse*, FetchAlgorithmsBodyBytes, unit]*):
    this.m_process_request_body_chunk_length = process_request_body_chunk_length
    this.m_process_request_end_of_body = process_request_end_of_body
    this.m_process_early_hints_response = process_early_hints_response
    this.m_process_response = process_response
    this.m_process_response_end_of_body = process_response_end_of_body
    this.m_process_response_consume_body = process_response_consume_body

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp:48 Web::Fetch::Infrastructure::FetchAlgorithms::visit_edges (override).
pub func fetch_algorithms_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (FetchAlgorithms*)base
    gc.cell_visit_edges_impl(base, visitor)
    gc.cell_visitor_visit_t(visitor, this.m_process_request_body_chunk_length)
    gc.cell_visitor_visit_t(visitor, this.m_process_request_end_of_body)
    gc.cell_visitor_visit_t(visitor, this.m_process_early_hints_response)
    gc.cell_visitor_visit_t(visitor, this.m_process_response)
    gc.cell_visitor_visit_t(visitor, this.m_process_response_end_of_body)
    gc.cell_visitor_visit_t(visitor, this.m_process_response_consume_body)

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h:52 Web::Fetch::Infrastructure::FetchAlgorithms::process_request_body_chunk_length.
pub func fetch_algorithms_process_request_body_chunk_length(this: FetchAlgorithms*) -> ak.Function1[u64, unit]:
    return this.m_process_request_body_chunk_length.function

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h:53 Web::Fetch::Infrastructure::FetchAlgorithms::process_request_end_of_body.
pub func fetch_algorithms_process_request_end_of_body(this: FetchAlgorithms*) -> ak.Function0[unit]:
    return this.m_process_request_end_of_body.function

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h:54 Web::Fetch::Infrastructure::FetchAlgorithms::process_early_hints_response.
pub func fetch_algorithms_process_early_hints_response(this: FetchAlgorithms*) -> ak.Function1[FetchResponse*, unit]:
    return this.m_process_early_hints_response.function

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h:55 Web::Fetch::Infrastructure::FetchAlgorithms::process_response.
pub func fetch_algorithms_process_response(this: FetchAlgorithms*) -> ak.Function1[FetchResponse*, unit]:
    return this.m_process_response.function

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h:56 Web::Fetch::Infrastructure::FetchAlgorithms::process_response_end_of_body.
pub func fetch_algorithms_process_response_end_of_body(this: FetchAlgorithms*) -> ak.Function1[FetchResponse*, unit]:
    return this.m_process_response_end_of_body.function

## Ported from Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h:57 Web::Fetch::Infrastructure::FetchAlgorithms::process_response_consume_body.
pub func fetch_algorithms_process_response_consume_body(this: FetchAlgorithms*) -> ak.Function2[FetchResponse*, FetchAlgorithmsBodyBytes, unit]:
    return this.m_process_response_consume_body.function