tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ReadableStreamBYOBReader.h (3091B)


      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_ReadableStreamBYOBReader_h
      8 #define mozilla_dom_ReadableStreamBYOBReader_h
      9 
     10 #include "js/TypeDecls.h"
     11 #include "mozilla/Attributes.h"
     12 #include "mozilla/ErrorResult.h"
     13 #include "mozilla/LinkedList.h"
     14 #include "mozilla/dom/BindingDeclarations.h"
     15 #include "mozilla/dom/ReadableStreamGenericReader.h"
     16 #include "mozilla/dom/TypedArray.h"
     17 #include "nsCycleCollectionParticipant.h"
     18 #include "nsWrapperCache.h"
     19 
     20 namespace mozilla::dom {
     21 
     22 class Promise;
     23 struct ReadIntoRequest;
     24 class ReadableStream;
     25 struct ReadableStreamBYOBReaderReadOptions;
     26 
     27 }  // namespace mozilla::dom
     28 
     29 namespace mozilla::dom {
     30 
     31 class ReadableStreamBYOBReader final : public ReadableStreamGenericReader,
     32                                       public nsWrapperCache {
     33 public:
     34  NS_DECL_ISUPPORTS_INHERITED
     35  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS_INHERITED(
     36      ReadableStreamBYOBReader, ReadableStreamGenericReader)
     37 
     38 public:
     39  explicit ReadableStreamBYOBReader(nsISupports* aGlobal);
     40 
     41  bool IsDefault() override { return false; };
     42  bool IsBYOB() override { return true; }
     43  ReadableStreamDefaultReader* AsDefault() override {
     44    MOZ_CRASH("Should have verified IsDefault first");
     45    return nullptr;
     46  }
     47  ReadableStreamBYOBReader* AsBYOB() override { return this; }
     48 
     49  JSObject* WrapObject(JSContext* aCx,
     50                       JS::Handle<JSObject*> aGivenProto) override;
     51 
     52  static already_AddRefed<ReadableStreamBYOBReader> Constructor(
     53      const GlobalObject& global, ReadableStream& stream, ErrorResult& rv);
     54 
     55  MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> Read(
     56      const ArrayBufferView& aArray,
     57      const ReadableStreamBYOBReaderReadOptions& aOptions, ErrorResult& rv);
     58 
     59  void ReleaseLock(ErrorResult& rv);
     60 
     61  LinkedList<RefPtr<ReadIntoRequest>>& ReadIntoRequests() {
     62    return mReadIntoRequests;
     63  }
     64 
     65 private:
     66  ~ReadableStreamBYOBReader() override = default;
     67 
     68  LinkedList<RefPtr<ReadIntoRequest>> mReadIntoRequests;
     69 };
     70 
     71 namespace streams_abstract {
     72 
     73 already_AddRefed<ReadableStreamBYOBReader> AcquireReadableStreamBYOBReader(
     74    ReadableStream* aStream, ErrorResult& aRv);
     75 
     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);
     80 
     81 void ReadableStreamBYOBReaderErrorReadIntoRequests(
     82    JSContext* aCx, ReadableStreamBYOBReader* aReader,
     83    JS::Handle<JS::Value> aError, ErrorResult& aRv);
     84 
     85 void ReadableStreamBYOBReaderRelease(JSContext* aCx,
     86                                     ReadableStreamBYOBReader* aReader,
     87                                     ErrorResult& aRv);
     88 
     89 }  // namespace streams_abstract
     90 
     91 }  // namespace mozilla::dom
     92 
     93 #endif  // mozilla_dom_ReadableStreamBYOBReader_h