/* * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Web::Fetch::Fetching { // Non-standard wrapper around a possibly pending Infrastructure::Response. // This is needed to fit the asynchronous nature of ResourceLoader into the synchronous expectations // of the Fetch spec - we run 'in parallel' as a deferred_invoke(), which is still on the main thread; // therefore we use callbacks to run portions of the spec that require waiting for an HTTP load. class PendingResponse : public JS::Cell { JS_CELL(PendingResponse, JS::Cell); public: using Callback = JS::SafeFunction)>; [[nodiscard]] static JS::NonnullGCPtr create(JS::VM&, JS::NonnullGCPtr); [[nodiscard]] static JS::NonnullGCPtr create(JS::VM&, JS::NonnullGCPtr, JS::NonnullGCPtr); void when_loaded(Callback); void resolve(JS::NonnullGCPtr); private: PendingResponse(JS::NonnullGCPtr, JS::GCPtr = {}); virtual void visit_edges(JS::Cell::Visitor&) override; void run_callback(); Callback m_callback; JS::NonnullGCPtr m_request; JS::GCPtr m_response; }; }