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/TransformStream.cpp | 8 -------- dom/streams/UnderlyingSinkCallbackHelpers.cpp | 29 ++++++++++++++++++++++----- dom/streams/UnderlyingSinkCallbackHelpers.h | 10 ++++++++- 3 files changed, 33 insertions(+), 14 deletions(-) (limited to 'dom/streams') diff --git a/dom/streams/TransformStream.cpp b/dom/streams/TransformStream.cpp index e517ecda89..3b78cabeea 100644 --- a/dom/streams/TransformStream.cpp +++ b/dom/streams/TransformStream.cpp @@ -20,14 +20,6 @@ #include "mozilla/dom/TransformerBinding.h" #include "nsWrapperCache.h" -// XXX: GCC somehow does not allow attributes before lambda return types, while -// clang requires so. See also bug 1627007. -#ifdef __clang__ -# define MOZ_CAN_RUN_SCRIPT_BOUNDARY_LAMBDA MOZ_CAN_RUN_SCRIPT_BOUNDARY -#else -# define MOZ_CAN_RUN_SCRIPT_BOUNDARY_LAMBDA -#endif - namespace mozilla::dom { using namespace streams_abstract; 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; } diff --git a/dom/streams/UnderlyingSinkCallbackHelpers.h b/dom/streams/UnderlyingSinkCallbackHelpers.h index c99c8709ce..0717176aca 100644 --- a/dom/streams/UnderlyingSinkCallbackHelpers.h +++ b/dom/streams/UnderlyingSinkCallbackHelpers.h @@ -135,6 +135,10 @@ class UnderlyingSinkAlgorithmsWrapper : public UnderlyingSinkAlgorithmsBase { aRetVal.setUndefined(); } + MOZ_CAN_RUN_SCRIPT already_AddRefed WriteCallback( + JSContext* aCx, JS::Handle aChunk, + WritableStreamDefaultController& aController, ErrorResult& aRv) final; + MOZ_CAN_RUN_SCRIPT already_AddRefed CloseCallback( JSContext* aCx, ErrorResult& aRv) final; @@ -142,6 +146,10 @@ class UnderlyingSinkAlgorithmsWrapper : public UnderlyingSinkAlgorithmsBase { JSContext* aCx, const Optional>& aReason, ErrorResult& aRv) final; + virtual already_AddRefed WriteCallbackImpl( + JSContext* aCx, JS::Handle aChunk, + WritableStreamDefaultController& aController, ErrorResult& aRv) = 0; + virtual already_AddRefed CloseCallbackImpl(JSContext* aCx, ErrorResult& aRv) { // (closeAlgorithm is optional, give null by default) @@ -169,7 +177,7 @@ class WritableStreamToOutput final : public UnderlyingSinkAlgorithmsWrapper, // Streams algorithms - already_AddRefed WriteCallback( + already_AddRefed WriteCallbackImpl( JSContext* aCx, JS::Handle aChunk, WritableStreamDefaultController& aController, ErrorResult& aRv) override; -- cgit v1.2.3