Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function howMuchToRead(n, state) {
if (state.objectMode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if state is undefined?

return n === 0 ? 0 : 1;

if (n === null || isNaN(n)) {
if (n === null || n !== n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a little paranoid here and totally not related to this PR, but If n is not a number, then we might fail somewhere with improper error message I guess.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point. This may not just be checking it it is NaN, but also non-number values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis This does change the functionality from isNaN(n) to Number.isNaN(n) (don't we all love JS). The only way I can think to make sure it matches is to change the check to:

if (n === null || (+n) != n) {

// only flow one buffer at a time
if (state.flowing && state.buffer.length)
return state.buffer[0].length;
Expand Down