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_ReadableStreamGenericReader_h
8 #define mozilla_dom_ReadableStreamGenericReader_h
10 #include "mozilla/dom/Promise.h"
11 #include "mozilla/dom/ReadableStreamDefaultReaderBinding.h"
12 #include "nsISupports.h"
13 #include "nsCycleCollectionParticipant.h"
15 namespace mozilla::dom
{
18 class ReadableStreamDefaultReader
;
19 class ReadableStreamBYOBReader
;
21 // Base class for internal slots of readable stream readers
22 class ReadableStreamGenericReader
: public nsISupports
{
24 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
25 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ReadableStreamGenericReader
)
27 explicit ReadableStreamGenericReader(nsCOMPtr
<nsIGlobalObject
> aGlobal
)
28 : mGlobal(std::move(aGlobal
)) {}
30 nsIGlobalObject
* GetParentObject() const { return mGlobal
; }
32 virtual bool IsDefault() = 0;
33 virtual bool IsBYOB() = 0;
34 virtual ReadableStreamDefaultReader
* AsDefault() = 0;
35 virtual ReadableStreamBYOBReader
* AsBYOB() = 0;
37 Promise
* ClosedPromise() { return mClosedPromise
; }
38 void SetClosedPromise(already_AddRefed
<Promise
>&& aClosedPromise
) {
39 mClosedPromise
= aClosedPromise
;
42 ReadableStream
* GetStream() { return mStream
; }
43 void SetStream(already_AddRefed
<ReadableStream
>&& aStream
) {
46 void SetStream(ReadableStream
* aStream
) {
47 RefPtr
<ReadableStream
> stream(aStream
);
48 SetStream(stream
.forget());
52 already_AddRefed
<Promise
> Closed() const;
54 MOZ_CAN_RUN_SCRIPT already_AddRefed
<Promise
> Cancel(
55 JSContext
* aCx
, JS::Handle
<JS::Value
> aReason
, ErrorResult
& aRv
);
58 virtual ~ReadableStreamGenericReader() = default;
60 nsCOMPtr
<nsIGlobalObject
> mGlobal
;
61 RefPtr
<Promise
> mClosedPromise
;
62 RefPtr
<ReadableStream
> mStream
;
65 namespace streams_abstract
{
67 bool ReadableStreamReaderGenericInitialize(ReadableStreamGenericReader
* aReader
,
68 ReadableStream
* aStream
);
70 void ReadableStreamReaderGenericRelease(ReadableStreamGenericReader
* aReader
,
73 } // namespace streams_abstract
75 } // namespace mozilla::dom