Uh oh!
There was an error while loading. Please reload this page.
stream: fix isDetachedBuffer validations in ReadableStream - #44114
Conversation
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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
Uh oh!
There was an error while loading. Please reload this page.
| 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.
nodejs-github-bot
commented
Aug 8, 2022
| 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
| 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.
| } | ||
| 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
daeyeon
commented
Aug 18, 2022
@aduh95 Applied the suggestions, PTAL. |
nodejs-github-bot
commented
Aug 18, 2022
nodejs-github-bot
commented
Aug 18, 2022
Landed in 937520a |
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