Skip to content

Commit

Permalink
Backed out 6 changesets (bug 1820776, bug 1820434, bug 1822138, bug 1…
Browse files Browse the repository at this point in the history
…822038, bug 1821146, bug 1791835) for causing build bustages on WebTransportDatagramDuplexStream.cpp CLOSED TREE

Backed out changeset 4a866db45f1a (bug 1822038)
Backed out changeset 889174ce36fd (bug 1821146)
Backed out changeset 39f22b088301 (bug 1820434)
Backed out changeset c93fec9914f5 (bug 1822138)
Backed out changeset 914ee3f0f3ee (bug 1791835)
Backed out changeset 43beacf35d14 (bug 1820776)
  • Loading branch information
Cristian Tuns committed Mar 21, 2023
1 parent 3e8710c commit 0ddabc0
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 632 deletions.
78 changes: 6 additions & 72 deletions dom/streams/UnderlyingSourceCallbackHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include "mozilla/dom/ReadableStreamDefaultController.h"
#include "mozilla/dom/UnderlyingSourceCallbackHelpers.h"
#include "mozilla/dom/UnderlyingSourceBinding.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRunnable.h"
#include "js/experimental/TypedData.h"

namespace mozilla::dom {
Expand Down Expand Up @@ -131,9 +128,7 @@ already_AddRefed<Promise> UnderlyingSourceAlgorithmsWrapper::PullCallback(
nsCOMPtr<nsIGlobalObject> global = aController.GetParentObject();
return PromisifyAlgorithm(
global,
[&](ErrorResult& aRv) MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
return PullCallbackImpl(aCx, aController, aRv);
},
[&](ErrorResult& aRv) { return PullCallbackImpl(aCx, aController, aRv); },
aRv);
}

Expand All @@ -151,67 +146,10 @@ already_AddRefed<Promise> UnderlyingSourceAlgorithmsWrapper::CancelCallback(
aRv);
}

NS_IMPL_ISUPPORTS(InputStreamHolder, nsIInputStreamCallback)

InputStreamHolder::InputStreamHolder(JSContext* aCx,
InputToReadableStreamAlgorithms* aCallback,
nsIAsyncInputStream* aInput)
: mCallback(aCallback), mInput(aInput) {
if (!NS_IsMainThread()) {
// We're in a worker
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
MOZ_ASSERT(workerPrivate);

workerPrivate->AssertIsOnWorkerThread();

// Note, this will create a ref-cycle between the holder and the stream.
// The cycle is broken when the stream is closed or the worker begins
// shutting down.
mWorkerRef =
StrongWorkerRef::Create(workerPrivate, "InputStreamHolder",
[self = RefPtr{this}]() { self->Shutdown(); });
if (NS_WARN_IF(!mWorkerRef)) {
return;
}
}
}

InputStreamHolder::~InputStreamHolder() { MOZ_ASSERT(!mCallback); }

void InputStreamHolder::Shutdown() {
if (mCallback) {
mCallback = nullptr;
mInput->CloseWithStatus(NS_BASE_STREAM_CLOSED);
mWorkerRef = nullptr;
// If we have an AsyncWait running, we'll get a callback and clear
// the mAsyncWaitWorkerRef
}
}

nsresult InputStreamHolder::AsyncWait(uint32_t aFlags, uint32_t aRequestedCount,
nsIEventTarget* aEventTarget) {
nsresult rv = mInput->AsyncWait(this, aFlags, aRequestedCount, aEventTarget);
if (NS_SUCCEEDED(rv)) {
mAsyncWaitWorkerRef = mWorkerRef;
}
return rv;
}

NS_IMETHODIMP InputStreamHolder::OnInputStreamReady(
nsIAsyncInputStream* aStream) {
mAsyncWaitWorkerRef = nullptr;
// We may get called back after ::Shutdown()
if (mCallback) {
return mCallback->OnInputStreamReady(aStream);
}
return NS_ERROR_FAILURE;
}

NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(
InputToReadableStreamAlgorithms, UnderlyingSourceAlgorithmsWrapper)
NS_IMPL_CYCLE_COLLECTION_INHERITED(InputToReadableStreamAlgorithms,
UnderlyingSourceAlgorithmsWrapper, mStream,
mOwningEventTarget)
UnderlyingSourceAlgorithmsWrapper, mStream)

already_AddRefed<Promise> InputToReadableStreamAlgorithms::PullCallbackImpl(
JSContext* aCx, ReadableStreamController& aController, ErrorResult& aRv) {
Expand Down Expand Up @@ -248,7 +186,7 @@ already_AddRefed<Promise> InputToReadableStreamAlgorithms::PullCallbackImpl(

MOZ_DIAGNOSTIC_ASSERT(mInput);

nsresult rv = mInput->AsyncWait(0, 0, mOwningEventTarget);
nsresult rv = mInput->AsyncWait(this, 0, 0, mOwningEventTarget);
if (NS_WARN_IF(NS_FAILED(rv))) {
ErrorPropagation(aCx, stream, rv);
return nullptr;
Expand All @@ -264,7 +202,7 @@ InputToReadableStreamAlgorithms::OnInputStreamReady(
MOZ_DIAGNOSTIC_ASSERT(aStream);

// Already closed. We have nothing else to do here.
if (mState == eClosed || !mStream) {
if (mState == eClosed) {
return NS_OK;
}

Expand Down Expand Up @@ -353,7 +291,7 @@ void InputToReadableStreamAlgorithms::WriteIntoReadRequestBuffer(
return;
}

rv = mInput->AsyncWait(0, 0, mOwningEventTarget);
rv = mInput->AsyncWait(this, 0, 0, mOwningEventTarget);
if (NS_WARN_IF(NS_FAILED(rv))) {
ErrorPropagation(aCx, aStream, rv);
return;
Expand Down Expand Up @@ -420,11 +358,7 @@ void InputToReadableStreamAlgorithms::CloseAndReleaseObjects(
}

void InputToReadableStreamAlgorithms::ReleaseObjects() {
if (mInput) {
mInput->CloseWithStatus(NS_BASE_STREAM_CLOSED);
mInput->Shutdown();
mInput = nullptr;
}
mInput->CloseWithStatus(NS_BASE_STREAM_CLOSED);
}

void InputToReadableStreamAlgorithms::ErrorPropagation(JSContext* aCx,
Expand Down
57 changes: 5 additions & 52 deletions dom/streams/UnderlyingSourceCallbackHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ enum class nsresult : uint32_t;

namespace mozilla::dom {

class StrongWorkerRef;
class BodyStreamHolder;
class ReadableStreamController;
class ReadableStream;
Expand Down Expand Up @@ -146,7 +145,7 @@ class UnderlyingSourceAlgorithmsWrapper
JSContext* aCx, const Optional<JS::Handle<JS::Value>>& aReason,
ErrorResult& aRv) final;

MOZ_CAN_RUN_SCRIPT virtual already_AddRefed<Promise> PullCallbackImpl(
virtual already_AddRefed<Promise> PullCallbackImpl(
JSContext* aCx, ReadableStreamController& aController, ErrorResult& aRv) {
// pullAlgorithm is optional, return null by default
return nullptr;
Expand All @@ -160,48 +159,6 @@ class UnderlyingSourceAlgorithmsWrapper
}
};

class InputToReadableStreamAlgorithms;

// This class exists to isolate InputToReadableStreamAlgorithms from the
// nsIAsyncInputStream. If we call AsyncWait(this,...), it holds a
// reference to 'this' which can't be cc'd, and we can leak the stream,
// causing a Worker to assert with globalScopeAlive. By isolating
// ourselves from the inputstream, we can safely be CC'd if needed and
// will inform the inputstream to shut down.
class InputStreamHolder final : public nsIInputStreamCallback {
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIINPUTSTREAMCALLBACK

InputStreamHolder(JSContext* aCx, InputToReadableStreamAlgorithms* aCallback,
nsIAsyncInputStream* aInput);

// This MUST be called before we're destroyed
void Shutdown();

// These just proxy the calls to the nsIAsyncInputStream
nsresult AsyncWait(uint32_t aFlags, uint32_t aRequestedCount,
nsIEventTarget* aEventTarget);
nsresult Available(uint64_t* aSize) { return mInput->Available(aSize); }
nsresult Read(char* aBuffer, uint32_t aLength, uint32_t* aWritten) {
return mInput->Read(aBuffer, aLength, aWritten);
}
nsresult CloseWithStatus(nsresult aStatus) {
return mInput->CloseWithStatus(aStatus);
}

private:
~InputStreamHolder();

// Purposely rawptr to avoid cycles. Must be cleared with Shutdown() before
// destruction
InputToReadableStreamAlgorithms* mCallback;
// To ensure the worker sticks around
RefPtr<StrongWorkerRef> mAsyncWaitWorkerRef;
RefPtr<StrongWorkerRef> mWorkerRef;
nsCOMPtr<nsIAsyncInputStream> mInput;
};

class InputToReadableStreamAlgorithms final
: public UnderlyingSourceAlgorithmsWrapper,
public nsIInputStreamCallback {
Expand All @@ -210,11 +167,11 @@ class InputToReadableStreamAlgorithms final
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InputToReadableStreamAlgorithms,
UnderlyingSourceAlgorithmsWrapper)

InputToReadableStreamAlgorithms(JSContext* aCx, nsIAsyncInputStream* aInput,
InputToReadableStreamAlgorithms(nsIAsyncInputStream* aInput,
ReadableStream* aStream)
: mState(eInitializing),
mOwningEventTarget(GetCurrentSerialEventTarget()),
mInput(new InputStreamHolder(aCx, this, aInput)),
mInput(aInput),
mStream(aStream) {}

// Streams algorithms
Expand All @@ -226,11 +183,7 @@ class InputToReadableStreamAlgorithms final
void ReleaseObjects() override;

private:
~InputToReadableStreamAlgorithms() {
if (mInput) {
mInput->Shutdown();
}
}
~InputToReadableStreamAlgorithms() override = default;

MOZ_CAN_RUN_SCRIPT_BOUNDARY void CloseAndReleaseObjects(
JSContext* aCx, ReadableStream* aStream);
Expand Down Expand Up @@ -274,7 +227,7 @@ class InputToReadableStreamAlgorithms final

nsCOMPtr<nsIEventTarget> mOwningEventTarget;

RefPtr<InputStreamHolder> mInput;
nsCOMPtr<nsIAsyncInputStream> mInput;
RefPtr<ReadableStream> mStream;
};

Expand Down
8 changes: 4 additions & 4 deletions dom/webidl/WebTransportDatagramDuplexStream.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ interface WebTransportDatagramDuplexStream {
readonly attribute WritableStream writable;

readonly attribute unsigned long maxDatagramSize;
[Throws] attribute unrestricted double incomingMaxAge;
[Throws] attribute unrestricted double outgoingMaxAge;
[Throws] attribute unrestricted double incomingHighWaterMark;
[Throws] attribute unrestricted double outgoingHighWaterMark;
attribute double? incomingMaxAge;
attribute double? outgoingMaxAge;
attribute long incomingHighWaterMark;
attribute long outgoingHighWaterMark;
};
28 changes: 5 additions & 23 deletions dom/webtransport/api/WebTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WebTransport)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mUnidirectionalStreams)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBidirectionalStreams)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIncomingUnidirectionalStreams)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIncomingBidirectionalStreams)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIncomingUnidirectionalAlgorithm)
Expand Down Expand Up @@ -135,11 +133,6 @@ void WebTransport::NewUnidirectionalStream(
}
}

void WebTransport::NewDatagramReceived(nsTArray<uint8_t>&& aData,
const mozilla::TimeStamp& aTimeStamp) {
mDatagrams->NewDatagramReceived(std::move(aData), aTimeStamp);
}

// WebIDL Boilerplate

nsIGlobalObject* WebTransport::GetParentObject() const { return mGlobal; }
Expand Down Expand Up @@ -220,11 +213,6 @@ void WebTransport::Init(const GlobalObject& aGlobal, const nsAString& aURL,
// Step 14: Let datagrams be the result of creating a
// WebTransportDatagramDuplexStream, its readable set to
// incomingDatagrams and its writable set to outgoingDatagrams.
mDatagrams = new WebTransportDatagramDuplexStream(mGlobal, this);
mDatagrams->Init(aError);
if (aError.Failed()) {
return;
}

// XXX TODO

Expand All @@ -251,15 +239,8 @@ void WebTransport::Init(const GlobalObject& aGlobal, const nsAString& aURL,
PWebTransport::CreateEndpoints(&parentEndpoint, &childEndpoint));

RefPtr<WebTransportChild> child = new WebTransportChild(this);
if (NS_IsMainThread()) {
if (!childEndpoint.Bind(child)) {
return;
}
} else {
if (!childEndpoint.Bind(child,
mGlobal->EventTargetFor(TaskCategory::Other))) {
return;
}
if (!childEndpoint.Bind(child)) {
return;
}

mState = WebTransportState::CONNECTING;
Expand Down Expand Up @@ -368,7 +349,6 @@ void WebTransport::ResolveWaitingConnection(
}

mChild = aChild;
mDatagrams->SetChild(aChild);
// Step 17.2: Set transport.[[State]] to "connected".
mState = WebTransportState::CONNECTED;
// Step 17.3: Set transport.[[Session]] to session.
Expand Down Expand Up @@ -547,7 +527,9 @@ void WebTransport::Close(const WebTransportCloseInfo& aOptions,

already_AddRefed<WebTransportDatagramDuplexStream> WebTransport::GetDatagrams(
ErrorResult& aError) {
return do_AddRef(mDatagrams);
LOG(("Datagrams() called"));
aError.Throw(NS_ERROR_NOT_IMPLEMENTED);
return nullptr;
}

already_AddRefed<Promise> WebTransport::CreateBidirectionalStream(
Expand Down
14 changes: 1 addition & 13 deletions dom/webtransport/api/WebTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@ class WebTransportDatagramDuplexStream;
class WebTransportIncomingStreamsAlgorithms;
class ReadableStream;
class WritableStream;

using BidirectionalPair = std::pair<RefPtr<mozilla::ipc::DataPipeReceiver>,
RefPtr<mozilla::ipc::DataPipeSender>>;

struct DatagramEntry {
DatagramEntry(nsTArray<uint8_t>&& aData, const mozilla::TimeStamp& aTimeStamp)
: mBuffer(std::move(aData)), mTimeStamp(aTimeStamp) {}
DatagramEntry(Span<uint8_t>& aData, const mozilla::TimeStamp& aTimeStamp)
: mBuffer(aData), mTimeStamp(aTimeStamp) {}

nsTArray<uint8_t> mBuffer;
mozilla::TimeStamp mTimeStamp;
};

class WebTransport final : public nsISupports, public nsWrapperCache {
friend class WebTransportIncomingStreamsAlgorithms;
// For mSendStreams/mReceiveStreams
Expand Down Expand Up @@ -77,9 +68,6 @@ class WebTransport final : public nsISupports, public nsWrapperCache {
void NewUnidirectionalStream(
const RefPtr<mozilla::ipc::DataPipeReceiver>& aStream);

void NewDatagramReceived(nsTArray<uint8_t>&& aData,
const mozilla::TimeStamp& aTimeStamp);

void RemoteClosed(bool aCleanly, const uint32_t& aCode,
const nsACString& aReason);
// WebIDL Boilerplate
Expand Down
Loading

0 comments on commit 0ddabc0

Please sign in to comment.