From 938c3b15c96f30216200a7005c4f181d0bf8e5e7 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Tue, 7 Feb 2023 11:56:06 +0000 Subject: [PATCH] Bug 1809408 - Part 2: Move WritableStream internal algorithms to internal namespace r=mgaudet Differential Revision: https://phabricator.services.mozilla.com/D167829 --- dom/base/StructuredCloneHolder.cpp | 5 ++--- dom/streams/ReadableStream.cpp | 2 ++ dom/streams/ReadableStreamPipeTo.cpp | 2 ++ dom/streams/Transferable.cpp | 2 ++ dom/streams/WritableStream.cpp | 12 ++++++++++++ dom/streams/WritableStream.h | 4 ++++ dom/streams/WritableStreamDefaultController.cpp | 6 ++++++ dom/streams/WritableStreamDefaultController.h | 4 ++++ dom/streams/WritableStreamDefaultWriter.cpp | 12 ++++++++++++ dom/streams/WritableStreamDefaultWriter.h | 4 ++++ 10 files changed, 50 insertions(+), 3 deletions(-) diff --git a/dom/base/StructuredCloneHolder.cpp b/dom/base/StructuredCloneHolder.cpp index 504a204575cc..d757dcd566c8 100644 --- a/dom/base/StructuredCloneHolder.cpp +++ b/dom/base/StructuredCloneHolder.cpp @@ -1594,7 +1594,7 @@ bool StructuredCloneHolder::CustomCanTransferHandler( // https://streams.spec.whatwg.org/#ref-for-transfer-steps① // Step 1: If ! IsWritableStreamLocked(value) is true, throw a // "DataCloneError" DOMException. - return !IsWritableStreamLocked(stream); + return !stream->Locked(); } } @@ -1605,8 +1605,7 @@ bool StructuredCloneHolder::CustomCanTransferHandler( // https://streams.spec.whatwg.org/#ref-for-transfer-steps② // Step 3 + 4: If ! Is{Readable,Writable}StreamLocked(value) is true, // throw a "DataCloneError" DOMException. - return !stream->Readable()->Locked() && - !IsWritableStreamLocked(stream->Writable()); + return !stream->Readable()->Locked() && !stream->Writable()->Locked(); } } diff --git a/dom/streams/ReadableStream.cpp b/dom/streams/ReadableStream.cpp index 054f153c13c9..2a02755ecd1c 100644 --- a/dom/streams/ReadableStream.cpp +++ b/dom/streams/ReadableStream.cpp @@ -70,6 +70,8 @@ inline void ImplCycleCollectionUnlink( namespace mozilla::dom { +using namespace streams_abstract; + // Only needed for refcounted objects. NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS( ReadableStream, (mGlobal, mController, mReader), (mStoredError)) diff --git a/dom/streams/ReadableStreamPipeTo.cpp b/dom/streams/ReadableStreamPipeTo.cpp index 9a9eb29fdcb8..744b0dfbf1c1 100644 --- a/dom/streams/ReadableStreamPipeTo.cpp +++ b/dom/streams/ReadableStreamPipeTo.cpp @@ -23,6 +23,8 @@ namespace mozilla::dom { +using namespace streams_abstract; + struct PipeToReadRequest; class WriteFinishedPromiseHandler; class ShutdownActionFinishedPromiseHandler; diff --git a/dom/streams/Transferable.cpp b/dom/streams/Transferable.cpp index 41b9256c08fd..5920ec67d7b9 100644 --- a/dom/streams/Transferable.cpp +++ b/dom/streams/Transferable.cpp @@ -30,6 +30,8 @@ namespace mozilla::dom { +using namespace streams_abstract; + static void PackAndPostMessage(JSContext* aCx, MessagePort* aPort, const nsAString& aType, JS::Handle aValue, ErrorResult& aRv) { diff --git a/dom/streams/WritableStream.cpp b/dom/streams/WritableStream.cpp index 93c70d0b7f55..fcd65e302ff5 100644 --- a/dom/streams/WritableStream.cpp +++ b/dom/streams/WritableStream.cpp @@ -35,6 +35,8 @@ namespace mozilla::dom { +using namespace streams_abstract; + NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS( WritableStream, (mGlobal, mCloseRequest, mController, mInFlightWriteRequest, @@ -499,6 +501,7 @@ already_AddRefed WritableStream::Constructor( return writableStream.forget(); } +namespace streams_abstract { // https://streams.spec.whatwg.org/#writable-stream-abort already_AddRefed WritableStreamAbort(JSContext* aCx, WritableStream* aStream, @@ -576,6 +579,7 @@ already_AddRefed WritableStreamAbort(JSContext* aCx, // Step 12. Return promise. return promise.forget(); } +} // namespace streams_abstract // https://streams.spec.whatwg.org/#ws-abort already_AddRefed WritableStream::Abort(JSContext* aCx, @@ -593,6 +597,7 @@ already_AddRefed WritableStream::Abort(JSContext* aCx, return WritableStreamAbort(aCx, thisRefPtr, aReason, aRv); } +namespace streams_abstract { // https://streams.spec.whatwg.org/#writable-stream-close already_AddRefed WritableStreamClose(JSContext* aCx, WritableStream* aStream, @@ -644,6 +649,7 @@ already_AddRefed WritableStreamClose(JSContext* aCx, // Step 10. Return promise. return promise.forget(); } +} // namespace streams_abstract // https://streams.spec.whatwg.org/#ws-close already_AddRefed WritableStream::Close(JSContext* aCx, @@ -667,6 +673,8 @@ already_AddRefed WritableStream::Close(JSContext* aCx, return WritableStreamClose(aCx, thisRefPtr, aRv); } +namespace streams_abstract { + // https://streams.spec.whatwg.org/#acquire-writable-stream-default-writer already_AddRefed AcquireWritableStreamDefaultWriter(WritableStream* aStream, ErrorResult& aRv) { @@ -714,11 +722,14 @@ already_AddRefed CreateWritableStream( return stream.forget(); } +} // namespace streams_abstract + already_AddRefed WritableStream::GetWriter( ErrorResult& aRv) { return AcquireWritableStreamDefaultWriter(this, aRv); } +namespace streams_abstract { // https://streams.spec.whatwg.org/#writable-stream-add-write-request already_AddRefed WritableStreamAddWriteRequest( WritableStream* aStream) { @@ -738,6 +749,7 @@ already_AddRefed WritableStreamAddWriteRequest( // Step 5. Return promise. return promise.forget(); } +} // namespace streams_abstract // https://streams.spec.whatwg.org/#writablestream-set-up void WritableStream::SetUpNative(JSContext* aCx, diff --git a/dom/streams/WritableStream.h b/dom/streams/WritableStream.h index 2478c98feb9d..13ab15a97114 100644 --- a/dom/streams/WritableStream.h +++ b/dom/streams/WritableStream.h @@ -243,6 +243,8 @@ class WritableStream : public nsISupports, public nsWrapperCache { HoldDropJSObjectsCaller mHoldDropCaller; }; +namespace streams_abstract { + MOZ_CAN_RUN_SCRIPT already_AddRefed CreateWritableStream( JSContext* aCx, nsIGlobalObject* aGlobal, UnderlyingSinkAlgorithmsBase* aAlgorithms, double aHighWaterMark, @@ -265,6 +267,8 @@ already_AddRefed WritableStreamAddWriteRequest( already_AddRefed AcquireWritableStreamDefaultWriter(WritableStream* aStream, ErrorResult& aRv); +} // namespace streams_abstract + } // namespace mozilla::dom #endif // mozilla_dom_WritableStream_h diff --git a/dom/streams/WritableStreamDefaultController.cpp b/dom/streams/WritableStreamDefaultController.cpp index 45cbf553c4be..c1ee4bd8ea26 100644 --- a/dom/streams/WritableStreamDefaultController.cpp +++ b/dom/streams/WritableStreamDefaultController.cpp @@ -22,6 +22,8 @@ namespace mozilla::dom { +using namespace streams_abstract; + // Note: Using the individual macros vs NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE // because I need to specificy a manual implementation of // NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN. @@ -118,6 +120,8 @@ void WritableStreamDefaultController::SetSignal(AbortSignal* aSignal) { mSignal = aSignal; } +namespace streams_abstract { + MOZ_CAN_RUN_SCRIPT static void WritableStreamDefaultControllerAdvanceQueueIfNeeded( JSContext* aCx, WritableStreamDefaultController* aController, @@ -555,4 +559,6 @@ double WritableStreamDefaultControllerGetChunkSize( return chunkSize; } +} // namespace streams_abstract + } // namespace mozilla::dom diff --git a/dom/streams/WritableStreamDefaultController.h b/dom/streams/WritableStreamDefaultController.h index ecc7626c2a83..808c68315b29 100644 --- a/dom/streams/WritableStreamDefaultController.h +++ b/dom/streams/WritableStreamDefaultController.h @@ -137,6 +137,8 @@ class WritableStreamDefaultController final : public nsISupports, RefPtr mStream; }; +namespace streams_abstract { + MOZ_CAN_RUN_SCRIPT void SetUpWritableStreamDefaultController( JSContext* aCx, WritableStream* aStream, WritableStreamDefaultController* aController, @@ -169,6 +171,8 @@ MOZ_CAN_RUN_SCRIPT double WritableStreamDefaultControllerGetChunkSize( JSContext* aCx, WritableStreamDefaultController* aController, JS::Handle aChunk, ErrorResult& aRv); +} // namespace streams_abstract + } // namespace mozilla::dom #endif // mozilla_dom_WritableStreamDefaultController_h diff --git a/dom/streams/WritableStreamDefaultWriter.cpp b/dom/streams/WritableStreamDefaultWriter.cpp index 01bdabafe53f..cc9b6e621635 100644 --- a/dom/streams/WritableStreamDefaultWriter.cpp +++ b/dom/streams/WritableStreamDefaultWriter.cpp @@ -24,6 +24,8 @@ namespace mozilla::dom { +using namespace streams_abstract; + NS_IMPL_CYCLE_COLLECTION_CLASS(WritableStreamDefaultWriter) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WritableStreamDefaultWriter) NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal, mStream, mReadyPromise, @@ -97,6 +99,7 @@ already_AddRefed WritableStreamDefaultWriter::Ready() { return readyPromise.forget(); } +namespace streams_abstract { // https://streams.spec.whatwg.org/#writable-stream-default-writer-get-desired-size Nullable WritableStreamDefaultWriterGetDesiredSize( WritableStreamDefaultWriter* aWriter) { @@ -121,6 +124,7 @@ Nullable WritableStreamDefaultWriterGetDesiredSize( // ! WritableStreamDefaultControllerGetDesiredSize(stream.[[controller]]). return stream->Controller()->GetDesiredSize(); } +} // namespace streams_abstract // https://streams.spec.whatwg.org/#default-writer-desired-size Nullable WritableStreamDefaultWriter::GetDesiredSize(ErrorResult& aRv) { @@ -204,6 +208,7 @@ already_AddRefed WritableStreamDefaultWriter::Close(JSContext* aCx, return WritableStreamDefaultWriterClose(aCx, thisRefPtr, aRv); } +namespace streams_abstract { // https://streams.spec.whatwg.org/#writable-stream-default-writer-release void WritableStreamDefaultWriterRelease(JSContext* aCx, WritableStreamDefaultWriter* aWriter) { @@ -242,6 +247,7 @@ void WritableStreamDefaultWriterRelease(JSContext* aCx, // Step 8. Set writer.[[stream]] to undefined. aWriter->SetStream(nullptr); } +} // namespace streams_abstract // https://streams.spec.whatwg.org/#default-writer-release-lock void WritableStreamDefaultWriter::ReleaseLock(JSContext* aCx) { @@ -261,6 +267,7 @@ void WritableStreamDefaultWriter::ReleaseLock(JSContext* aCx) { return WritableStreamDefaultWriterRelease(aCx, thisRefPtr); } +namespace streams_abstract { // https://streams.spec.whatwg.org/#writable-stream-default-writer-write already_AddRefed WritableStreamDefaultWriterWrite( JSContext* aCx, WritableStreamDefaultWriter* aWriter, @@ -332,6 +339,7 @@ already_AddRefed WritableStreamDefaultWriterWrite( // Step 13. Return promise. return promise.forget(); } +} // namespace streams_abstract // https://streams.spec.whatwg.org/#default-writer-write already_AddRefed WritableStreamDefaultWriter::Write( @@ -347,6 +355,8 @@ already_AddRefed WritableStreamDefaultWriter::Write( return WritableStreamDefaultWriterWrite(aCx, this, aChunk, aRv); } +namespace streams_abstract { + // https://streams.spec.whatwg.org/#set-up-writable-stream-default-writer void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter, WritableStream* aStream, @@ -530,4 +540,6 @@ already_AddRefed WritableStreamDefaultWriterCloseWithErrorPropagation( return WritableStreamDefaultWriterClose(aCx, aWriter, aRv); } +} // namespace streams_abstract + } // namespace mozilla::dom diff --git a/dom/streams/WritableStreamDefaultWriter.h b/dom/streams/WritableStreamDefaultWriter.h index e9307c6c4586..487a504cd13f 100644 --- a/dom/streams/WritableStreamDefaultWriter.h +++ b/dom/streams/WritableStreamDefaultWriter.h @@ -79,6 +79,8 @@ class WritableStreamDefaultWriter final : public nsISupports, RefPtr mClosedPromise; }; +namespace streams_abstract { + void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter, WritableStream* aStream, ErrorResult& aRv); @@ -103,6 +105,8 @@ MOZ_CAN_RUN_SCRIPT already_AddRefed WritableStreamDefaultWriterCloseWithErrorPropagation( JSContext* aCx, WritableStreamDefaultWriter* aWriter, ErrorResult& aRv); +} // namespace streams_abstract + } // namespace mozilla::dom #endif // mozilla_dom_WritableStreamDefaultWriter_h