Bug 1806664 - Use python toolchain tasks to build firefox r=glandium,taskgraph-review...
[gecko.git] / dom / streams / ReadableStreamTee.h
blob855fcf42861835f22ca161e3321d5c17566743ba
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ReadableStreamTee_h
8 #define mozilla_dom_ReadableStreamTee_h
10 #include "mozilla/dom/ReadRequest.h"
11 #include "mozilla/dom/ReadableStreamController.h"
12 #include "mozilla/dom/UnderlyingSourceCallbackHelpers.h"
13 #include "nsCycleCollectionParticipant.h"
14 #include "nsISupportsImpl.h"
16 namespace mozilla::dom {
17 struct TeeState;
18 enum class TeeBranch : bool;
19 class ReadableStream;
21 // Implementation of the Pull algorithm steps for ReadableStreamDefaultTee,
22 // from
23 // https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaulttee
24 // Step 12.
25 class ReadableStreamDefaultTeeSourceAlgorithms final
26 : public UnderlyingSourceAlgorithmsBase {
27 public:
28 NS_DECL_ISUPPORTS_INHERITED
29 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(
30 ReadableStreamDefaultTeeSourceAlgorithms, UnderlyingSourceAlgorithmsBase)
32 ReadableStreamDefaultTeeSourceAlgorithms(TeeState* aTeeState,
33 TeeBranch aBranch)
34 : mTeeState(aTeeState), mBranch(aBranch) {}
36 MOZ_CAN_RUN_SCRIPT void StartCallback(JSContext* aCx,
37 ReadableStreamController& aController,
38 JS::MutableHandle<JS::Value> aRetVal,
39 ErrorResult& aRv) override {
40 aRetVal.setUndefined();
43 MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> PullCallback(
44 JSContext* aCx, ReadableStreamController& aController,
45 ErrorResult& aRv) override;
47 MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> CancelCallback(
48 JSContext* aCx, const Optional<JS::Handle<JS::Value>>& aReason,
49 ErrorResult& aRv) override;
51 protected:
52 ~ReadableStreamDefaultTeeSourceAlgorithms() override = default;
54 private:
55 // Virtually const, but is cycle collected
56 MOZ_KNOWN_LIVE RefPtr<TeeState> mTeeState;
57 TeeBranch mBranch;
60 // https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaulttee
61 // Step 12.3
62 struct ReadableStreamDefaultTeeReadRequest final : public ReadRequest {
63 NS_DECL_ISUPPORTS_INHERITED
64 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ReadableStreamDefaultTeeReadRequest,
65 ReadRequest)
67 RefPtr<TeeState> mTeeState;
69 explicit ReadableStreamDefaultTeeReadRequest(TeeState* aTeeState)
70 : mTeeState(aTeeState) {}
72 void ChunkSteps(JSContext* aCx, JS::Handle<JS::Value> aChunk,
73 ErrorResult& aRv) override;
75 MOZ_CAN_RUN_SCRIPT void CloseSteps(JSContext* aCx, ErrorResult& aRv) override;
77 void ErrorSteps(JSContext* aCx, JS::Handle<JS::Value> aError,
78 ErrorResult& aRv) override;
80 protected:
81 ~ReadableStreamDefaultTeeReadRequest() override = default;
84 namespace streams_abstract {
85 MOZ_CAN_RUN_SCRIPT void ReadableByteStreamTee(
86 JSContext* aCx, ReadableStream* aStream,
87 nsTArray<RefPtr<ReadableStream>>& aResult, ErrorResult& aRv);
90 } // namespace mozilla::dom
91 #endif