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 DOM_STREAMS_TRANSFORMSTREAM_H_
8 #define DOM_STREAMS_TRANSFORMSTREAM_H_
10 #include "TransformStreamDefaultController.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/QueuingStrategyBinding.h"
14 #include "mozilla/dom/TransformerBinding.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsWrapperCache.h"
18 namespace mozilla::dom
{
22 class UniqueMessagePortId
;
25 class TransformStream final
: public nsISupports
, public nsWrapperCache
{
27 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
28 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TransformStream
)
30 TransformStream(nsIGlobalObject
* aGlobal
, ReadableStream
* aReadable
,
31 WritableStream
* aWritable
);
33 // Internal slot accessors
34 bool Backpressure() const { return mBackpressure
; }
35 void SetBackpressure(bool aBackpressure
) { mBackpressure
= aBackpressure
; }
36 Promise
* BackpressureChangePromise() { return mBackpressureChangePromise
; }
37 void SetBackpressureChangePromise(Promise
* aPromise
) {
38 mBackpressureChangePromise
= aPromise
;
40 MOZ_KNOWN_LIVE TransformStreamDefaultController
* Controller() {
43 void SetController(TransformStreamDefaultController
& aController
) {
44 MOZ_ASSERT(!mController
);
45 mController
= &aController
;
47 MOZ_KNOWN_LIVE ReadableStream
* Readable() { return mReadable
; }
48 MOZ_KNOWN_LIVE WritableStream
* Writable() { return mWritable
; }
51 // https://html.spec.whatwg.org/multipage/structured-data.html#transfer-steps
52 MOZ_CAN_RUN_SCRIPT
bool Transfer(JSContext
* aCx
,
53 UniqueMessagePortId
& aPortId1
,
54 UniqueMessagePortId
& aPortId2
);
55 // https://html.spec.whatwg.org/multipage/structured-data.html#transfer-receiving-steps
56 static MOZ_CAN_RUN_SCRIPT
bool ReceiveTransfer(
57 JSContext
* aCx
, nsIGlobalObject
* aGlobal
, MessagePort
& aPort1
,
58 MessagePort
& aPort2
, JS::MutableHandle
<JSObject
*> aReturnObject
);
62 explicit TransformStream(nsIGlobalObject
* aGlobal
);
64 MOZ_CAN_RUN_SCRIPT
void Initialize(
65 JSContext
* aCx
, Promise
* aStartPromise
, double aWritableHighWaterMark
,
66 QueuingStrategySize
* aWritableSizeAlgorithm
,
67 double aReadableHighWaterMark
,
68 QueuingStrategySize
* aReadableSizeAlgorithm
, ErrorResult
& aRv
);
71 nsIGlobalObject
* GetParentObject() const { return mGlobal
; }
72 JSObject
* WrapObject(JSContext
* aCx
,
73 JS::Handle
<JSObject
*> aGivenProto
) override
;
76 // TODO: Mark as MOZ_CAN_RUN_SCRIPT when IDL constructors can be (bug 1749042)
77 MOZ_CAN_RUN_SCRIPT_BOUNDARY
static already_AddRefed
<TransformStream
>
78 Constructor(const GlobalObject
& aGlobal
,
79 const Optional
<JS::Handle
<JSObject
*>>& aTransformer
,
80 const QueuingStrategy
& aWritableStrategy
,
81 const QueuingStrategy
& aReadableStrategy
, ErrorResult
& aRv
);
83 already_AddRefed
<ReadableStream
> GetReadable();
84 already_AddRefed
<WritableStream
> GetWritable();
87 nsCOMPtr
<nsIGlobalObject
> mGlobal
;
90 // MOZ_KNOWN_LIVE for slots that will never be reassigned
91 bool mBackpressure
= false;
92 RefPtr
<Promise
> mBackpressureChangePromise
;
93 RefPtr
<TransformStreamDefaultController
> mController
;
94 RefPtr
<ReadableStream
> mReadable
;
95 RefPtr
<WritableStream
> mWritable
;
98 MOZ_CAN_RUN_SCRIPT
void TransformStreamErrorWritableAndUnblockWrite(
99 JSContext
* aCx
, TransformStream
* aStream
, JS::Handle
<JS::Value
> aError
,
102 MOZ_CAN_RUN_SCRIPT
void TransformStreamError(JSContext
* aCx
,
103 TransformStream
* aStream
,
104 JS::Handle
<JS::Value
> aError
,
107 void TransformStreamSetBackpressure(TransformStream
* aStream
,
108 bool aBackpressure
, ErrorResult
& aRv
);
110 } // namespace mozilla::dom
112 #endif // DOM_STREAMS_TRANSFORMSTREAM_H_