-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: improve
respondWithNewView()
This fixes validating an ArrayBufferView given to ReadableStreamBYOBRequest.respondWithNewView() to improve the web streams compatibility. Signed-off-by: Daeyeon Jeong [email protected]
- Loading branch information
Showing
4 changed files
with
67 additions
and
3 deletions.
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
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('node:assert'); | ||
|
||
{ | ||
// 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); | ||
}, RangeError); | ||
}), | ||
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); | ||
}, TypeError); | ||
}), | ||
type: 'bytes', | ||
}); | ||
|
||
const reader = stream.getReader({ mode: 'byob' }); | ||
reader.read(new Uint8Array([4, 5, 6])); | ||
} |
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