Skip to content

Commit 4ecc4e5

Browse files
authored
improve streams wpt coverage (#5759)
1 parent 40ffa84 commit 4ecc4e5

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ void WritableImpl<Self>::setup(jsg::Lock& js,
14771477
dealWithRejection(js, kj::mv(self), handle);
14781478
});
14791479

1480-
flags.backpressure = getDesiredSize() < 0;
1480+
flags.backpressure = getDesiredSize() <= 0;
14811481

14821482
maybeRunAlgorithm(js, startAlgorithm, kj::mv(onSuccess), kj::mv(onFailure), self.addRef());
14831483
}
@@ -3351,6 +3351,10 @@ jsg::Promise<void> WritableStreamJsController::close(jsg::Lock& js, bool markAsH
33513351
js, js.v8TypeError("This WritableStream has been closed."_kj), markAsHandled);
33523352
}
33533353
KJ_CASE_ONEOF(errored, StreamStates::Errored) {
3354+
if (FeatureFlags::get(js).getPedanticWpt()) {
3355+
return rejectedMaybeHandledPromise<void>(
3356+
js, js.v8TypeError("This WritableStream has been errored."_kj), markAsHandled);
3357+
}
33543358
return rejectedMaybeHandledPromise<void>(js, errored.getHandle(js), markAsHandled);
33553359
}
33563360
KJ_CASE_ONEOF(controller, Controller) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,14 @@ void WritableStreamDefaultWriter::replaceReadyPromise(
177177
this->readyPromise = KJ_ASSERT_NONNULL(this->readyPromisePending).whenResolved(js);
178178
}
179179

180-
jsg::Promise<void> WritableStreamDefaultWriter::write(jsg::Lock& js, v8::Local<v8::Value> chunk) {
180+
jsg::Promise<void> WritableStreamDefaultWriter::write(
181+
jsg::Lock& js, jsg::Optional<v8::Local<v8::Value>> chunk) {
181182
KJ_SWITCH_ONEOF(state) {
182183
KJ_CASE_ONEOF(i, Initial) {
183184
KJ_FAIL_ASSERT("this writer was never attached");
184185
}
185186
KJ_CASE_ONEOF(stream, Attached) {
186-
return stream->getController().write(js, chunk);
187+
return stream->getController().write(js, kj::mv(chunk));
187188
}
188189
KJ_CASE_ONEOF(r, Released) {
189190
return js.rejectedPromise<void>(

src/workerd/api/streams/writable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class WritableStreamDefaultWriter: public jsg::Object, public WritableStreamCont
3939
// complete on this side if we don't care that they're actually read?
4040
jsg::Promise<void> close(jsg::Lock& js);
4141

42-
jsg::Promise<void> write(jsg::Lock& js, v8::Local<v8::Value> chunk);
42+
jsg::Promise<void> write(jsg::Lock& js, jsg::Optional<v8::Local<v8::Value>> chunk);
4343
void releaseLock(jsg::Lock& js);
4444

4545
JSG_RESOURCE_TYPE(WritableStreamDefaultWriter, CompatibilityFlags::Reader flags) {

src/wpt/streams-test.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,6 @@ export default {
738738
'Aborting a WritableStream puts it in an errored state with the error passed to abort()',
739739
'if a writer is created for a stream with a pending abort, its ready should be rejected with the abort error',
740740
'sink abort() should not be called if stream was erroring due to bad strategy before abort() was called',
741-
"WritableStream if sink's abort throws, for an abort performed during a write, the promise returned by ws.abort() rejects",
742741
'writer.abort() while there is an in-flight write, and then finish the write with rejection',
743742
'writer.abort(), controller.error() while there is an in-flight write, and then finish the write',
744743
'writer.abort(), controller.error() while there is an in-flight close, and then finish the close',
@@ -773,7 +772,6 @@ export default {
773772
expectedFailures: [
774773
'when close is called on a WritableStream in waiting state, ready promise should be fulfilled',
775774
'releaseLock() should not change the result of sync close()',
776-
'close() on an errored stream should reject',
777775
],
778776
},
779777
'writable-streams/constructor.any.js': {
@@ -814,13 +812,7 @@ export default {
814812
'ready promise should fire before closed on releaseLock',
815813
],
816814
},
817-
'writable-streams/properties.any.js': {
818-
comment: 'To be investigated',
819-
expectedFailures: [
820-
'sink method write should be called with the right number of arguments',
821-
"sink method write should be called even when it's located on the prototype chain",
822-
],
823-
},
815+
'writable-streams/properties.any.js': {},
824816
'writable-streams/reentrant-strategy.any.js': {
825817
comment: 'A hanging Promise was canceled.',
826818
disabledTests: true,
@@ -829,15 +821,12 @@ export default {
829821
comment: 'To be investigated',
830822
expectedFailures: [
831823
"underlying sink's write or close should not be called if start throws",
832-
'when start() rejects, writer promises should reject in standard order',
833824
],
834825
},
835826
'writable-streams/write.any.js': {
836827
comment: 'To be investigated',
837828
expectedFailures: [
838-
'write() on a stream with HWM 0 should not cause the ready Promise to resolve',
839829
'WritableStream should transition to waiting until write is acknowledged',
840-
"when sink's write throws an error, the stream should become errored and the promise should reject",
841830
],
842831
},
843832
} satisfies TestRunnerConfig;

0 commit comments

Comments
 (0)