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_ReadableStreamBYOBRequest_h
8 #define mozilla_dom_ReadableStreamBYOBRequest_h
10 #include "js/RootingAPI.h"
11 #include "js/TypeDecls.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/ErrorResult.h"
14 #include "mozilla/HoldDropJSObjects.h"
15 #include "mozilla/dom/BindingDeclarations.h"
16 #include "mozilla/dom/TypedArray.h"
18 #include "nsCycleCollectionParticipant.h"
19 #include "nsWrapperCache.h"
20 #include "nsIGlobalObject.h"
22 namespace mozilla::dom
{
24 class ReadableByteStreamController
;
26 class ReadableStreamBYOBRequest final
: public nsISupports
,
27 public nsWrapperCache
{
29 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
30 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ReadableStreamBYOBRequest
)
33 explicit ReadableStreamBYOBRequest(nsIGlobalObject
* aGlobal
);
36 ~ReadableStreamBYOBRequest();
39 nsIGlobalObject
* GetParentObject() const { return mGlobal
; }
41 JSObject
* WrapObject(JSContext
* aCx
,
42 JS::Handle
<JSObject
*> aGivenProto
) override
;
44 void GetView(JSContext
* cx
, JS::MutableHandle
<JSObject
*> aRetVal
) const;
46 MOZ_CAN_RUN_SCRIPT
void Respond(JSContext
* aCx
, uint64_t bytesWritten
,
49 MOZ_CAN_RUN_SCRIPT
void RespondWithNewView(JSContext
* aCx
,
50 const ArrayBufferView
& view
,
53 ReadableByteStreamController
* Controller() { return mController
; }
54 void SetController(ReadableByteStreamController
* aController
);
56 JSObject
* View() { return mView
; }
57 void SetView(JS::Handle
<JSObject
*> aView
) { mView
= aView
; }
61 nsCOMPtr
<nsIGlobalObject
> mGlobal
;
62 RefPtr
<ReadableByteStreamController
> mController
;
63 JS::Heap
<JSObject
*> mView
;
66 } // namespace mozilla::dom