diff --git a/dom/streams/ReadableByteStreamController.cpp b/dom/streams/ReadableByteStreamController.cpp index 4645293dc7e7..32b5edb8f4f3 100644 --- a/dom/streams/ReadableByteStreamController.cpp +++ b/dom/streams/ReadableByteStreamController.cpp @@ -1895,10 +1895,8 @@ void SetUpReadableByteStreamController( } // Let startPromise be a promise resolved with startResult. - RefPtr startPromise = Promise::Create(GetIncumbentGlobal(), aRv); - if (aRv.Failed()) { - return; - } + RefPtr startPromise = + Promise::CreateInfallible(GetIncumbentGlobal()); startPromise->MaybeResolve(startResult); // Step 16+17 diff --git a/dom/streams/ReadableStream.cpp b/dom/streams/ReadableStream.cpp index 21870e0f7f2d..45046768cf5f 100644 --- a/dom/streams/ReadableStream.cpp +++ b/dom/streams/ReadableStream.cpp @@ -331,11 +331,8 @@ already_AddRefed ReadableStreamCancel(JSContext* aCx, // Step 2. if (aStream->State() == ReadableStream::ReaderState::Closed) { - RefPtr promise = Promise::Create(aStream->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } - + RefPtr promise = + Promise::CreateInfallible(aStream->GetParentObject()); promise->MaybeResolveWithUndefined(); return promise.forget(); } @@ -387,10 +384,7 @@ already_AddRefed ReadableStreamCancel(JSContext* aCx, // Step 8. RefPtr promise = - Promise::Create(sourceCancelPromise->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + Promise::CreateInfallible(sourceCancelPromise->GetParentObject()); // ThenWithCycleCollectedArgs will carry promise, keeping it alive until the // callback executes. @@ -894,10 +888,7 @@ already_AddRefed ReadableStream::GetNextIterationResult( MOZ_ASSERT(reader->GetStream()); // Step 3. Let promise be a new promise. - RefPtr promise = Promise::Create(GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr promise = Promise::CreateInfallible(GetParentObject()); // Step 4. Let readRequest be a new read request with the following items: RefPtr request = new IteratorReadRequest(promise, reader); diff --git a/dom/streams/ReadableStreamBYOBReader.cpp b/dom/streams/ReadableStreamBYOBReader.cpp index b8281e204b45..6c615e03404d 100644 --- a/dom/streams/ReadableStreamBYOBReader.cpp +++ b/dom/streams/ReadableStreamBYOBReader.cpp @@ -255,10 +255,7 @@ already_AddRefed ReadableStreamBYOBReader::Read( } // Step 5. - RefPtr promise = Promise::Create(GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr promise = Promise::CreateInfallible(GetParentObject()); // Step 6. Let readIntoRequest be a new read-into request with the following // items: diff --git a/dom/streams/ReadableStreamDefaultController.cpp b/dom/streams/ReadableStreamDefaultController.cpp index dda3ec75fc21..df8b2d7285bb 100644 --- a/dom/streams/ReadableStreamDefaultController.cpp +++ b/dom/streams/ReadableStreamDefaultController.cpp @@ -507,10 +507,7 @@ void SetUpReadableStreamDefaultController( // Step 10. RefPtr startPromise = - Promise::Create(aStream->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aStream->GetParentObject()); startPromise->MaybeResolve(startResult); // Step 11 & 12: diff --git a/dom/streams/ReadableStreamDefaultReader.cpp b/dom/streams/ReadableStreamDefaultReader.cpp index 218ef9f37bcc..014aca9652b7 100644 --- a/dom/streams/ReadableStreamDefaultReader.cpp +++ b/dom/streams/ReadableStreamDefaultReader.cpp @@ -67,10 +67,8 @@ bool ReadableStreamReaderGenericInitialize(ReadableStreamGenericReader* aReader, // Step 2. aStream->SetReader(aReader); - aReader->SetClosedPromise(Promise::Create(aReader->GetParentObject(), aRv)); - if (aRv.Failed()) { - return false; - } + aReader->SetClosedPromise( + Promise::CreateInfallible(aReader->GetParentObject())); switch (aStream->State()) { // Step 3. @@ -247,7 +245,7 @@ already_AddRefed ReadableStreamDefaultReader::Read(ErrorResult& aRv) { } // Step 2. - RefPtr promise = Promise::Create(GetParentObject(), aRv); + RefPtr promise = Promise::CreateInfallible(GetParentObject()); // Step 3. RefPtr request = new Read_ReadRequest(promise); diff --git a/dom/streams/ReadableStreamPipeTo.cpp b/dom/streams/ReadableStreamPipeTo.cpp index cbbaac43607e..71ddf6d190fe 100644 --- a/dom/streams/ReadableStreamPipeTo.cpp +++ b/dom/streams/ReadableStreamPipeTo.cpp @@ -941,10 +941,8 @@ already_AddRefed ReadableStreamPipeTo( // Note: PipeToPump ensures this by construction. // Step 13. Let promise be a new promise. - RefPtr promise = Promise::Create(aSource->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr promise = + Promise::CreateInfallible(aSource->GetParentObject()); // Steps 14-15. RefPtr pump = new PipeToPump( diff --git a/dom/streams/TeeState.cpp b/dom/streams/TeeState.cpp index 806107421ffa..349583977862 100644 --- a/dom/streams/TeeState.cpp +++ b/dom/streams/TeeState.cpp @@ -47,10 +47,7 @@ already_AddRefed TeeState::Create(ReadableStream* aStream, teeState->SetReader(reader); RefPtr promise = - Promise::Create(teeState->GetStream()->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + Promise::CreateInfallible(teeState->GetStream()->GetParentObject()); teeState->SetCancelPromise(promise); return teeState.forget(); diff --git a/dom/streams/Transferable.cpp b/dom/streams/Transferable.cpp index f436e5aa8ba0..c3aaa93a4be1 100644 --- a/dom/streams/Transferable.cpp +++ b/dom/streams/Transferable.cpp @@ -178,7 +178,8 @@ class SetUpTransformWritableMessageEventListener final Promise* BackpressurePromise() { return mBackpressurePromise; } void CreateBackpressurePromise(ErrorResult& aRv) { - mBackpressurePromise = Promise::Create(mController->GetParentObject(), aRv); + mBackpressurePromise = + Promise::CreateInfallible(mController->GetParentObject()); } private: @@ -449,10 +450,7 @@ MOZ_CAN_RUN_SCRIPT static void SetUpCrossRealmTransformWritable( // Step 3: Let backpressurePromise be a new promise. RefPtr backpressurePromise = - Promise::Create(aWritable->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aWritable->GetParentObject()); // Step 4: Add a handler for port’s message event with the following steps: auto listener = MakeRefPtr( diff --git a/dom/streams/TransformStream.cpp b/dom/streams/TransformStream.cpp index 6765c1620c5b..6ec994529d2c 100644 --- a/dom/streams/TransformStream.cpp +++ b/dom/streams/TransformStream.cpp @@ -517,10 +517,7 @@ void TransformStream::SetBackpressure(bool aBackpressure, ErrorResult& aRv) { } // Step 3. Set stream.[[backpressureChangePromise]] to a new promise. - RefPtr promise = Promise::Create(GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + RefPtr promise = Promise::CreateInfallible(GetParentObject()); mBackpressureChangePromise = promise; // Step 4. Set stream.[[backpressure]] to backpressure. @@ -657,10 +654,7 @@ already_AddRefed TransformStream::Constructor( // Step 9. Let startPromise be a new promise. nsCOMPtr global = do_QueryInterface(aGlobal.GetAsSupports()); - RefPtr startPromise = Promise::Create(global, aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr startPromise = Promise::CreateInfallible(global); // Step 10. Perform ! InitializeTransformStream(this, startPromise, // writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, diff --git a/dom/streams/WritableStream.cpp b/dom/streams/WritableStream.cpp index 8d10ff4836cb..e910e294544f 100644 --- a/dom/streams/WritableStream.cpp +++ b/dom/streams/WritableStream.cpp @@ -422,10 +422,8 @@ void WritableStream::UpdateBackpressure(bool aBackpressure, ErrorResult& aRv) { // Step 4.1. If backpressure is true, set writer.[[readyPromise]] to a new // promise. if (aBackpressure) { - RefPtr promise = Promise::Create(writer->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + RefPtr promise = + Promise::CreateInfallible(writer->GetParentObject()); writer->SetReadyPromise(promise); } else { // Step 4.2. Otherwise, @@ -513,10 +511,8 @@ already_AddRefed WritableStreamAbort(JSContext* aCx, // resolved with undefined. if (aStream->State() == WritableStream::WriterState::Closed || aStream->State() == WritableStream::WriterState::Errored) { - RefPtr promise = Promise::Create(aStream->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr promise = + Promise::CreateInfallible(aStream->GetParentObject()); promise->MaybeResolveWithUndefined(); return promise.forget(); } @@ -533,10 +529,8 @@ already_AddRefed WritableStreamAbort(JSContext* aCx, // code and that might have changed the state. if (aStream->State() == WritableStream::WriterState::Closed || aStream->State() == WritableStream::WriterState::Errored) { - RefPtr promise = Promise::Create(aStream->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr promise = + Promise::CreateInfallible(aStream->GetParentObject()); promise->MaybeResolveWithUndefined(); return promise.forget(); } @@ -565,10 +559,8 @@ already_AddRefed WritableStreamAbort(JSContext* aCx, } // Step 9. Let promise be a new promise. - RefPtr promise = Promise::Create(aStream->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr promise = + Promise::CreateInfallible(aStream->GetParentObject()); // Step 10. Set stream.[[pendingAbortRequest]] to a new pending abort request // whose promise is promise, reason is reason, and was already erroring is @@ -628,10 +620,8 @@ already_AddRefed WritableStreamClose(JSContext* aCx, MOZ_ASSERT(!aStream->CloseQueuedOrInFlight()); // Step 5. Let promise be a new promise. - RefPtr promise = Promise::Create(aStream->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr promise = + Promise::CreateInfallible(aStream->GetParentObject()); // Step 6. Set stream.[[closeRequest]] to promise. aStream->SetCloseRequest(promise); @@ -742,10 +732,8 @@ already_AddRefed WritableStreamAddWriteRequest(WritableStream* aStream, MOZ_ASSERT(aStream->State() == WritableStream::WriterState::Writable); // Step 3. Let promise be a new promise. - RefPtr promise = Promise::Create(aStream->GetParentObject(), aRv); - if (aRv.Failed()) { - return nullptr; - } + RefPtr promise = + Promise::CreateInfallible(aStream->GetParentObject()); // Step 4. Append promise to stream.[[writeRequests]]. aStream->AppendWriteRequest(promise); diff --git a/dom/streams/WritableStreamDefaultController.cpp b/dom/streams/WritableStreamDefaultController.cpp index 32099f8f3974..2f0964bc8f24 100644 --- a/dom/streams/WritableStreamDefaultController.cpp +++ b/dom/streams/WritableStreamDefaultController.cpp @@ -184,10 +184,7 @@ void SetUpWritableStreamDefaultController( // Step 16. Let startPromise be a promise resolved with startResult. RefPtr startPromise = - Promise::Create(aStream->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aStream->GetParentObject()); startPromise->MaybeResolve(startResult); // Step 17/18. diff --git a/dom/streams/WritableStreamDefaultWriter.cpp b/dom/streams/WritableStreamDefaultWriter.cpp index c7f1186ce799..b3728420e890 100644 --- a/dom/streams/WritableStreamDefaultWriter.cpp +++ b/dom/streams/WritableStreamDefaultWriter.cpp @@ -382,10 +382,7 @@ void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter, // Step 5. If state is "writable", if (state == WritableStream::WriterState::Writable) { RefPtr readyPromise = - Promise::Create(aWriter->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aWriter->GetParentObject()); // Step 5.1 If ! WritableStreamCloseQueuedOrInFlight(stream) is false and // stream.[[backpressure]] is true, set writer.[[readyPromise]] to a new @@ -401,10 +398,7 @@ void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter, // Step 5.3. Set writer.[[closedPromise]] to a new promise. RefPtr closedPromise = - Promise::Create(aWriter->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aWriter->GetParentObject()); aWriter->SetClosedPromise(closedPromise); } else if (state == WritableStream::WriterState::Erroring) { // Step 6. Otherwise, if state is "erroring", @@ -413,10 +407,7 @@ void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter, // stream.[[storedError]]. JS::Rooted storedError(RootingCx(), aStream->StoredError()); RefPtr readyPromise = - Promise::Create(aWriter->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aWriter->GetParentObject()); readyPromise->MaybeReject(storedError); aWriter->SetReadyPromise(readyPromise); @@ -425,10 +416,7 @@ void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter, // Step 6.3. Set writer.[[closedPromise]] to a new promise. RefPtr closedPromise = - Promise::Create(aWriter->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aWriter->GetParentObject()); aWriter->SetClosedPromise(closedPromise); } else if (state == WritableStream::WriterState::Closed) { // Step 7. Otherwise, if state is "closed", @@ -460,10 +448,7 @@ void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter, // Step 8.3. Set writer.[[readyPromise]] to a promise rejected with // storedError. RefPtr readyPromise = - Promise::Create(aWriter->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aWriter->GetParentObject()); readyPromise->MaybeReject(storedError); aWriter->SetReadyPromise(readyPromise); @@ -473,10 +458,7 @@ void SetUpWritableStreamDefaultWriter(WritableStreamDefaultWriter* aWriter, // Step 8.5. Set writer.[[closedPromise]] to a promise rejected with // storedError. RefPtr closedPromise = - Promise::Create(aWriter->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + Promise::CreateInfallible(aWriter->GetParentObject()); closedPromise->MaybeReject(storedError); aWriter->SetClosedPromise(closedPromise); @@ -497,10 +479,7 @@ void WritableStreamDefaultWriterEnsureClosedPromiseRejected( } else { // Step 2. Otherwise, set writer.[[closedPromise]] to a promise rejected // with error. - closedPromise = Promise::Create(aWriter->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + closedPromise = Promise::CreateInfallible(aWriter->GetParentObject()); closedPromise->MaybeReject(aError); aWriter->SetClosedPromise(closedPromise); } @@ -521,10 +500,7 @@ void WritableStreamDefaultWriterEnsureReadyPromiseRejected( } else { // Step 2. Otherwise, set writer.[[readyPromise]] to a promise rejected with // error. - readyPromise = Promise::Create(aWriter->GetParentObject(), aRv); - if (aRv.Failed()) { - return; - } + readyPromise = Promise::CreateInfallible(aWriter->GetParentObject()); readyPromise->MaybeReject(aError); aWriter->SetReadyPromise(readyPromise); }