-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream: improve ArrayBufferView
validation in respondWithNewView()
#43866
Merged
nodejs-github-bot
merged 5 commits into
nodejs:main
from
daeyeon:main.webstream-220716.Sat.260d
Jul 24, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3dc3627
stream: improve `respondWithNewView()`
daeyeon 958ee56
fixup: add a counter for passed tests
daeyeon 593536f
fixup: add `isViewedArrayBufferDetached` in JS
daeyeon 97408ed
fixup: remove the c++ part
daeyeon ec99eb9
fixup: revert unnecessary test changes
daeyeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
test/parallel/test-whatwg-readablebytestream-bad-buffers-and-views.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('node:assert'); | ||
|
||
let pass = 0; | ||
|
||
{ | ||
// ReadableStream with byte source: respondWithNewView() throws if the | ||
// supplied view's buffer has a different length (in the closed state) | ||
const stream = new ReadableStream({ | ||
pull: common.mustCall(async (c) => { | ||
const view = new Uint8Array(new ArrayBuffer(10), 0, 0); | ||
|
||
c.close(); | ||
|
||
assert.throws(() => c.byobRequest.respondWithNewView(view), { | ||
code: 'ERR_INVALID_ARG_VALUE', | ||
name: 'RangeError', | ||
}); | ||
pass++; | ||
}), | ||
type: 'bytes', | ||
}); | ||
|
||
const reader = stream.getReader({ mode: 'byob' }); | ||
reader.read(new Uint8Array([4, 5, 6])); | ||
} | ||
|
||
{ | ||
// ReadableStream with byte source: respondWithNewView() throws if the | ||
// supplied view's buffer has been detached (in the closed state) | ||
const stream = new ReadableStream({ | ||
pull: common.mustCall((c) => { | ||
c.close(); | ||
|
||
// Detach it by reading into it | ||
const view = new Uint8Array([1, 2, 3]); | ||
reader.read(view); | ||
|
||
assert.throws(() => c.byobRequest.respondWithNewView(view), { | ||
code: 'ERR_INVALID_STATE', | ||
name: 'TypeError', | ||
}); | ||
pass++; | ||
}), | ||
type: 'bytes', | ||
}); | ||
|
||
const reader = stream.getReader({ mode: 'byob' }); | ||
reader.read(new Uint8Array([4, 5, 6])); | ||
} | ||
|
||
process.on('exit', () => assert.strictEqual(pass, 2)); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how slow this might really be but I guess it's fine for now because the Web Streams API is experimental.
@nodejs/streams wdyt?