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

Throw a TypeError in ReadableStreamBYOBReader constructor if stream isn't a byte stream #638

Merged
merged 6 commits into from Jan 6, 2017
Copy path View file
@@ -514,10 +514,7 @@ ReadableStream(<var>underlyingSource</var> = {}, { <var>size</var>, <var>highWat
<emu-alg>
1. If ! IsReadableStream(*this*) is *false*, throw a *TypeError* exception.
1. If _mode_ is `"byob"`,
1. If ! IsReadableByteStreamController(*this*.[[readableStreamController]]) is *false*, throw a *TypeError*
exception.
1. Return ? AcquireReadableStreamBYOBReader(*this*).
1. If _mode_ is `"byob"`, return ? AcquireReadableStreamBYOBReader(*this*).
1. If _mode_ is *undefined*, return ? AcquireReadableStreamDefaultReader(*this*).
1. Throw a *RangeError* exception.
</emu-alg>
@@ -1247,6 +1244,7 @@ ReadableStreamBYOBReader(<var>stream</var>)</h4>
<emu-alg>
1. If ! IsReadableStream(_stream_) is *false*, throw a *TypeError* exception.
1. If ! IsReadableByteStreamController(_stream_.[[readableStreamController]]) is *false*, throw a *TypeError* exception.
1. If ! IsReadableStreamLocked(_stream_) is *true*, throw a *TypeError* exception.
1. Perform ! ReadableStreamReaderGenericInitialize(*this*, _stream_).
1. Set *this*.[[readIntoRequests]] to a new empty List.
@@ -4287,6 +4285,7 @@ Stephen Sugden,
Tab Atkins,
Tanguy Krotoff,
Thorsten Lorenz,
Till Schneidereit,
Tim Caswell,
Trevor Norris,
tzik,
@@ -69,10 +69,6 @@ class ReadableStream {
}
if (mode === 'byob') {
if (IsReadableByteStreamController(this._readableStreamController) === false) {
throw new TypeError('Cannot get a ReadableStreamBYOBReader for a stream not constructed with a byte source');
}
return AcquireReadableStreamBYOBReader(this);
}
@@ -665,6 +661,10 @@ class ReadableStreamBYOBReader {
throw new TypeError('ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a ' +
'byte source');
}
if (IsReadableByteStreamController(stream._readableStreamController) === false) {
throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' +
'source');
}
if (IsReadableStreamLocked(stream)) {
throw new TypeError('This stream has already been locked for exclusive reading by another reader');
}
@@ -2196,3 +2196,31 @@ test('ReadableStream with byte source: Throwing in pull in response to read(view
});
});
});
test('ReadableStreamBYOBReader can be constructed directly', t => {
const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
const stream = new ReadableStream({ type: 'bytes' });
new ReadableStreamBYOBReader(stream);
t.end();
});
test('ReadableStreamBYOBReader constructor requires a ReadableStream argument', t => {
const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
t.throws(() => new ReadableStreamBYOBReader({}), TypeError, 'constructor must throw');
t.end();
});
test('ReadableStreamBYOBReader constructor requires an unlocked ReadableStream', t => {
const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
const stream = new ReadableStream({ type: 'bytes' });
stream.getReader();
t.throws(() => new ReadableStreamBYOBReader(stream), TypeError, 'constructor must throw');
t.end();
});
test('ReadableStreamBYOBReader constructor requires a ReadableStream with type "bytes"', t => {
const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
const stream = new ReadableStream();
t.throws(() => new ReadableStreamBYOBReader(stream), TypeError, 'constructor must throw');
t.end();
});
ProTip! Use n and p to navigate between commits in a pull request.