Skip to content

Commit 25e3c11

Browse files
authored
throw appropriate signal.reason on empty (#5762)
1 parent 58efd04 commit 25e3c11

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/workerd/api/streams/standard.c++

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,17 @@ WritableImpl<Self>::WritableImpl(
11351135
template <typename Self>
11361136
jsg::Promise<void> WritableImpl<Self>::abort(
11371137
jsg::Lock& js, jsg::Ref<Self> self, v8::Local<v8::Value> reason) {
1138-
signal->triggerAbort(js, jsg::JsValue(reason));
1138+
// Per the spec, the signal.reason should be a DOMException with name 'AbortError'
1139+
// when no reason is provided, but the stored error should remain as the original reason.
1140+
auto signalReason = [&]() -> jsg::JsValue {
1141+
if (reason->IsUndefined() && FeatureFlags::get(js).getPedanticWpt()) {
1142+
auto ex = js.domException(
1143+
kj::str("AbortError"), kj::str("This writable stream has been aborted."), kj::none);
1144+
return jsg::JsValue(KJ_ASSERT_NONNULL(ex.tryGetHandle(js)));
1145+
}
1146+
return jsg::JsValue(reason);
1147+
}();
1148+
signal->triggerAbort(js, signalReason);
11391149

11401150
// We have to check this again after the AbortSignal is triggered.
11411151
if (state.template is<StreamStates::Closed>() || state.template is<StreamStates::Errored>()) {

src/wpt/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ wpt_test(
111111
wpt_test(
112112
name = "streams",
113113
size = "large",
114+
compat_flags = ["pedantic_wpt"],
114115
config = "streams-test.ts",
115116
wpt_directory = "@wpt//:streams@module",
116117
)

src/wpt/streams-test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,6 @@ export default {
734734
"Aborting a WritableStream before it starts should cause the writer's unsettled ready promise to reject",
735735
"WritableStream if sink's abort throws, the promise returned by multiple writer.abort()s is the same and rejects",
736736
'when calling abort() twice on the same stream, both should give the same promise that fulfills with undefined',
737-
'the abort signal is signalled synchronously - write',
738737
'Aborting a WritableStream causes any outstanding write() promises to be rejected with the reason supplied',
739738
'Aborting a WritableStream puts it in an errored state with the error passed to abort()',
740739
'if a writer is created for a stream with a pending abort, its ready should be rejected with the abort error',

0 commit comments

Comments
 (0)