2021-11-16 01:01:39 +03: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_ReadableStreamTee_h
|
|
|
|
#define mozilla_dom_ReadableStreamTee_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/TeeState.h"
|
|
|
|
#include "mozilla/dom/UnderlyingSourceCallbackHelpers.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
|
|
|
|
namespace mozilla::dom {
|
|
|
|
// Implementation of the Pull algorithm steps for ReadableStreamDefaultTee,
|
|
|
|
// from
|
|
|
|
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaulttee
|
|
|
|
// Step 12.
|
|
|
|
class ReadableStreamDefaultTeePullAlgorithm final
|
|
|
|
: public UnderlyingSourcePullCallbackHelper {
|
|
|
|
RefPtr<TeeState> mTeeState;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(
|
|
|
|
ReadableStreamDefaultTeePullAlgorithm, UnderlyingSourcePullCallbackHelper)
|
|
|
|
|
|
|
|
explicit ReadableStreamDefaultTeePullAlgorithm(TeeState* aTeeState)
|
|
|
|
: mTeeState(aTeeState) {}
|
|
|
|
|
2021-11-16 01:01:39 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
already_AddRefed<Promise> PullCallback(JSContext* aCx,
|
|
|
|
nsIGlobalObject* aGlobal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2021-11-16 01:01:39 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2022-02-19 01:56:33 +03:00
|
|
|
already_AddRefed<Promise> PullCallback(JSContext* aCx,
|
|
|
|
ReadableStreamController& aController,
|
|
|
|
ErrorResult& aRv) override {
|
2021-11-16 01:01:39 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global(aController.GetParentObject());
|
|
|
|
return PullCallback(aCx, global, aRv);
|
|
|
|
}
|
2021-11-16 01:01:39 +03:00
|
|
|
|
|
|
|
protected:
|
2022-02-19 01:56:33 +03:00
|
|
|
~ReadableStreamDefaultTeePullAlgorithm() override = default;
|
2021-11-16 01:01:39 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaulttee
|
|
|
|
// Step 12.3
|
|
|
|
struct ReadableStreamDefaultTeeReadRequest final : public ReadRequest {
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ReadableStreamDefaultTeeReadRequest,
|
|
|
|
ReadRequest)
|
|
|
|
|
|
|
|
RefPtr<TeeState> mTeeState;
|
|
|
|
|
|
|
|
explicit ReadableStreamDefaultTeeReadRequest(TeeState* aTeeState)
|
|
|
|
: mTeeState(aTeeState) {}
|
|
|
|
|
2022-02-19 01:56:33 +03:00
|
|
|
void ChunkSteps(JSContext* aCx, JS::Handle<JS::Value> aChunk,
|
|
|
|
ErrorResult& aRv) override;
|
2021-11-16 01:01:39 +03:00
|
|
|
|
2022-02-19 01:56:33 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void CloseSteps(JSContext* aCx, ErrorResult& aRv) override;
|
2021-11-16 01:01:39 +03:00
|
|
|
|
2022-02-19 01:56:33 +03:00
|
|
|
void ErrorSteps(JSContext* aCx, JS::Handle<JS::Value> aError,
|
|
|
|
ErrorResult& aRv) override;
|
2021-11-16 01:01:39 +03:00
|
|
|
|
|
|
|
protected:
|
2022-02-19 01:56:33 +03:00
|
|
|
~ReadableStreamDefaultTeeReadRequest() override = default;
|
2021-11-16 01:01:39 +03:00
|
|
|
};
|
|
|
|
|
2022-01-07 23:46:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void ReadableByteStreamTee(
|
|
|
|
JSContext* aCx, ReadableStream* aStream,
|
|
|
|
nsTArray<RefPtr<ReadableStream>>& aResult, ErrorResult& aRv);
|
2022-01-05 01:33:24 +03:00
|
|
|
|
2021-11-16 01:01:39 +03:00
|
|
|
} // namespace mozilla::dom
|
|
|
|
#endif
|