/* * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include namespace Web::Fetch::Infrastructure { FetchParams::FetchParams(JS::NonnullGCPtr request, JS::NonnullGCPtr algorithms, JS::NonnullGCPtr controller, JS::NonnullGCPtr timing_info) : m_request(request) , m_algorithms(algorithms) , m_controller(controller) , m_timing_info(timing_info) { } JS::NonnullGCPtr FetchParams::create(JS::VM& vm, JS::NonnullGCPtr request, JS::NonnullGCPtr timing_info) { auto algorithms = Infrastructure::FetchAlgorithms::create(vm, {}); auto controller = Infrastructure::FetchController::create(vm); return vm.heap().allocate_without_realm(request, algorithms, controller, timing_info); } void FetchParams::visit_edges(JS::Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_request); visitor.visit(m_algorithms); visitor.visit(m_controller); visitor.visit(m_timing_info); if (m_task_destination.has>()) visitor.visit(m_task_destination.get>()); if (m_preloaded_response_candidate.has>()) visitor.visit(m_preloaded_response_candidate.get>()); } // https://fetch.spec.whatwg.org/#fetch-params-aborted bool FetchParams::is_aborted() const { // A fetch params fetchParams is aborted if its controller’s state is "aborted". return m_controller->state() == FetchController::State::Aborted; } // https://fetch.spec.whatwg.org/#fetch-params-canceled bool FetchParams::is_canceled() const { // A fetch params fetchParams is canceled if its controller’s state is "aborted" or "terminated". return m_controller->state() == FetchController::State::Aborted || m_controller->state() == FetchController::State::Terminated; } }