Skip to content

Commit

Permalink
Change the byob switch of ReadableStream constructor to a string swit…
Browse files Browse the repository at this point in the history
…ch named type

Partially fixes #294
  • Loading branch information
tyoshino committed Apr 6, 2016
1 parent 2cf372d commit f4fa9d0
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 77 deletions.
20 changes: 11 additions & 9 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ Instances of {{ReadableStream}} are created with the internal slots described in
state via the passed <code>controller</code> object. This is an example of the
<a href="https://blog.domenic.me/the-revealing-constructor-pattern/">revealing constructor pattern</a>.

If the <code>underlyingSource</code> object contains a truthy property <code>byob</code>, this <a>readable stream</a> is
If the <code>underlyingSource</code> object contains a string property <code>type</code>, this <a>readable stream</a> is
a <a>readable byte stream</a>, and can successfully vend <a>BYOB readers</a>. In that case, the passed
<code>controller</code> object will be an instance of {{ReadableByteStreamController}}. Otherwise, it will be an instance of
{{ReadableStreamDefaultController}}.
Expand All @@ -447,16 +447,18 @@ Instances of {{ReadableStream}} are created with the internal slots described in
1. Set *this*@[[reader]] and *this*@[[storedError]] to *undefined*.
1. Set *this*@[[disturbed]] to *false*.
1. Set *this*@[[readableStreamController]] to *undefined*.
1. Let _byob_ be ToBoolean(GetV(_underlyingSource_, `"byob"`)).
1. ReturnIfAbrupt(_byob_).
1. If _byob_ is *true*,
1. Let _type_ be ToBoolean(GetV(_underlyingSource_, `"type"`)).
1. ReturnIfAbrupt(_type_).
1. If _type_ is `"bytes"`,
1. If _highWaterMark_ is *undefined*,
1. Let _highWaterMark_ be 0.
1. Set *this*@[[readableStreamController]] to Construct(`<a idl>ReadableByteStreamController</a>`, «*this*, _underlyingSource_, _highWaterMark_»).
1. Otherwise,
1. If _highWaterMark_ is *undefined*,
1. Let _highWaterMark_ be 1.
1. Set *this*@[[readableStreamController]] to Construct(`<a idl>ReadableStreamDefaultController</a>`, «*this*, _underlyingSource_, _size_, _highWaterMark_»).
1. If _type_ is *undefined*,
1. If _highWaterMark_ is *undefined*,
1. Let _highWaterMark_ be 1.
1. Set *this*@[[readableStreamController]] to Construct(`<a idl>ReadableStreamDefaultController</a>`, «*this*, _underlyingSource_, _size_, _highWaterMark_»).
1. Otherwise, throw a *TypeError* exception.
</emu-alg>

<h4 id="rs-prototype">Properties of the {{ReadableStream}} Prototype</h4>
Expand Down Expand Up @@ -3154,7 +3156,7 @@ BYOB reader, to move the data from the stream's internal queue to the developer-
const socket = createHypotheticalSelect2Socket(host, port);

return new ReadableStream({
byob: true,
type: "bytes",

start(controller) {
socket.setTCPWindowSize(Math.max(0, controller.desiredSize));
Expand Down Expand Up @@ -3261,7 +3263,7 @@ size of 1024, it attempts to fill the developer-supplied buffer, allowing full c
let position = 0;

return new ReadableStream({
byob: true,
type: "bytes",

start() {
return fs.open(filename, "r").then(result => {
Expand Down
14 changes: 9 additions & 5 deletions reference-implementation/lib/readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ export default class ReadableStream {
// Initialize to undefined first because the constructor of the controller checks this
// variable to validate the caller.
this._readableStreamController = undefined;
const byob = underlyingSource['byob'];
if (byob === true) {
const type = underlyingSource['type'];
if (type === 'bytes') {
if (highWaterMark === undefined) {
highWaterMark = 0;
}
this._readableStreamController = new ReadableByteStreamController(this, underlyingSource, highWaterMark);
} else {
if (highWaterMark === undefined) {
highWaterMark = 1;
if (type === undefined) {
if (highWaterMark === undefined) {
highWaterMark = 1;
}
this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark);
} else {
throw new TypeError('Invalid type is specified');
}
this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark);
}
}

Expand Down

0 comments on commit f4fa9d0

Please sign in to comment.