From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- dom/streams/UnderlyingSinkCallbackHelpers.cpp | 29 ++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'dom/streams/UnderlyingSinkCallbackHelpers.cpp') diff --git a/dom/streams/UnderlyingSinkCallbackHelpers.cpp b/dom/streams/UnderlyingSinkCallbackHelpers.cpp index 91562a2db3..6277fd26e0 100644 --- a/dom/streams/UnderlyingSinkCallbackHelpers.cpp +++ b/dom/streams/UnderlyingSinkCallbackHelpers.cpp @@ -110,6 +110,24 @@ already_AddRefed UnderlyingSinkAlgorithms::AbortCallback( return promise.forget(); } +// https://streams.spec.whatwg.org/#writable-set-up +// This one is not covered by the above section as the spec expects any spec +// implementation to explicitly return a promise for this callback. It's still +// useful for Gecko as error handling is very frequently done with +// ErrorResult instead of a rejected promise. See also +// https://github.com/whatwg/streams/issues/1253. +already_AddRefed UnderlyingSinkAlgorithmsWrapper::WriteCallback( + JSContext* aCx, JS::Handle aChunk, + WritableStreamDefaultController& aController, ErrorResult& aRv) { + nsCOMPtr global = xpc::CurrentNativeGlobal(aCx); + return PromisifyAlgorithm( + global, + [&](ErrorResult& aRv) { + return WriteCallbackImpl(aCx, aChunk, aController, aRv); + }, + aRv); +} + // https://streams.spec.whatwg.org/#writable-set-up // Step 2.1: Let closeAlgorithmWrapper be an algorithm that runs these steps: already_AddRefed UnderlyingSinkAlgorithmsWrapper::CloseCallback( @@ -182,19 +200,20 @@ WritableStreamToOutput::OnOutputStreamReady(nsIAsyncOutputStream* aStream) { return NS_OK; } -already_AddRefed WritableStreamToOutput::WriteCallback( +already_AddRefed WritableStreamToOutput::WriteCallbackImpl( JSContext* aCx, JS::Handle aChunk, - WritableStreamDefaultController& aController, ErrorResult& aError) { + WritableStreamDefaultController& aController, ErrorResult& aRv) { ArrayBufferViewOrArrayBuffer data; if (!data.Init(aCx, aChunk)) { - aError.StealExceptionFromJSContext(aCx); + aRv.MightThrowJSException(); + aRv.StealExceptionFromJSContext(aCx); return nullptr; } // buffer/bufferView MOZ_ASSERT(data.IsArrayBuffer() || data.IsArrayBufferView()); - RefPtr promise = Promise::Create(mParent, aError); - if (NS_WARN_IF(aError.Failed())) { + RefPtr promise = Promise::Create(mParent, aRv); + if (NS_WARN_IF(aRv.Failed())) { return nullptr; } -- cgit v1.2.3