stream: fix isDetachedBuffer validations in ReadableStream#44114
Conversation
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
This reverts commit 6f6ba3e. Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
lib/internal/webstreams/util.js
Outdated
| function isDetachedBuffer(buffer) { | ||
| if (!isArrayBuffer(buffer)) | ||
| throw new ERR_INVALID_ARG_TYPE('buffer', 'ArrayBuffer', buffer); |
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 daeyeon.dev@gmail.com
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
This comment was marked as outdated.
This comment was marked as outdated.
| if (!isArrayBufferView(view)) { | ||
| throw new ERR_INVALID_ARG_TYPE( | ||
| 'view', | ||
| ['Buffer', 'TypedArray', 'DataView'], | ||
| view, | ||
| ); | ||
| } |
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
|
|
||
| function isArrayBufferDetached(buffer) { | ||
| function isDetachedBuffer(buffer) { | ||
| assert(isArrayBuffer(buffer)); |
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
| } | ||
|
|
||
| function isViewedArrayBufferDetached(view) { | ||
| assert(isArrayBufferView(view)); |
There was a problem hiding this comment.
same here
| assert(isArrayBufferView(view)); |
| reader | ||
| .read(view) | ||
| .then(common.mustNotCall()) | ||
| .catch( | ||
| common.mustCall( | ||
| common.expectsError({ | ||
| code: 'ERR_INVALID_STATE', | ||
| name: 'TypeError', | ||
| }), | ||
| ), | ||
| ); |
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()); |
| reader | ||
| .read(view) | ||
| .then(common.mustNotCall()) | ||
| .catch( | ||
| common.mustCall( | ||
| common.expectsError({ | ||
| code: 'ERR_INVALID_STATE', | ||
| name: 'TypeError', | ||
| }), | ||
| ), | ||
| ); |
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 daeyeon.dev@gmail.com
|
@aduh95 Applied the suggestions, PTAL. |
|
Landed in 937520a |
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: nodejs#44114 Refs: nodejs#43866 Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
|
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 daeyeon.dev@gmail.com