2021-10-06 18:43:01 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_ReadableStreamDefaultReader_h
|
|
|
|
#define mozilla_dom_ReadableStreamDefaultReader_h
|
|
|
|
|
|
|
|
#include "js/TypeDecls.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
#include "mozilla/dom/ReadableStreamGenericReader.h"
|
|
|
|
#include "mozilla/dom/ReadRequest.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/LinkedList.h"
|
|
|
|
|
2022-02-18 22:56:33 +00:00
|
|
|
namespace mozilla::dom {
|
2021-10-06 18:43:01 +00:00
|
|
|
|
|
|
|
class Promise;
|
|
|
|
class ReadableStream;
|
|
|
|
|
2022-01-14 21:09:20 +00:00
|
|
|
// https://streams.spec.whatwg.org/#default-reader-read
|
|
|
|
struct Read_ReadRequest : public ReadRequest {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Read_ReadRequest, ReadRequest)
|
|
|
|
|
|
|
|
RefPtr<Promise> mPromise;
|
|
|
|
|
2022-03-18 17:46:32 +00:00
|
|
|
explicit Read_ReadRequest(Promise* aPromise) : mPromise(aPromise) {}
|
2022-01-14 21:09:20 +00:00
|
|
|
|
|
|
|
void ChunkSteps(JSContext* aCx, JS::Handle<JS::Value> aChunk,
|
|
|
|
ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
void CloseSteps(JSContext* aCx, ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
void ErrorSteps(JSContext* aCx, JS::Handle<JS::Value> e,
|
|
|
|
ErrorResult& aRv) override;
|
|
|
|
|
|
|
|
protected:
|
2022-02-18 22:56:33 +00:00
|
|
|
~Read_ReadRequest() override = default;
|
2022-01-14 21:09:20 +00:00
|
|
|
};
|
|
|
|
|
2021-10-06 18:43:01 +00:00
|
|
|
class ReadableStreamDefaultReader final : public ReadableStreamGenericReader,
|
|
|
|
public nsWrapperCache
|
|
|
|
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
|
|
|
|
ReadableStreamDefaultReader, ReadableStreamGenericReader)
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ReadableStreamDefaultReader(nsISupports* aGlobal);
|
|
|
|
|
|
|
|
protected:
|
2022-02-18 22:56:33 +00:00
|
|
|
~ReadableStreamDefaultReader() override;
|
2021-10-06 18:43:01 +00:00
|
|
|
|
|
|
|
public:
|
2022-01-04 22:33:20 +00:00
|
|
|
bool IsDefault() override { return true; }
|
|
|
|
bool IsBYOB() override { return false; }
|
2022-01-04 22:33:22 +00:00
|
|
|
ReadableStreamDefaultReader* AsDefault() override { return this; }
|
|
|
|
ReadableStreamBYOBReader* AsBYOB() override {
|
|
|
|
MOZ_CRASH();
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-01-04 22:33:20 +00:00
|
|
|
|
2021-10-06 18:43:01 +00:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
static already_AddRefed<ReadableStreamDefaultReader> Constructor(
|
|
|
|
const GlobalObject& aGlobal, ReadableStream& stream, ErrorResult& aRv);
|
|
|
|
|
2022-01-07 20:46:19 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> Read(JSContext* aCx,
|
|
|
|
ErrorResult& aRv);
|
2021-10-06 18:43:01 +00:00
|
|
|
|
|
|
|
void ReleaseLock(ErrorResult& aRv);
|
|
|
|
|
|
|
|
LinkedList<RefPtr<ReadRequest>>& ReadRequests() { return mReadRequests; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
LinkedList<RefPtr<ReadRequest>> mReadRequests = {};
|
|
|
|
};
|
|
|
|
|
2022-03-02 01:31:26 +00:00
|
|
|
void SetUpReadableStreamDefaultReader(ReadableStreamDefaultReader* aReader,
|
|
|
|
ReadableStream* aStream,
|
|
|
|
ErrorResult& aRv);
|
2021-10-06 18:43:01 +00:00
|
|
|
|
2022-02-06 10:11:53 +00:00
|
|
|
void ReadableStreamDefaultReaderErrorReadRequests(
|
|
|
|
JSContext* aCx, ReadableStreamDefaultReader* aReader,
|
|
|
|
JS::Handle<JS::Value> aError, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void ReadableStreamDefaultReaderRelease(JSContext* aCx,
|
|
|
|
ReadableStreamDefaultReader* aReader,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2022-02-18 22:56:33 +00:00
|
|
|
} // namespace mozilla::dom
|
2021-10-06 18:43:01 +00:00
|
|
|
|
|
|
|
#endif // mozilla_dom_ReadableStreamDefaultReader_h
|