/* * Copyright (c) 2023, Matthew Olsson * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include namespace Web::Streams { // https://streams.spec.whatwg.org/#generic-reader-closed WebIDL::ExceptionOr> ReadableStreamGenericReaderMixin::closed() { // 1. Return this.[[closedPromise]]. return JS::GCPtr { verify_cast(*m_closed_promise->promise()) }; } // https://streams.spec.whatwg.org/#generic-reader-cancel WebIDL::ExceptionOr> ReadableStreamGenericReaderMixin::cancel(JS::Value reason) { // 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception. if (!m_stream) { auto& realm = stream()->realm(); auto promise_capability = WebIDL::create_rejected_promise(realm, TRY(JS::TypeError::create(realm, "No stream present to cancel"sv))); return JS::NonnullGCPtr { verify_cast(*promise_capability->promise().ptr()) }; } // 2. Return ! ReadableStreamReaderGenericCancel(this, reason). auto promise_capability = readable_stream_reader_generic_cancel(*this, reason); return JS::NonnullGCPtr { verify_cast(*promise_capability->promise().ptr()) }; } void ReadableStreamGenericReaderMixin::visit_edges(JS::Cell::Visitor& visitor) { visitor.visit(m_closed_promise); visitor.visit(m_stream); } }