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
;
26 } // namespace mozilla::dom
28 namespace mozilla::dom
{
30 class ReadableStreamBYOBReader final
: public ReadableStreamGenericReader
,
31 public nsWrapperCache
{
33 NS_DECL_ISUPPORTS_INHERITED
34 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS_INHERITED(
35 ReadableStreamBYOBReader
, ReadableStreamGenericReader
)
38 explicit ReadableStreamBYOBReader(nsISupports
* aGlobal
);
40 bool IsDefault() override
{ return false; };
41 bool IsBYOB() override
{ return true; }
42 ReadableStreamDefaultReader
* AsDefault() override
{
43 MOZ_CRASH("Should have verified IsDefault first");
46 ReadableStreamBYOBReader
* AsBYOB() override
{ return this; }
48 JSObject
* WrapObject(JSContext
* aCx
,
49 JS::Handle
<JSObject
*> aGivenProto
) override
;
51 static already_AddRefed
<ReadableStreamBYOBReader
> Constructor(
52 const GlobalObject
& global
, ReadableStream
& stream
, ErrorResult
& rv
);
54 MOZ_CAN_RUN_SCRIPT already_AddRefed
<Promise
> Read(
55 const ArrayBufferView
& aArray
, ErrorResult
& rv
);
57 void ReleaseLock(ErrorResult
& rv
);
59 LinkedList
<RefPtr
<ReadIntoRequest
>>& ReadIntoRequests() {
60 return mReadIntoRequests
;
64 ~ReadableStreamBYOBReader() override
= default;
66 LinkedList
<RefPtr
<ReadIntoRequest
>> mReadIntoRequests
;
69 namespace streams_abstract
{
71 already_AddRefed
<ReadableStreamBYOBReader
> AcquireReadableStreamBYOBReader(
72 ReadableStream
* aStream
, ErrorResult
& aRv
);
74 MOZ_CAN_RUN_SCRIPT
void ReadableStreamBYOBReaderRead(
75 JSContext
* aCx
, ReadableStreamBYOBReader
* aReader
,
76 JS::Handle
<JSObject
*> aView
, ReadIntoRequest
* aReadIntoRequest
,
79 void ReadableStreamBYOBReaderErrorReadIntoRequests(
80 JSContext
* aCx
, ReadableStreamBYOBReader
* aReader
,
81 JS::Handle
<JS::Value
> aError
, ErrorResult
& aRv
);
83 void ReadableStreamBYOBReaderRelease(JSContext
* aCx
,
84 ReadableStreamBYOBReader
* aReader
,
87 } // namespace streams_abstract
89 } // namespace mozilla::dom
91 #endif // mozilla_dom_ReadableStreamBYOBReader_h