summaryrefslogtreecommitdiffstats
path: root/dom/streams
diff options
context:
space:
mode:
Diffstat (limited to 'dom/streams')
-rw-r--r--dom/streams/TransformStream.cpp8
-rw-r--r--dom/streams/UnderlyingSinkCallbackHelpers.cpp29
-rw-r--r--dom/streams/UnderlyingSinkCallbackHelpers.h10
3 files changed, 33 insertions, 14 deletions
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
@@ -111,6 +111,24 @@ already_AddRefed<Promise> UnderlyingSinkAlgorithms::AbortCallback(
}
// 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<Promise> UnderlyingSinkAlgorithmsWrapper::WriteCallback(
+ JSContext* aCx, JS::Handle<JS::Value> aChunk,
+ WritableStreamDefaultController& aController, ErrorResult& aRv) {
+ nsCOMPtr<nsIGlobalObject> 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<Promise> UnderlyingSinkAlgorithmsWrapper::CloseCallback(
JSContext* aCx, ErrorResult& aRv) {
@@ -182,19 +200,20 @@ WritableStreamToOutput::OnOutputStreamReady(nsIAsyncOutputStream* aStream) {
return NS_OK;
}
-already_AddRefed<Promise> WritableStreamToOutput::WriteCallback(
+already_AddRefed<Promise> WritableStreamToOutput::WriteCallbackImpl(
JSContext* aCx, JS::Handle<JS::Value> 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 = Promise::Create(mParent, aError);
- if (NS_WARN_IF(aError.Failed())) {
+ RefPtr<Promise> 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<Promise> WriteCallback(
+ JSContext* aCx, JS::Handle<JS::Value> aChunk,
+ WritableStreamDefaultController& aController, ErrorResult& aRv) final;
+
MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> CloseCallback(
JSContext* aCx, ErrorResult& aRv) final;
@@ -142,6 +146,10 @@ class UnderlyingSinkAlgorithmsWrapper : public UnderlyingSinkAlgorithmsBase {
JSContext* aCx, const Optional<JS::Handle<JS::Value>>& aReason,
ErrorResult& aRv) final;
+ virtual already_AddRefed<Promise> WriteCallbackImpl(
+ JSContext* aCx, JS::Handle<JS::Value> aChunk,
+ WritableStreamDefaultController& aController, ErrorResult& aRv) = 0;
+
virtual already_AddRefed<Promise> 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<Promise> WriteCallback(
+ already_AddRefed<Promise> WriteCallbackImpl(
JSContext* aCx, JS::Handle<JS::Value> aChunk,
WritableStreamDefaultController& aController, ErrorResult& aRv) override;