ReadableStreamBYOBRequest.h (2221B)
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/. */ 6 7 #ifndef mozilla_dom_ReadableStreamBYOBRequest_h 8 #define mozilla_dom_ReadableStreamBYOBRequest_h 9 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" 17 #include "nsCOMPtr.h" 18 #include "nsCycleCollectionParticipant.h" 19 #include "nsIGlobalObject.h" 20 #include "nsWrapperCache.h" 21 22 namespace mozilla::dom { 23 24 class ReadableByteStreamController; 25 26 class ReadableStreamBYOBRequest final : public nsISupports, 27 public nsWrapperCache { 28 public: 29 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 30 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ReadableStreamBYOBRequest) 31 32 public: 33 explicit ReadableStreamBYOBRequest(nsIGlobalObject* aGlobal); 34 35 protected: 36 ~ReadableStreamBYOBRequest(); 37 38 public: 39 nsIGlobalObject* GetParentObject() const { return mGlobal; } 40 41 JSObject* WrapObject(JSContext* aCx, 42 JS::Handle<JSObject*> aGivenProto) override; 43 44 void GetView(JSContext* cx, JS::MutableHandle<JSObject*> aRetVal) const; 45 46 MOZ_CAN_RUN_SCRIPT void Respond(JSContext* aCx, uint64_t bytesWritten, 47 ErrorResult& aRv); 48 49 MOZ_CAN_RUN_SCRIPT void RespondWithNewView(JSContext* aCx, 50 const ArrayBufferView& view, 51 ErrorResult& aRv); 52 53 ReadableByteStreamController* Controller() { return mController; } 54 void SetController(ReadableByteStreamController* aController); 55 56 JSObject* View() { return mView; } 57 void SetView(JS::Handle<JSObject*> aView) { mView = aView; } 58 59 private: 60 // Internal Slots 61 nsCOMPtr<nsIGlobalObject> mGlobal; 62 RefPtr<ReadableByteStreamController> mController; 63 JS::Heap<JSObject*> mView; 64 }; 65 66 } // namespace mozilla::dom 67 68 #endif