Skip to content

Commit 72d64a4

Browse files
authored
Merge pull request #5778 from cloudflare/yagiz/byte-length-queueing-strategy-size
make sure ByteLengthQueuingStrategy::size handles objects
2 parents 140ecc0 + d4ddbf5 commit 72d64a4

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,18 @@ jsg::Optional<uint32_t> ByteLengthQueuingStrategy::size(
512512
} else if ((value)->IsArrayBufferView()) {
513513
auto view = value.As<v8::ArrayBufferView>();
514514
return view->ByteLength();
515+
} else {
516+
// Per the WHATWG Streams spec, ByteLengthQueuingStrategy.size should return
517+
// GetV(chunk, "byteLength"), which means getting the byteLength property
518+
// from any object, not just ArrayBuffer/ArrayBufferView.
519+
KJ_IF_SOME(obj, jsg::JsValue(value).tryCast<jsg::JsObject>()) {
520+
auto byteLength = obj.get(js, "byteLength"_kj);
521+
KJ_IF_SOME(num, byteLength.tryCast<jsg::JsNumber>()) {
522+
KJ_IF_SOME(val, num.value(js)) {
523+
return static_cast<uint32_t>(val);
524+
}
525+
}
526+
}
515527
}
516528
}
517529
return kj::none;

src/wpt/streams-test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,7 @@ export default {
727727
'write: returning a rejected promise (second write) should cause writer write() and ready to reject',
728728
],
729729
},
730-
'writable-streams/byte-length-queuing-strategy.any.js': {
731-
comment:
732-
'TypeError: The value cannot be converted because it is not an integer.',
733-
expectedFailures: [
734-
'Closing a writable stream with in-flight writes below the high water mark delays the close call properly',
735-
],
736-
},
730+
'writable-streams/byte-length-queuing-strategy.any.js': {},
737731
'writable-streams/close.any.js': {
738732
comment: 'To be investigated',
739733
expectedFailures: [

0 commit comments

Comments
 (0)