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_ReadableStreamBYOBReader_h
8 #define mozilla_dom_ReadableStreamBYOBReader_h
10 #include "js/TypeDecls.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/ErrorResult.h"
13 #include "mozilla/dom/BindingDeclarations.h"
14 #include "mozilla/dom/ReadableStreamGenericReader.h"
15 #include "mozilla/dom/TypedArray.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsWrapperCache.h"
18 #include "mozilla/LinkedList.h"
20 namespace mozilla::dom
{
23 struct ReadIntoRequest
;
25 struct ReadableStreamBYOBReaderReadOptions
;
27 } // namespace mozilla::dom
29 namespace mozilla::dom
{
31 class ReadableStreamBYOBReader final
: public ReadableStreamGenericReader
,
32 public nsWrapperCache
{
34 NS_DECL_ISUPPORTS_INHERITED
35 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS_INHERITED(
36 ReadableStreamBYOBReader
, ReadableStreamGenericReader
)
39 explicit ReadableStreamBYOBReader(nsISupports
* aGlobal
);
41 bool IsDefault() override
{ return false; };
42 bool IsBYOB() override
{ return true; }
43 ReadableStreamDefaultReader
* AsDefault() override
{
44 MOZ_CRASH("Should have verified IsDefault first");
47 ReadableStreamBYOBReader
* AsBYOB() override
{ return this; }
49 JSObject
* WrapObject(JSContext
* aCx
,
50 JS::Handle
<JSObject
*> aGivenProto
) override
;
52 static already_AddRefed
<ReadableStreamBYOBReader
> Constructor(
53 const GlobalObject
& global
, ReadableStream
& stream
, ErrorResult
& rv
);
55 MOZ_CAN_RUN_SCRIPT already_AddRefed
<Promise
> Read(
56 const ArrayBufferView
& aArray
,
57 const ReadableStreamBYOBReaderReadOptions
& aOptions
, ErrorResult
& rv
);
59 void ReleaseLock(ErrorResult
& rv
);
61 LinkedList
<RefPtr
<ReadIntoRequest
>>& ReadIntoRequests() {
62 return mReadIntoRequests
;
66 ~ReadableStreamBYOBReader() override
= default;
68 LinkedList
<RefPtr
<ReadIntoRequest
>> mReadIntoRequests
;
71 namespace streams_abstract
{
73 already_AddRefed
<ReadableStreamBYOBReader
> AcquireReadableStreamBYOBReader(
74 ReadableStream
* aStream
, ErrorResult
& aRv
);
76 MOZ_CAN_RUN_SCRIPT
void ReadableStreamBYOBReaderRead(
77 JSContext
* aCx
, ReadableStreamBYOBReader
* aReader
,
78 JS::Handle
<JSObject
*> aView
, uint64_t aMin
,
79 ReadIntoRequest
* aReadIntoRequest
, ErrorResult
& aRv
);
81 void ReadableStreamBYOBReaderErrorReadIntoRequests(
82 JSContext
* aCx
, ReadableStreamBYOBReader
* aReader
,
83 JS::Handle
<JS::Value
> aError
, ErrorResult
& aRv
);
85 void ReadableStreamBYOBReaderRelease(JSContext
* aCx
,
86 ReadableStreamBYOBReader
* aReader
,
89 } // namespace streams_abstract
91 } // namespace mozilla::dom
93 #endif // mozilla_dom_ReadableStreamBYOBReader_h