stream: fix isDetachedBuffer validations in ReadableStream#44114
Conversation
Signed-off-by: Daeyeon Jeong [email protected]
Signed-off-by: Daeyeon Jeong [email protected]
Signed-off-by: Daeyeon Jeong [email protected]
This reverts commit 6f6ba3e. Signed-off-by: Daeyeon Jeong [email protected]
Signed-off-by: Daeyeon Jeong [email protected]
Signed-off-by: Daeyeon Jeong [email protected]
lib/internal/webstreams/util.js
Outdated
There was a problem hiding this comment.
Non-blocking comment: this change is fine in context of this PR, but it probably should be rewritten in a follow-up.
It would be better if is* functions always returned boolean without throwing. If we want to throw, validate* function is preferable.
Since either true or false won't make sense if provided value is not a buffer, it looks like an acceptable temporal solution.
There was a problem hiding this comment.
Indeed, it looks better to follow the coding convention.
I updated the util using assert instead, since, as you mentioned, either true or false won't make sense if a provided value is not a buffer. We can guarantee a passing value is a buffer since it's internal util. PTAL.
Signed-off-by: Daeyeon Jeong [email protected]
Signed-off-by: Daeyeon Jeong [email protected]
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Can you use validateBuffer instead?
node/lib/internal/validators.js
Lines 200 to 206 in d83446b
lib/internal/webstreams/util.js
Outdated
There was a problem hiding this comment.
Is this useful? I think the error thrown by V8 enough (and clearer).
| assert(isArrayBuffer(buffer)); |
There was a problem hiding this comment.
On second thought, seemingly it can be deleted in the current version of this PR. Fixed.
lib/internal/webstreams/util.js
Outdated
There was a problem hiding this comment.
same here
| assert(isArrayBufferView(view)); |
There was a problem hiding this comment.
| reader | |
| .read(view) | |
| .then(common.mustNotCall()) | |
| .catch( | |
| common.mustCall( | |
| common.expectsError({ | |
| code: 'ERR_INVALID_STATE', | |
| name: 'TypeError', | |
| }), | |
| ), | |
| ); | |
| assert.rejects( | |
| reader.read(view), | |
| { | |
| code: 'ERR_INVALID_STATE', | |
| name: 'TypeError', | |
| } | |
| ).then(common.mustCall()); |
There was a problem hiding this comment.
| reader | |
| .read(view) | |
| .then(common.mustNotCall()) | |
| .catch( | |
| common.mustCall( | |
| common.expectsError({ | |
| code: 'ERR_INVALID_STATE', | |
| name: 'TypeError', | |
| }), | |
| ), | |
| ); | |
| assert.rejects( | |
| reader.read(view), | |
| { | |
| code: 'ERR_INVALID_STATE', | |
| name: 'TypeError', | |
| } | |
| ).then(common.mustCall()); |
Signed-off-by: Daeyeon Jeong [email protected]
|
@aduh95 Applied the suggestions, PTAL. |
|
Landed in 937520a |
Signed-off-by: Daeyeon Jeong [email protected] PR-URL: #44114 Refs: #43866 Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Signed-off-by: Daeyeon Jeong [email protected] PR-URL: nodejs#44114 Refs: nodejs#43866 Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
|
Depends on #43866 |
This fixes validations below related to
isDetachedBufferusing a function introduced in #43866.https://streams.spec.whatwg.org/#rs-byob-request-respond
https://streams.spec.whatwg.org/#byob-reader-read
https://streams.spec.whatwg.org/#readable-byte-stream-controller-enqueue
Refs: #43866 (review)
Signed-off-by: Daeyeon Jeong [email protected]