Serenity Operating System
at master 56 lines 2.2 kB view raw
1/* 2 * Copyright (c) 2022, Linus Groh <linusg@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibJS/Heap/Heap.h> 8#include <LibJS/Runtime/VM.h> 9#include <LibWeb/Fetch/Infrastructure/FetchParams.h> 10#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h> 11 12namespace Web::Fetch::Infrastructure { 13 14FetchParams::FetchParams(JS::NonnullGCPtr<Request> request, JS::NonnullGCPtr<FetchAlgorithms> algorithms, JS::NonnullGCPtr<FetchController> controller, JS::NonnullGCPtr<FetchTimingInfo> timing_info) 15 : m_request(request) 16 , m_algorithms(algorithms) 17 , m_controller(controller) 18 , m_timing_info(timing_info) 19{ 20} 21 22JS::NonnullGCPtr<FetchParams> FetchParams::create(JS::VM& vm, JS::NonnullGCPtr<Request> request, JS::NonnullGCPtr<FetchTimingInfo> timing_info) 23{ 24 auto algorithms = Infrastructure::FetchAlgorithms::create(vm, {}); 25 auto controller = Infrastructure::FetchController::create(vm); 26 return vm.heap().allocate_without_realm<FetchParams>(request, algorithms, controller, timing_info); 27} 28 29void FetchParams::visit_edges(JS::Cell::Visitor& visitor) 30{ 31 Base::visit_edges(visitor); 32 visitor.visit(m_request); 33 visitor.visit(m_algorithms); 34 visitor.visit(m_controller); 35 visitor.visit(m_timing_info); 36 if (m_task_destination.has<JS::NonnullGCPtr<JS::Object>>()) 37 visitor.visit(m_task_destination.get<JS::NonnullGCPtr<JS::Object>>()); 38 if (m_preloaded_response_candidate.has<JS::NonnullGCPtr<Response>>()) 39 visitor.visit(m_preloaded_response_candidate.get<JS::NonnullGCPtr<Response>>()); 40} 41 42// https://fetch.spec.whatwg.org/#fetch-params-aborted 43bool FetchParams::is_aborted() const 44{ 45 // A fetch params fetchParams is aborted if its controller’s state is "aborted". 46 return m_controller->state() == FetchController::State::Aborted; 47} 48 49// https://fetch.spec.whatwg.org/#fetch-params-canceled 50bool FetchParams::is_canceled() const 51{ 52 // A fetch params fetchParams is canceled if its controller’s state is "aborted" or "terminated". 53 return m_controller->state() == FetchController::State::Aborted || m_controller->state() == FetchController::State::Terminated; 54} 55 56}