-
Notifications
You must be signed in to change notification settings - Fork 161
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
Byte stream update, including reference implementation #361
Changes from 1 commit
e31cf83
33b4db3
49e2b91
60fdeca
4b03976
60ec5f3
2dda7e9
06309a0
50eafbe
1d7c673
a0b9daf
189c31d
a6f3a95
721d9f7
1696a79
6b45951
afceae3
6897df9
5e40178
db3ab8a
10bd5d3
187172e
3f7fd74
09d9847
18235da
87f45a6
a63f0a4
5a20417
c49457a
b6ae151
16cb5fa
29a4ed2
1c4f531
b04c8fd
c8a8917
a0f36e8
3ca35ec
3d3717e
7d2f9b8
788aae8
b626d86
13f446e
0a512da
6bd7b93
afeede5
422795d
4c87a4d
ffaea95
2bf0357
a174501
f2a9f07
186a262
18c5554
14e3bbc
28cbdc8
7b559f5
f3be413
f174dd5
67af7d5
a8e4945
95cb1d5
e187dbf
24d5faf
6c55dbf
7db54d1
719ba77
48a23cd
a4f9a28
76bf9ec
f697ea8
e5b1c9d
8d263f4
f39fa42
735b773
15b5d4c
b9ac65e
9d83b77
0142e33
ac98124
ed7e2b2
7711f9c
cd57295
87ab09f
946dd41
6ddcdc5
9ba49b1
f6b3edd
b343560
cddeae7
21728cc
bfcfa31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,8 @@ class ReadableByteStreamController { | |
|
||
this._underlyingByteSource = underlyingByteSource; | ||
|
||
this._insideUnderlyingByteSource = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In ReadableStream these are called, respectively, pullAgain and pulling. Those names seems shorter and accurate enough to maybe use here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 48a23cd |
||
|
||
this._pendingPulls = []; | ||
|
||
this._queue = []; | ||
|
@@ -113,9 +115,10 @@ class ReadableByteStreamController { | |
|
||
if (this._pendingPulls.length > 0 && this._pendingPulls[0].bytesFilled > 0) { | ||
DestroyReadableByteStreamController(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In all but one case, DestroyReadableByteStreamController is followed by ErrorReadableByteStream. It might be worth thinking about how to combine them into one function. If not possible, then that's fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually two. Maybe you searched for Destroy. There's one with typo (Destory). Fixed by 186a262. We could have a helper to run both, but maybe leads to increase of texts and a little longer time to trace call path in reviewing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just kind of hoping there was a way to refactor so that they always happen together, instead of happening together usually except in 2 cases. But I haven't thought about it too hard so probably there is a good reason for it to be separate :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ya. For now I'll leave them as is. |
||
ErrorReadableByteStream(stream, new TypeError('Insufficient bytes to fill elements in the given buffer')); | ||
const e = new TypeError('Insufficient bytes to fill elements in the given buffer'); | ||
ErrorReadableByteStream(stream, e); | ||
|
||
return undefined; | ||
throw e; | ||
} | ||
|
||
CloseReadableByteStream(stream); | ||
|
@@ -239,15 +242,19 @@ class ReadableByteStreamController { | |
|
||
ConsumeQueueForReadableByteStreamByobReaderReadIntoRequest(this, reader); | ||
} else { | ||
try { | ||
controller._underlyingByteSource.pullInto(pullDescriptor.buffer, | ||
pullDescriptor.byteOffset + pullDescriptor.bytesFilled, | ||
pullDescriptor.byteLength - pullDescriptor.bytesFilled); | ||
} catch (e) { | ||
DestroyReadableByteStreamController(this); | ||
if (stream._state === 'readable') { | ||
ErrorReadableByteStream(stream, e); | ||
if (!controller._insideUnderlyingByteSource) { | ||
controller._insideUnderlyingByteSource = true; | ||
try { | ||
controller._underlyingByteSource.pullInto(pullDescriptor.buffer, | ||
pullDescriptor.byteOffset + pullDescriptor.bytesFilled, | ||
pullDescriptor.byteLength - pullDescriptor.bytesFilled); | ||
} catch (e) { | ||
DestroyReadableByteStreamController(this); | ||
if (stream._state === 'readable') { | ||
ErrorReadableByteStream(stream, e); | ||
} | ||
} | ||
controller._insideUnderlyingByteSource = false; | ||
} | ||
} | ||
|
||
|
@@ -405,7 +412,7 @@ class ReadableByteStreamByobReader { | |
} | ||
|
||
if (this._state === 'closed' && this._ownerReadableByteStream === undefined) { | ||
return Promise.resolve(CreateIterResultObject(view, true)); | ||
return Promise.resolve(CreateIterResultObject(new view.constructor(view.buffer, view.byteOffset, 0), true)); | ||
} | ||
|
||
const promise = new Promise((resolve, reject) => { | ||
|
@@ -746,15 +753,19 @@ function ConsumeQueueForReadableByteStreamByobReaderReadIntoRequest(controller, | |
|
||
// TODO: Detach pullDescriptor.buffer if detachRequired is true. | ||
|
||
try { | ||
controller._underlyingByteSource.pullInto(pullDescriptor.buffer, | ||
pullDescriptor.byteOffset + pullDescriptor.bytesFilled, | ||
pullDescriptor.byteLength - pullDescriptor.bytesFilled); | ||
} catch (e) { | ||
DestroyReadableByteStreamController(controller); | ||
if (stream._state === 'readable') { | ||
ErrorReadableByteStream(stream, e); | ||
if (!controller._insideUnderlyingByteSource) { | ||
controller._insideUnderlyingByteSource = true; | ||
try { | ||
controller._underlyingByteSource.pullInto(pullDescriptor.buffer, | ||
pullDescriptor.byteOffset + pullDescriptor.bytesFilled, | ||
pullDescriptor.byteLength - pullDescriptor.bytesFilled); | ||
} catch (e) { | ||
DestroyReadableByteStreamController(controller); | ||
if (stream._state === 'readable') { | ||
ErrorReadableByteStream(stream, e); | ||
} | ||
} | ||
controller._insideUnderlyingByteSource = false; | ||
} | ||
|
||
return undefined; | ||
|
@@ -800,13 +811,17 @@ function MaybeRespondToReadableByteStreamReaderReadRequest(controller, reader) { | |
return undefined; | ||
} | ||
|
||
try { | ||
controller._underlyingByteSource.pull(); | ||
} catch (e) { | ||
DestoryReadableByteStreamController(controller); | ||
if (stream._state === 'readable') { | ||
ErrorReadableByteStream(stream, e); | ||
if (!controller._insideUnderlyingByteSource) { | ||
controller._insideUnderlyingByteSource = true; | ||
try { | ||
controller._underlyingByteSource.pull(); | ||
} catch (e) { | ||
DestoryReadableByteStreamController(controller); | ||
if (stream._state === 'readable') { | ||
ErrorReadableByteStream(stream, e); | ||
} | ||
} | ||
controller._insideUnderlyingByteSource = false; | ||
} | ||
|
||
return undefined; | ||
|
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.
Hmm, all these being on the controller seems a bit weird... we should probably be consistent between RBS and RS.
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.
This is attempt to satisfy #312. I've put all the helper stuff (buffering, fragmentation, coalescing) into
ReadableByteStreamController
experimentally.ReadableByteStream
andReadableByteStream.*Reader
doesn't have any variable for these work.