Bug 1809408 - Part 2: Move WritableStream internal algorithms to internal namespace r=mgaudet

Differential Revision: https://phabricator.services.mozilla.com/D167829
This commit is contained in:
Kagami Sascha Rosylight 2023-02-07 11:56:06 +00:00
parent d8983d750a
commit 938c3b15c9
10 changed files with 50 additions and 3 deletions

View File

@ -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();
}
}

View File

@ -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))

View File

@ -23,6 +23,8 @@
namespace mozilla::dom {
using namespace streams_abstract;
struct PipeToReadRequest;
class WriteFinishedPromiseHandler;
class ShutdownActionFinishedPromiseHandler;

View File

@ -30,6 +30,8 @@
namespace mozilla::dom {
using namespace streams_abstract;
static void PackAndPostMessage(JSContext* aCx, MessagePort* aPort,
const nsAString& aType,
JS::Handle<JS::Value> aValue, ErrorResult& aRv) {

View File

@ -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> WritableStream::Constructor(
return writableStream.forget();
}
namespace streams_abstract {
// https://streams.spec.whatwg.org/#writable-stream-abort
already_AddRefed<Promise> WritableStreamAbort(JSContext* aCx,
WritableStream* aStream,
@ -576,6 +579,7 @@ already_AddRefed<Promise> WritableStreamAbort(JSContext* aCx,
// Step 12. Return promise.
return promise.forget();
}
} // namespace streams_abstract
// https://streams.spec.whatwg.org/#ws-abort
already_AddRefed<Promise> WritableStream::Abort(JSContext* aCx,
@ -593,6 +597,7 @@ already_AddRefed<Promise> WritableStream::Abort(JSContext* aCx,
return WritableStreamAbort(aCx, thisRefPtr, aReason, aRv);
}
namespace streams_abstract {
// https://streams.spec.whatwg.org/#writable-stream-close
already_AddRefed<Promise> WritableStreamClose(JSContext* aCx,
WritableStream* aStream,
@ -644,6 +649,7 @@ already_AddRefed<Promise> WritableStreamClose(JSContext* aCx,
// Step 10. Return promise.
return promise.forget();
}
} // namespace streams_abstract
// https://streams.spec.whatwg.org/#ws-close
already_AddRefed<Promise> WritableStream::Close(JSContext* aCx,
@ -667,6 +673,8 @@ already_AddRefed<Promise> WritableStream::Close(JSContext* aCx,
return WritableStreamClose(aCx, thisRefPtr, aRv);
}
namespace streams_abstract {
// https://streams.spec.whatwg.org/#acquire-writable-stream-default-writer
already_AddRefed<WritableStreamDefaultWriter>
AcquireWritableStreamDefaultWriter(WritableStream* aStream, ErrorResult& aRv) {
@ -714,11 +722,14 @@ already_AddRefed<WritableStream> CreateWritableStream(
return stream.forget();
}
} // namespace streams_abstract
already_AddRefed<WritableStreamDefaultWriter> WritableStream::GetWriter(
ErrorResult& aRv) {
return AcquireWritableStreamDefaultWriter(this, aRv);
}
namespace streams_abstract {
// https://streams.spec.whatwg.org/#writable-stream-add-write-request
already_AddRefed<Promise> WritableStreamAddWriteRequest(
WritableStream* aStream) {
@ -738,6 +749,7 @@ already_AddRefed<Promise> WritableStreamAddWriteRequest(
// Step 5. Return promise.
return promise.forget();
}
} // namespace streams_abstract
// https://streams.spec.whatwg.org/#writablestream-set-up
void WritableStream::SetUpNative(JSContext* aCx,

View File

@ -243,6 +243,8 @@ class WritableStream : public nsISupports, public nsWrapperCache {
HoldDropJSObjectsCaller mHoldDropCaller;
};
namespace streams_abstract {
MOZ_CAN_RUN_SCRIPT already_AddRefed<WritableStream> CreateWritableStream(
JSContext* aCx, nsIGlobalObject* aGlobal,
UnderlyingSinkAlgorithmsBase* aAlgorithms, double aHighWaterMark,
@ -265,6 +267,8 @@ already_AddRefed<Promise> WritableStreamAddWriteRequest(
already_AddRefed<WritableStreamDefaultWriter>
AcquireWritableStreamDefaultWriter(WritableStream* aStream, ErrorResult& aRv);
} // namespace streams_abstract
} // namespace mozilla::dom
#endif // mozilla_dom_WritableStream_h

View File

@ -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

View File

@ -137,6 +137,8 @@ class WritableStreamDefaultController final : public nsISupports,
RefPtr<WritableStream> 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<JS::Value> aChunk, ErrorResult& aRv);
} // namespace streams_abstract
} // namespace mozilla::dom
#endif // mozilla_dom_WritableStreamDefaultController_h

View File

@ -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<Promise> WritableStreamDefaultWriter::Ready() {
return readyPromise.forget();
}
namespace streams_abstract {
// https://streams.spec.whatwg.org/#writable-stream-default-writer-get-desired-size
Nullable<double> WritableStreamDefaultWriterGetDesiredSize(
WritableStreamDefaultWriter* aWriter) {
@ -121,6 +124,7 @@ Nullable<double> WritableStreamDefaultWriterGetDesiredSize(
// ! WritableStreamDefaultControllerGetDesiredSize(stream.[[controller]]).
return stream->Controller()->GetDesiredSize();
}
} // namespace streams_abstract
// https://streams.spec.whatwg.org/#default-writer-desired-size
Nullable<double> WritableStreamDefaultWriter::GetDesiredSize(ErrorResult& aRv) {
@ -204,6 +208,7 @@ already_AddRefed<Promise> 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<Promise> WritableStreamDefaultWriterWrite(
JSContext* aCx, WritableStreamDefaultWriter* aWriter,
@ -332,6 +339,7 @@ already_AddRefed<Promise> WritableStreamDefaultWriterWrite(
// Step 13. Return promise.
return promise.forget();
}
} // namespace streams_abstract
// https://streams.spec.whatwg.org/#default-writer-write
already_AddRefed<Promise> WritableStreamDefaultWriter::Write(
@ -347,6 +355,8 @@ already_AddRefed<Promise> 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<Promise> WritableStreamDefaultWriterCloseWithErrorPropagation(
return WritableStreamDefaultWriterClose(aCx, aWriter, aRv);
}
} // namespace streams_abstract
} // namespace mozilla::dom

View File

@ -79,6 +79,8 @@ class WritableStreamDefaultWriter final : public nsISupports,
RefPtr<Promise> mClosedPromise;
};
namespace streams_abstract {
void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter,
WritableStream* aStream,
ErrorResult& aRv);
@ -103,6 +105,8 @@ MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise>
WritableStreamDefaultWriterCloseWithErrorPropagation(
JSContext* aCx, WritableStreamDefaultWriter* aWriter, ErrorResult& aRv);
} // namespace streams_abstract
} // namespace mozilla::dom
#endif // mozilla_dom_WritableStreamDefaultWriter_h