Commit abeaa5ea authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

Re-order ReadableStream.js

Change the order of functions in ReadableStream.js to match the standard. This
will make it easier to update the implementation to match changes to the
standard.

No functional changes.

This corresponds to step 3 of issue 710728.

Verified identical to the previous version once comments and blank lines are
removed and the file is sorted by function.

Bug: 710728
Change-Id: I8b0ae4ad41aa5e84f234901560ad6f97e6319001
Reviewed-on: https://chromium-review.googlesource.com/821955Reviewed-by: default avatarTakeshi Yoshino <tyoshino@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523739}
parent 594a5f31
...@@ -427,149 +427,196 @@ ...@@ -427,149 +427,196 @@
return promise; return promise;
} }
class ReadableStreamDefaultController { //
constructor( // Readable stream abstract operations
stream, underlyingSource, size, highWaterMark, isExternallyControlled) { //
if (IsReadableStream(stream) === false) {
throw new TypeError(streamErrors.illegalConstructor);
}
if (stream[_controller] !== undefined) { function AcquireReadableStreamDefaultReader(stream) {
throw new TypeError(streamErrors.illegalConstructor); return new ReadableStreamDefaultReader(stream);
} }
this[_controlledReadableStream] = stream; function IsReadableStream(x) {
return hasOwnPropertyNoThrow(x, _controller);
}
this[_underlyingSource] = underlyingSource; function IsReadableStreamDisturbed(stream) {
return stream[_readableStreamBits] & DISTURBED;
}
this[_queue] = new binding.SimpleQueue(); function IsReadableStreamLocked(stream) {
this[_queueTotalSize] = 0; return stream[_reader] !== undefined;
}
this[_readableStreamDefaultControllerBits] = 0b0; // Potential future optimization: use class instances for the underlying
if (isExternallyControlled === true) { // sources, so that we don't re-create
this[_readableStreamDefaultControllerBits] |= EXTERNALLY_CONTROLLED; // closures every time.
// TODO(domenic): shouldClone argument from spec not supported yet
function ReadableStreamTee(stream) {
const reader = AcquireReadableStreamDefaultReader(stream);
let closedOrErrored = false;
let canceled1 = false;
let canceled2 = false;
let reason1;
let reason2;
const promise = v8.createPromise();
const branch1Stream = new ReadableStream({pull, cancel: cancel1});
const branch2Stream = new ReadableStream({pull, cancel: cancel2});
const branch1 = branch1Stream[_controller];
const branch2 = branch2Stream[_controller];
thenPromise(reader[_closedPromise], undefined, function(r) {
if (closedOrErrored === true) {
return;
} }
const normalizedStrategy = ReadableStreamDefaultControllerError(branch1, r);
ValidateAndNormalizeQueuingStrategy(size, highWaterMark); ReadableStreamDefaultControllerError(branch2, r);
this[_strategySize] = normalizedStrategy.size; closedOrErrored = true;
this[_strategyHWM] = normalizedStrategy.highWaterMark; });
const controller = this; return [branch1Stream, branch2Stream];
const startResult = CallOrNoop1( function pull() {
underlyingSource, 'start', this, 'underlyingSource.start'); return thenPromise(
thenPromise( ReadableStreamDefaultReaderRead(reader), function(result) {
Promise_resolve(startResult), const value = result.value;
() => { const done = result.done;
controller[_readableStreamDefaultControllerBits] |= STARTED;
ReadableStreamDefaultControllerCallPullIfNeeded(controller); if (done === true && closedOrErrored === false) {
}, if (canceled1 === false) {
r => { ReadableStreamDefaultControllerClose(branch1);
if (ReadableStreamGetState(stream) === STATE_READABLE) { }
ReadableStreamDefaultControllerError(controller, r); if (canceled2 === false) {
ReadableStreamDefaultControllerClose(branch2);
}
closedOrErrored = true;
} }
});
}
get desiredSize() { if (closedOrErrored === true) {
if (IsReadableStreamDefaultController(this) === false) { return;
throw new TypeError(streamErrors.illegalInvocation); }
}
return ReadableStreamDefaultControllerGetDesiredSize(this); if (canceled1 === false) {
ReadableStreamDefaultControllerEnqueue(branch1, value);
}
if (canceled2 === false) {
ReadableStreamDefaultControllerEnqueue(branch2, value);
}
});
} }
close() { function cancel1(reason) {
if (IsReadableStreamDefaultController(this) === false) { canceled1 = true;
throw new TypeError(streamErrors.illegalInvocation); reason1 = reason;
if (canceled2 === true) {
const compositeReason = [reason1, reason2];
const cancelResult = ReadableStreamCancel(stream, compositeReason);
resolvePromise(promise, cancelResult);
} }
const stream = this[_controlledReadableStream]; return promise;
}
if (this[_readableStreamDefaultControllerBits] & CLOSE_REQUESTED) { function cancel2(reason) {
throw new TypeError(errCloseCloseRequestedStream); canceled2 = true;
} reason2 = reason;
const state = ReadableStreamGetState(stream); if (canceled1 === true) {
if (state === STATE_ERRORED) { const compositeReason = [reason1, reason2];
throw new TypeError(errCloseErroredStream); const cancelResult = ReadableStreamCancel(stream, compositeReason);
} resolvePromise(promise, cancelResult);
if (state === STATE_CLOSED) {
throw new TypeError(errCloseClosedStream);
} }
return ReadableStreamDefaultControllerClose(this); return promise;
} }
}
enqueue(chunk) { //
if (IsReadableStreamDefaultController(this) === false) { // Abstract Operations Used By Controllers
throw new TypeError(streamErrors.illegalInvocation); //
}
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) { function ReadableStreamAddReadRequest(stream) {
const stream = this[_controlledReadableStream]; const promise = v8.createPromise();
throw getReadableStreamEnqueueError(stream, this); stream[_reader][_readRequests].push(promise);
} return promise;
}
return ReadableStreamDefaultControllerEnqueue(this, chunk); function ReadableStreamCancel(stream, reason) {
stream[_readableStreamBits] |= DISTURBED;
const state = ReadableStreamGetState(stream);
if (state === STATE_CLOSED) {
return Promise_resolve(undefined);
}
if (state === STATE_ERRORED) {
return Promise_reject(stream[_storedError]);
} }
error(e) { ReadableStreamClose(stream);
if (IsReadableStreamDefaultController(this) === false) {
throw new TypeError(streamErrors.illegalInvocation);
}
const stream = this[_controlledReadableStream]; const sourceCancelPromise =
ReadableStreamDefaultControllerCancel(stream[_controller], reason);
return thenPromise(sourceCancelPromise, () => undefined);
}
const state = ReadableStreamGetState(stream); function ReadableStreamClose(stream) {
if (state === STATE_ERRORED) { ReadableStreamSetState(stream, STATE_CLOSED);
throw new TypeError(errErrorErroredStream);
}
if (state === STATE_CLOSED) {
throw new TypeError(errErrorClosedStream);
}
return ReadableStreamDefaultControllerError(this, e); const reader = stream[_reader];
if (reader === undefined) {
return undefined;
} }
}
function ReadableStreamDefaultControllerCancel(controller, reason) { if (IsReadableStreamDefaultReader(reader) === true) {
controller[_queue] = new binding.SimpleQueue(); reader[_readRequests].forEach(
request =>
resolvePromise(request, CreateIterResultObject(undefined, true)));
reader[_readRequests] = new binding.SimpleQueue();
}
const underlyingSource = controller[_underlyingSource]; resolvePromise(reader[_closedPromise], undefined);
return PromiseCallOrNoop1(
underlyingSource, 'cancel', reason, 'underlyingSource.cancel');
} }
function ReadableStreamDefaultControllerPull(controller) { function ReadableStreamError(stream, e) {
const stream = controller[_controlledReadableStream]; stream[_storedError] = e;
ReadableStreamSetState(stream, STATE_ERRORED);
if (controller[_queue].length > 0) {
const chunk = DequeueValue(controller);
if ((controller[_readableStreamDefaultControllerBits] & const reader = stream[_reader];
CLOSE_REQUESTED) && if (reader === undefined) {
controller[_queue].length === 0) { return undefined;
ReadableStreamClose(stream); }
} else {
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
}
return Promise_resolve(CreateIterResultObject(chunk, false)); if (IsReadableStreamDefaultReader(reader) === true) {
reader[_readRequests].forEach(request => rejectPromise(request, e));
reader[_readRequests] = new binding.SimpleQueue();
} }
const pendingPromise = ReadableStreamAddReadRequest(stream); rejectPromise(reader[_closedPromise], e);
ReadableStreamDefaultControllerCallPullIfNeeded(controller); markPromiseAsHandled(reader[_closedPromise]);
return pendingPromise;
} }
function ReadableStreamAddReadRequest(stream) { function ReadableStreamFulfillReadRequest(stream, chunk, done) {
const promise = v8.createPromise(); const readRequest = stream[_reader][_readRequests].shift();
stream[_reader][_readRequests].push(promise); resolvePromise(readRequest, CreateIterResultObject(chunk, done));
return promise; }
function ReadableStreamGetNumReadRequests(stream) {
const reader = stream[_reader];
const readRequests = reader[_readRequests];
return readRequests.length;
} }
//
// Class ReadableStreamDefaultReader
//
class ReadableStreamDefaultReader { class ReadableStreamDefaultReader {
constructor(stream) { constructor(stream) {
if (IsReadableStream(stream) === false) { if (IsReadableStream(stream) === false) {
...@@ -635,196 +682,16 @@ ...@@ -635,196 +682,16 @@
} }
} }
function ReadableStreamReaderGenericCancel(reader, reason) {
return ReadableStreamCancel(reader[_ownerReadableStream], reason);
}
// //
// Readable stream abstract operations // Readable Stream Reader Abstract Operations
// //
function AcquireReadableStreamDefaultReader(stream) { function IsReadableStreamDefaultReader(x) {
return new ReadableStreamDefaultReader(stream); return hasOwnPropertyNoThrow(x, _readRequests);
} }
function ReadableStreamCancel(stream, reason) { function ReadableStreamReaderGenericCancel(reader, reason) {
stream[_readableStreamBits] |= DISTURBED; return ReadableStreamCancel(reader[_ownerReadableStream], reason);
const state = ReadableStreamGetState(stream);
if (state === STATE_CLOSED) {
return Promise_resolve(undefined);
}
if (state === STATE_ERRORED) {
return Promise_reject(stream[_storedError]);
}
ReadableStreamClose(stream);
const sourceCancelPromise =
ReadableStreamDefaultControllerCancel(stream[_controller], reason);
return thenPromise(sourceCancelPromise, () => undefined);
}
function ReadableStreamDefaultControllerClose(controller) {
const stream = controller[_controlledReadableStream];
controller[_readableStreamDefaultControllerBits] |= CLOSE_REQUESTED;
if (controller[_queue].length === 0) {
ReadableStreamClose(stream);
}
}
function ReadableStreamFulfillReadRequest(stream, chunk, done) {
const readRequest = stream[_reader][_readRequests].shift();
resolvePromise(readRequest, CreateIterResultObject(chunk, done));
}
function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
const stream = controller[_controlledReadableStream];
if (IsReadableStreamLocked(stream) === true &&
ReadableStreamGetNumReadRequests(stream) > 0) {
ReadableStreamFulfillReadRequest(stream, chunk, false);
} else {
let chunkSize = 1;
const strategySize = controller[_strategySize];
if (strategySize !== undefined) {
try {
chunkSize = strategySize(chunk);
} catch (chunkSizeE) {
if (ReadableStreamGetState(stream) === STATE_READABLE) {
ReadableStreamDefaultControllerError(controller, chunkSizeE);
}
throw chunkSizeE;
}
}
try {
EnqueueValueWithSize(controller, chunk, chunkSize);
} catch (enqueueE) {
if (ReadableStreamGetState(stream) === STATE_READABLE) {
ReadableStreamDefaultControllerError(controller, enqueueE);
}
throw enqueueE;
}
}
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
}
function ReadableStreamGetState(stream) {
return (stream[_readableStreamBits] & STATE_MASK) >> STATE_BITS_OFFSET;
}
function ReadableStreamSetState(stream, state) {
stream[_readableStreamBits] = (stream[_readableStreamBits] & ~STATE_MASK) |
(state << STATE_BITS_OFFSET);
}
function ReadableStreamDefaultControllerError(controller, e) {
controller[_queue] = new binding.SimpleQueue();
const stream = controller[_controlledReadableStream];
ReadableStreamError(stream, e);
}
function ReadableStreamError(stream, e) {
stream[_storedError] = e;
ReadableStreamSetState(stream, STATE_ERRORED);
const reader = stream[_reader];
if (reader === undefined) {
return undefined;
}
if (IsReadableStreamDefaultReader(reader) === true) {
reader[_readRequests].forEach(request => rejectPromise(request, e));
reader[_readRequests] = new binding.SimpleQueue();
}
rejectPromise(reader[_closedPromise], e);
markPromiseAsHandled(reader[_closedPromise]);
}
function ReadableStreamClose(stream) {
ReadableStreamSetState(stream, STATE_CLOSED);
const reader = stream[_reader];
if (reader === undefined) {
return undefined;
}
if (IsReadableStreamDefaultReader(reader) === true) {
reader[_readRequests].forEach(
request =>
resolvePromise(request, CreateIterResultObject(undefined, true)));
reader[_readRequests] = new binding.SimpleQueue();
}
resolvePromise(reader[_closedPromise], undefined);
}
function ReadableStreamDefaultControllerGetDesiredSize(controller) {
return controller[_strategyHWM] - controller[_queueTotalSize];
}
function ReadableStreamDefaultControllerHasBackpressure(controller) {
return !ReadableStreamDefaultControllerShouldCallPull(controller);
}
function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
if (controller[_readableStreamDefaultControllerBits] & CLOSE_REQUESTED) {
return false;
}
const state = ReadableStreamGetState(controller[_controlledReadableStream]);
return state === STATE_READABLE;
}
function IsReadableStream(x) {
return hasOwnPropertyNoThrow(x, _controller);
}
function IsReadableStreamDisturbed(stream) {
return stream[_readableStreamBits] & DISTURBED;
}
function IsReadableStreamLocked(stream) {
return stream[_reader] !== undefined;
}
function IsReadableStreamDefaultController(x) {
return hasOwnPropertyNoThrow(x, _controlledReadableStream);
}
function IsReadableStreamDefaultReader(x) {
return hasOwnPropertyNoThrow(x, _readRequests);
}
function IsReadableStreamReadable(stream) {
return ReadableStreamGetState(stream) === STATE_READABLE;
}
function IsReadableStreamClosed(stream) {
return ReadableStreamGetState(stream) === STATE_CLOSED;
}
function IsReadableStreamErrored(stream) {
return ReadableStreamGetState(stream) === STATE_ERRORED;
}
// Used internally by enqueue() and also by TransformStream.
function getReadableStreamEnqueueError(stream, controller) {
if (controller[_readableStreamDefaultControllerBits] & CLOSE_REQUESTED) {
return new TypeError(errEnqueueCloseRequestedStream);
}
const state = ReadableStreamGetState(stream);
if (state === STATE_ERRORED) {
return new TypeError(errEnqueueErroredStream);
}
// assert(state === STATE_CLOSED, 'state is "closed"');
return new TypeError(errEnqueueClosedStream);
} }
function ReadableStreamReaderGenericInitialize(reader, stream) { function ReadableStreamReaderGenericInitialize(reader, stream) {
...@@ -898,6 +765,157 @@ ...@@ -898,6 +765,157 @@
return ReadableStreamDefaultControllerPull(stream[_controller]); return ReadableStreamDefaultControllerPull(stream[_controller]);
} }
//
// Class ReadableStreamDefaultController
//
class ReadableStreamDefaultController {
constructor(
stream, underlyingSource, size, highWaterMark, isExternallyControlled) {
if (IsReadableStream(stream) === false) {
throw new TypeError(streamErrors.illegalConstructor);
}
if (stream[_controller] !== undefined) {
throw new TypeError(streamErrors.illegalConstructor);
}
this[_controlledReadableStream] = stream;
this[_underlyingSource] = underlyingSource;
this[_queue] = new binding.SimpleQueue();
this[_queueTotalSize] = 0;
this[_readableStreamDefaultControllerBits] = 0b0;
if (isExternallyControlled === true) {
this[_readableStreamDefaultControllerBits] |= EXTERNALLY_CONTROLLED;
}
const normalizedStrategy =
ValidateAndNormalizeQueuingStrategy(size, highWaterMark);
this[_strategySize] = normalizedStrategy.size;
this[_strategyHWM] = normalizedStrategy.highWaterMark;
const controller = this;
const startResult = CallOrNoop1(
underlyingSource, 'start', this, 'underlyingSource.start');
thenPromise(
Promise_resolve(startResult),
() => {
controller[_readableStreamDefaultControllerBits] |= STARTED;
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
},
r => {
if (ReadableStreamGetState(stream) === STATE_READABLE) {
ReadableStreamDefaultControllerError(controller, r);
}
});
}
get desiredSize() {
if (IsReadableStreamDefaultController(this) === false) {
throw new TypeError(streamErrors.illegalInvocation);
}
return ReadableStreamDefaultControllerGetDesiredSize(this);
}
close() {
if (IsReadableStreamDefaultController(this) === false) {
throw new TypeError(streamErrors.illegalInvocation);
}
const stream = this[_controlledReadableStream];
if (this[_readableStreamDefaultControllerBits] & CLOSE_REQUESTED) {
throw new TypeError(errCloseCloseRequestedStream);
}
const state = ReadableStreamGetState(stream);
if (state === STATE_ERRORED) {
throw new TypeError(errCloseErroredStream);
}
if (state === STATE_CLOSED) {
throw new TypeError(errCloseClosedStream);
}
return ReadableStreamDefaultControllerClose(this);
}
enqueue(chunk) {
if (IsReadableStreamDefaultController(this) === false) {
throw new TypeError(streamErrors.illegalInvocation);
}
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
const stream = this[_controlledReadableStream];
throw getReadableStreamEnqueueError(stream, this);
}
return ReadableStreamDefaultControllerEnqueue(this, chunk);
}
error(e) {
if (IsReadableStreamDefaultController(this) === false) {
throw new TypeError(streamErrors.illegalInvocation);
}
const stream = this[_controlledReadableStream];
const state = ReadableStreamGetState(stream);
if (state === STATE_ERRORED) {
throw new TypeError(errErrorErroredStream);
}
if (state === STATE_CLOSED) {
throw new TypeError(errErrorClosedStream);
}
return ReadableStreamDefaultControllerError(this, e);
}
}
// [[CancelSteps]] in the standard.
function ReadableStreamDefaultControllerCancel(controller, reason) {
controller[_queue] = new binding.SimpleQueue();
const underlyingSource = controller[_underlyingSource];
return PromiseCallOrNoop1(
underlyingSource, 'cancel', reason, 'underlyingSource.cancel');
}
// [[PullSteps]] in the standard.
function ReadableStreamDefaultControllerPull(controller) {
const stream = controller[_controlledReadableStream];
if (controller[_queue].length > 0) {
const chunk = DequeueValue(controller);
if ((controller[_readableStreamDefaultControllerBits] &
CLOSE_REQUESTED) &&
controller[_queue].length === 0) {
ReadableStreamClose(stream);
} else {
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
}
return Promise_resolve(CreateIterResultObject(chunk, false));
}
const pendingPromise = ReadableStreamAddReadRequest(stream);
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
return pendingPromise;
}
//
// Readable Stream Default Controller Abstract Operations
//
function IsReadableStreamDefaultController(x) {
return hasOwnPropertyNoThrow(x, _controlledReadableStream);
}
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) { function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
const shouldPull = const shouldPull =
ReadableStreamDefaultControllerShouldCallPull(controller); ReadableStreamDefaultControllerShouldCallPull(controller);
...@@ -964,101 +982,113 @@ ...@@ -964,101 +982,113 @@
return false; return false;
} }
function ReadableStreamGetNumReadRequests(stream) { function ReadableStreamDefaultControllerClose(controller) {
const reader = stream[_reader]; const stream = controller[_controlledReadableStream];
const readRequests = reader[_readRequests];
return readRequests.length;
}
// Potential future optimization: use class instances for the underlying
// sources, so that we don't re-create
// closures every time.
// TODO(domenic): shouldClone argument from spec not supported yet controller[_readableStreamDefaultControllerBits] |= CLOSE_REQUESTED;
function ReadableStreamTee(stream) {
const reader = AcquireReadableStreamDefaultReader(stream);
let closedOrErrored = false; if (controller[_queue].length === 0) {
let canceled1 = false; ReadableStreamClose(stream);
let canceled2 = false; }
let reason1; }
let reason2;
const promise = v8.createPromise();
const branch1Stream = new ReadableStream({pull, cancel: cancel1}); function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
const stream = controller[_controlledReadableStream];
const branch2Stream = new ReadableStream({pull, cancel: cancel2}); if (IsReadableStreamLocked(stream) === true &&
ReadableStreamGetNumReadRequests(stream) > 0) {
ReadableStreamFulfillReadRequest(stream, chunk, false);
} else {
let chunkSize = 1;
const branch1 = branch1Stream[_controller]; const strategySize = controller[_strategySize];
const branch2 = branch2Stream[_controller]; if (strategySize !== undefined) {
try {
chunkSize = strategySize(chunk);
} catch (chunkSizeE) {
if (ReadableStreamGetState(stream) === STATE_READABLE) {
ReadableStreamDefaultControllerError(controller, chunkSizeE);
}
throw chunkSizeE;
}
}
thenPromise(reader[_closedPromise], undefined, function(r) { try {
if (closedOrErrored === true) { EnqueueValueWithSize(controller, chunk, chunkSize);
return; } catch (enqueueE) {
if (ReadableStreamGetState(stream) === STATE_READABLE) {
ReadableStreamDefaultControllerError(controller, enqueueE);
}
throw enqueueE;
} }
}
ReadableStreamDefaultControllerError(branch1, r); ReadableStreamDefaultControllerCallPullIfNeeded(controller);
ReadableStreamDefaultControllerError(branch2, r); }
closedOrErrored = true;
});
return [branch1Stream, branch2Stream]; function ReadableStreamDefaultControllerError(controller, e) {
controller[_queue] = new binding.SimpleQueue();
const stream = controller[_controlledReadableStream];
ReadableStreamError(stream, e);
}
function pull() { function ReadableStreamDefaultControllerGetDesiredSize(controller) {
return thenPromise( return controller[_strategyHWM] - controller[_queueTotalSize];
ReadableStreamDefaultReaderRead(reader), function(result) { }
const value = result.value;
const done = result.done;
if (done === true && closedOrErrored === false) { function ReadableStreamDefaultControllerHasBackpressure(controller) {
if (canceled1 === false) { return !ReadableStreamDefaultControllerShouldCallPull(controller);
ReadableStreamDefaultControllerClose(branch1); }
}
if (canceled2 === false) {
ReadableStreamDefaultControllerClose(branch2);
}
closedOrErrored = true;
}
if (closedOrErrored === true) { function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
return; if (controller[_readableStreamDefaultControllerBits] & CLOSE_REQUESTED) {
} return false;
}
const state = ReadableStreamGetState(controller[_controlledReadableStream]);
return state === STATE_READABLE;
}
if (canceled1 === false) { //
ReadableStreamDefaultControllerEnqueue(branch1, value); // Internal functions. Not part of the standard.
} //
if (canceled2 === false) { function ReadableStreamGetState(stream) {
ReadableStreamDefaultControllerEnqueue(branch2, value); return (stream[_readableStreamBits] & STATE_MASK) >> STATE_BITS_OFFSET;
} }
});
}
function cancel1(reason) { function ReadableStreamSetState(stream, state) {
canceled1 = true; stream[_readableStreamBits] = (stream[_readableStreamBits] & ~STATE_MASK) |
reason1 = reason; (state << STATE_BITS_OFFSET);
}
if (canceled2 === true) { //
const compositeReason = [reason1, reason2]; // Functions exported for use by TransformStream. Not part of the standard.
const cancelResult = ReadableStreamCancel(stream, compositeReason); //
resolvePromise(promise, cancelResult);
}
return promise; function IsReadableStreamReadable(stream) {
} return ReadableStreamGetState(stream) === STATE_READABLE;
}
function cancel2(reason) { function IsReadableStreamClosed(stream) {
canceled2 = true; return ReadableStreamGetState(stream) === STATE_CLOSED;
reason2 = reason; }
if (canceled1 === true) { function IsReadableStreamErrored(stream) {
const compositeReason = [reason1, reason2]; return ReadableStreamGetState(stream) === STATE_ERRORED;
const cancelResult = ReadableStreamCancel(stream, compositeReason); }
resolvePromise(promise, cancelResult);
}
return promise; // Used internally by enqueue() and also by TransformStream.
function getReadableStreamEnqueueError(stream, controller) {
if (controller[_readableStreamDefaultControllerBits] & CLOSE_REQUESTED) {
return new TypeError(errEnqueueCloseRequestedStream);
} }
const state = ReadableStreamGetState(stream);
if (state === STATE_ERRORED) {
return new TypeError(errEnqueueErroredStream);
}
// assert(state === STATE_CLOSED, 'state is "closed"');
return new TypeError(errEnqueueClosedStream);
} }
// //
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment