Skip to content

Commit 901ea6d

Browse files
committed
fix streams floating point web-platform tests
1 parent 2ea9d8f commit 901ea6d

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void ValueQueue::Consumer::reset() {
9696
impl.reset();
9797
};
9898

99-
size_t ValueQueue::Consumer::size() {
99+
double ValueQueue::Consumer::size() {
100100
return impl.size();
101101
}
102102

@@ -121,13 +121,13 @@ void ValueQueue::Consumer::visitForGc(jsg::GcVisitor& visitor) {
121121

122122
#pragma endregion ValueQueue::Consumer
123123

124-
ValueQueue::ValueQueue(size_t highWaterMark): impl(highWaterMark) {}
124+
ValueQueue::ValueQueue(double highWaterMark): impl(highWaterMark) {}
125125

126126
void ValueQueue::close(jsg::Lock& js) {
127127
impl.close(js);
128128
}
129129

130-
ssize_t ValueQueue::desiredSize() const {
130+
double ValueQueue::desiredSize() const {
131131
return impl.desiredSize();
132132
}
133133

@@ -143,7 +143,7 @@ void ValueQueue::push(jsg::Lock& js, kj::Rc<Entry> entry) {
143143
impl.push(js, kj::mv(entry));
144144
}
145145

146-
size_t ValueQueue::size() const {
146+
double ValueQueue::size() const {
147147
return impl.size();
148148
}
149149

@@ -373,7 +373,7 @@ void ByteQueue::Consumer::reset() {
373373
impl.reset();
374374
}
375375

376-
size_t ByteQueue::Consumer::size() const {
376+
double ByteQueue::Consumer::size() const {
377377
return impl.size();
378378
}
379379

@@ -535,7 +535,7 @@ v8::Local<v8::Uint8Array> ByteQueue::ByobRequest::getView(jsg::Lock& js) {
535535

536536
#pragma endregion ByteQueue::ByobRequest
537537

538-
ByteQueue::ByteQueue(size_t highWaterMark): impl(highWaterMark) {}
538+
ByteQueue::ByteQueue(double highWaterMark): impl(highWaterMark) {}
539539

540540
void ByteQueue::close(jsg::Lock& js) {
541541
KJ_IF_SOME(ready, impl.state.tryGet<ByteQueue::QueueImpl::Ready>()) {
@@ -548,7 +548,7 @@ void ByteQueue::close(jsg::Lock& js) {
548548
impl.close(js);
549549
}
550550

551-
ssize_t ByteQueue::desiredSize() const {
551+
double ByteQueue::desiredSize() const {
552552
return impl.desiredSize();
553553
}
554554

@@ -573,7 +573,7 @@ void ByteQueue::push(jsg::Lock& js, kj::Rc<Entry> entry) {
573573
impl.push(js, kj::mv(entry));
574574
}
575575

576-
size_t ByteQueue::size() const {
576+
double ByteQueue::size() const {
577577
return impl.size();
578578
}
579579

src/workerd/api/streams/queue.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class QueueImpl final {
153153
using Entry = typename Self::Entry;
154154
using State = typename Self::State;
155155

156-
explicit QueueImpl(size_t highWaterMark): highWaterMark(highWaterMark) {}
156+
explicit QueueImpl(double highWaterMark): highWaterMark(highWaterMark) {}
157157

158158
QueueImpl(QueueImpl&&) = default;
159159
QueueImpl& operator=(QueueImpl&&) = default;
@@ -176,7 +176,7 @@ class QueueImpl final {
176176
// The value can be zero or negative, in which case backpressure is
177177
// signaled on the queue.
178178
// If the queue is already closed or errored, return 0.
179-
inline ssize_t desiredSize() const {
179+
inline double desiredSize() const {
180180
return state.template is<Ready>() ? highWaterMark - size() : 0;
181181
}
182182

@@ -231,7 +231,7 @@ class QueueImpl final {
231231
}
232232

233233
// The current size of consumer with the most stored data.
234-
size_t size() const {
234+
double size() const {
235235
return totalQueueSize;
236236
}
237237

@@ -293,8 +293,8 @@ class QueueImpl final {
293293
SmallSet<ConsumerImpl*> consumers;
294294
};
295295

296-
size_t highWaterMark;
297-
size_t totalQueueSize = 0;
296+
double highWaterMark;
297+
double totalQueueSize = 0;
298298
kj::OneOf<Ready, Closed, Errored> state = Ready();
299299

300300
void addConsumer(ConsumerImpl* consumer) {
@@ -432,7 +432,7 @@ class ConsumerImpl final {
432432
}
433433

434434
// The current total calculated size of the consumer's internal buffer.
435-
size_t size() const {
435+
double size() const {
436436
KJ_SWITCH_ONEOF(state) {
437437
KJ_CASE_ONEOF(e, Errored) {
438438
return 0;
@@ -550,7 +550,7 @@ class ConsumerImpl final {
550550
struct Ready {
551551
workerd::RingBuffer<kj::OneOf<QueueEntry, Close>, 16> buffer;
552552
std::list<ReadRequest> readRequests;
553-
size_t queueTotalSize = 0;
553+
double queueTotalSize = 0;
554554

555555
inline kj::StringPtr jsgGetMemoryName() const;
556556
inline size_t jsgGetMemorySelfSize() const;
@@ -712,7 +712,7 @@ class ValueQueue final {
712712

713713
void reset();
714714

715-
size_t size();
715+
double size();
716716

717717
kj::Own<Consumer> clone(
718718
jsg::Lock& js, kj::Maybe<ConsumerImpl::StateListener&> stateListener = kj::none);
@@ -732,19 +732,19 @@ class ValueQueue final {
732732
friend class ValueQueue;
733733
};
734734

735-
explicit ValueQueue(size_t highWaterMark);
735+
explicit ValueQueue(double highWaterMark);
736736

737737
void close(jsg::Lock& js);
738738

739-
ssize_t desiredSize() const;
739+
double desiredSize() const;
740740

741741
void error(jsg::Lock& js, jsg::Value reason);
742742

743743
void maybeUpdateBackpressure();
744744

745745
void push(jsg::Lock& js, kj::Rc<Entry> entry);
746746

747-
size_t size() const;
747+
double size() const;
748748

749749
size_t getConsumerCount();
750750

@@ -932,7 +932,7 @@ class ByteQueue final {
932932

933933
void reset();
934934

935-
size_t size() const;
935+
double size() const;
936936

937937
kj::Own<Consumer> clone(
938938
jsg::Lock& js, kj::Maybe<ConsumerImpl::StateListener&> stateListener = kj::none);
@@ -949,19 +949,19 @@ class ByteQueue final {
949949
ConsumerImpl impl;
950950
};
951951

952-
explicit ByteQueue(size_t highWaterMark);
952+
explicit ByteQueue(double highWaterMark);
953953

954954
void close(jsg::Lock& js);
955955

956-
ssize_t desiredSize() const;
956+
double desiredSize() const;
957957

958958
void error(jsg::Lock& js, jsg::Value reason);
959959

960960
void maybeUpdateBackpressure();
961961

962962
void push(jsg::Lock& js, kj::Rc<Entry> entry);
963963

964-
size_t size() const;
964+
double size() const;
965965

966966
size_t getConsumerCount();
967967

src/wpt/streams-test.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,7 @@ export default {
442442
'getReader() should call ToString() on mode',
443443
],
444444
},
445-
'readable-streams/floating-point-total-queue-size.any.js': {
446-
comment: 'Queue size needs to use double math',
447-
expectedFailures: [
448-
'Floating point arithmetic must manifest near NUMBER.MAX_SAFE_INTEGER (total ends up positive)',
449-
'Floating point arithmetic must manifest near 0 (total ends up positive, but clamped)',
450-
'Floating point arithmetic must manifest near 0 (total ends up positive, and not clamped)',
451-
'Floating point arithmetic must manifest near 0 (total ends up zero)',
452-
],
453-
},
445+
'readable-streams/floating-point-total-queue-size.any.js': {},
454446
'readable-streams/from.any.js': {
455447
comment: 'See comments on tests',
456448
disabledTests: [
@@ -796,15 +788,7 @@ export default {
796788
'writable-streams/count-queuing-strategy.any.js': {},
797789
'writable-streams/crashtests/garbage-collection.any.js': {},
798790
'writable-streams/error.any.js': {},
799-
'writable-streams/floating-point-total-queue-size.any.js': {
800-
comment: 'Seems we should be using a double for queue size',
801-
expectedFailures: [
802-
'Floating point arithmetic must manifest near NUMBER.MAX_SAFE_INTEGER (total ends up positive)',
803-
'Floating point arithmetic must manifest near 0 (total ends up positive, but clamped)',
804-
'Floating point arithmetic must manifest near 0 (total ends up positive, and not clamped)',
805-
'Floating point arithmetic must manifest near 0 (total ends up zero)',
806-
],
807-
},
791+
'writable-streams/floating-point-total-queue-size.any.js': {},
808792
'writable-streams/garbage-collection.any.js': {},
809793
'writable-streams/general.any.js': {
810794
comment: 'To be investigated',

0 commit comments

Comments
 (0)