How to use byobReaderBrandCheckException method in wpt

Best JavaScript code snippet using wpt

readable-stream.js

Source:readable-stream.js Github

copy

Full Screen

...531 this._readIntoRequests = [];532 }533 get closed() {534 if (!IsReadableStreamBYOBReader(this)) {535 return Promise.reject(byobReaderBrandCheckException('closed'));536 }537 return this._closedPromise;538 }539 cancel(reason) {540 if (!IsReadableStreamBYOBReader(this)) {541 return Promise.reject(byobReaderBrandCheckException('cancel'));542 }543 if (this._ownerReadableStream === undefined) {544 return Promise.reject(readerLockException('cancel'));545 }546 return ReadableStreamReaderGenericCancel(this, reason);547 }548 read(view) {549 if (!IsReadableStreamBYOBReader(this)) {550 return Promise.reject(byobReaderBrandCheckException('read'));551 }552 if (this._ownerReadableStream === undefined) {553 return Promise.reject(readerLockException('read from'));554 }555 if (!ArrayBuffer.isView(view)) {556 return Promise.reject(new TypeError('view must be an array buffer view'));557 }558 if (view.byteLength === 0) {559 return Promise.reject(new TypeError('view must have non-zero byteLength'));560 }561 return ReadableStreamBYOBReaderRead(this, view);562 }563 releaseLock() {564 if (!IsReadableStreamBYOBReader(this)) {565 throw byobReaderBrandCheckException('releaseLock');566 }567 if (this._ownerReadableStream === undefined) {568 return;569 }570 if (this._readIntoRequests.length > 0) {571 throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');572 }573 ReadableStreamReaderGenericRelease(this);574 }575}576// Abstract operations for the readers.577function IsReadableStreamBYOBReader(x) {578 if (!typeIsObject(x)) {579 return false;580 }581 if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {582 return false;583 }584 return true;585}586function IsReadableStreamDefaultReader(x) {587 if (!typeIsObject(x)) {588 return false;589 }590 if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {591 return false;592 }593 return true;594}595function ReadableStreamReaderGenericInitialize(reader, stream) {596 reader._ownerReadableStream = stream;597 stream._reader = reader;598 if (stream._state === 'readable') {599 defaultReaderClosedPromiseInitialize(reader);600 } else if (stream._state === 'closed') {601 defaultReaderClosedPromiseInitializeAsResolved(reader);602 } else {603 assert(stream._state === 'errored', 'state must be errored');604 defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);605 reader._closedPromise.catch(() => {});606 }607}608// A client of ReadableStreamDefaultReader and ReadableStreamBYOBReader may use these functions directly to bypass state609// check.610function ReadableStreamReaderGenericCancel(reader, reason) {611 const stream = reader._ownerReadableStream;612 assert(stream !== undefined);613 return ReadableStreamCancel(stream, reason);614}615function ReadableStreamReaderGenericRelease(reader) {616 assert(reader._ownerReadableStream !== undefined);617 assert(reader._ownerReadableStream._reader === reader);618 if (reader._ownerReadableStream._state === 'readable') {619 defaultReaderClosedPromiseReject(620 reader,621 new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness'));622 } else {623 defaultReaderClosedPromiseResetToRejected(624 reader,625 new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness'));626 }627 reader._closedPromise.catch(() => {});628 reader._ownerReadableStream._reader = undefined;629 reader._ownerReadableStream = undefined;630}631function ReadableStreamBYOBReaderRead(reader, view) {632 const stream = reader._ownerReadableStream;633 assert(stream !== undefined);634 stream._disturbed = true;635 if (stream._state === 'errored') {636 return Promise.reject(stream._storedError);637 }638 // Controllers must implement this.639 return ReadableByteStreamControllerPullInto(stream._readableStreamController, view);640}641function ReadableStreamDefaultReaderRead(reader) {642 const stream = reader._ownerReadableStream;643 assert(stream !== undefined);644 stream._disturbed = true;645 if (stream._state === 'closed') {646 return Promise.resolve(CreateIterResultObject(undefined, true));647 }648 if (stream._state === 'errored') {649 return Promise.reject(stream._storedError);650 }651 assert(stream._state === 'readable');652 return stream._readableStreamController[InternalPull]();653}654// Controllers655class ReadableStreamDefaultController {656 constructor(stream, underlyingSource, size, highWaterMark) {657 if (IsReadableStream(stream) === false) {658 throw new TypeError('ReadableStreamDefaultController can only be constructed with a ReadableStream instance');659 }660 if (stream._readableStreamController !== undefined) {661 throw new TypeError(662 'ReadableStreamDefaultController instances can only be created by the ReadableStream constructor');663 }664 this._controlledReadableStream = stream;665 this._underlyingSource = underlyingSource;666 this._queue = [];667 this._started = false;668 this._closeRequested = false;669 this._pullAgain = false;670 this._pulling = false;671 const normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark);672 this._strategySize = normalizedStrategy.size;673 this._strategyHWM = normalizedStrategy.highWaterMark;674 const controller = this;675 const startResult = InvokeOrNoop(underlyingSource, 'start', [this]);676 Promise.resolve(startResult).then(677 () => {678 controller._started = true;679 assert(controller._pulling === false);680 assert(controller._pullAgain === false);681 ReadableStreamDefaultControllerCallPullIfNeeded(controller);682 },683 r => {684 ReadableStreamDefaultControllerErrorIfNeeded(controller, r);685 }686 )687 .catch(rethrowAssertionErrorRejection);688 }689 get desiredSize() {690 if (IsReadableStreamDefaultController(this) === false) {691 throw defaultControllerBrandCheckException('desiredSize');692 }693 return ReadableStreamDefaultControllerGetDesiredSize(this);694 }695 close() {696 if (IsReadableStreamDefaultController(this) === false) {697 throw defaultControllerBrandCheckException('close');698 }699 if (this._closeRequested === true) {700 throw new TypeError('The stream has already been closed; do not close it again!');701 }702 const state = this._controlledReadableStream._state;703 if (state !== 'readable') {704 throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be closed`);705 }706 ReadableStreamDefaultControllerClose(this);707 }708 enqueue(chunk) {709 if (IsReadableStreamDefaultController(this) === false) {710 throw defaultControllerBrandCheckException('enqueue');711 }712 if (this._closeRequested === true) {713 throw new TypeError('stream is closed or draining');714 }715 const state = this._controlledReadableStream._state;716 if (state !== 'readable') {717 throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be enqueued to`);718 }719 return ReadableStreamDefaultControllerEnqueue(this, chunk);720 }721 error(e) {722 if (IsReadableStreamDefaultController(this) === false) {723 throw defaultControllerBrandCheckException('error');724 }725 const stream = this._controlledReadableStream;726 if (stream._state !== 'readable') {727 throw new TypeError(`The stream is ${stream._state} and so cannot be errored`);728 }729 ReadableStreamDefaultControllerError(this, e);730 }731 [InternalCancel](reason) {732 this._queue = [];733 return PromiseInvokeOrNoop(this._underlyingSource, 'cancel', [reason]);734 }735 [InternalPull]() {736 const stream = this._controlledReadableStream;737 if (this._queue.length > 0) {738 const chunk = DequeueValue(this._queue);739 if (this._closeRequested === true && this._queue.length === 0) {740 ReadableStreamClose(stream);741 } else {742 ReadableStreamDefaultControllerCallPullIfNeeded(this);743 }744 return Promise.resolve(CreateIterResultObject(chunk, false));745 }746 const pendingPromise = ReadableStreamAddReadRequest(stream);747 ReadableStreamDefaultControllerCallPullIfNeeded(this);748 return pendingPromise;749 }750}751// Abstract operations for the ReadableStreamDefaultController.752function IsReadableStreamDefaultController(x) {753 if (!typeIsObject(x)) {754 return false;755 }756 if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSource')) {757 return false;758 }759 return true;760}761function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {762 const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);763 if (shouldPull === false) {764 return undefined;765 }766 if (controller._pulling === true) {767 controller._pullAgain = true;768 return undefined;769 }770 assert(controller._pullAgain === false);771 controller._pulling = true;772 const pullPromise = PromiseInvokeOrNoop(controller._underlyingSource, 'pull', [controller]);773 pullPromise.then(774 () => {775 controller._pulling = false;776 if (controller._pullAgain === true) {777 controller._pullAgain = false;778 return ReadableStreamDefaultControllerCallPullIfNeeded(controller);779 }780 return undefined;781 },782 e => {783 ReadableStreamDefaultControllerErrorIfNeeded(controller, e);784 }785 )786 .catch(rethrowAssertionErrorRejection);787 return undefined;788}789function ReadableStreamDefaultControllerShouldCallPull(controller) {790 const stream = controller._controlledReadableStream;791 if (stream._state === 'closed' || stream._state === 'errored') {792 return false;793 }794 if (controller._closeRequested === true) {795 return false;796 }797 if (controller._started === false) {798 return false;799 }800 if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {801 return true;802 }803 const desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);804 if (desiredSize > 0) {805 return true;806 }807 return false;808}809// A client of ReadableStreamDefaultController may use these functions directly to bypass state check.810function ReadableStreamDefaultControllerClose(controller) {811 const stream = controller._controlledReadableStream;812 assert(controller._closeRequested === false);813 assert(stream._state === 'readable');814 controller._closeRequested = true;815 if (controller._queue.length === 0) {816 ReadableStreamClose(stream);817 }818}819function ReadableStreamDefaultControllerEnqueue(controller, chunk) {820 const stream = controller._controlledReadableStream;821 assert(controller._closeRequested === false);822 assert(stream._state === 'readable');823 if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {824 ReadableStreamFulfillReadRequest(stream, chunk, false);825 } else {826 let chunkSize = 1;827 if (controller._strategySize !== undefined) {828 try {829 chunkSize = controller._strategySize(chunk);830 } catch (chunkSizeE) {831 ReadableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);832 throw chunkSizeE;833 }834 }835 try {836 EnqueueValueWithSize(controller._queue, chunk, chunkSize);837 } catch (enqueueE) {838 ReadableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);839 throw enqueueE;840 }841 }842 ReadableStreamDefaultControllerCallPullIfNeeded(controller);843 return undefined;844}845function ReadableStreamDefaultControllerError(controller, e) {846 const stream = controller._controlledReadableStream;847 assert(stream._state === 'readable');848 controller._queue = [];849 ReadableStreamError(stream, e);850}851function ReadableStreamDefaultControllerErrorIfNeeded(controller, e) {852 if (controller._controlledReadableStream._state === 'readable') {853 ReadableStreamDefaultControllerError(controller, e);854 }855}856function ReadableStreamDefaultControllerGetDesiredSize(controller) {857 const queueSize = GetTotalQueueSize(controller._queue);858 return controller._strategyHWM - queueSize;859}860class ReadableStreamBYOBRequest {861 constructor(controller, view) {862 this._associatedReadableByteStreamController = controller;863 this._view = view;864 }865 get view() {866 return this._view;867 }868 respond(bytesWritten) {869 if (IsReadableStreamBYOBRequest(this) === false) {870 throw byobRequestBrandCheckException('respond');871 }872 if (this._associatedReadableByteStreamController === undefined) {873 throw new TypeError('This BYOB request has been invalidated');874 }875 ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);876 }877 respondWithNewView(view) {878 if (IsReadableStreamBYOBRequest(this) === false) {879 throw byobRequestBrandCheckException('respond');880 }881 if (this._associatedReadableByteStreamController === undefined) {882 throw new TypeError('This BYOB request has been invalidated');883 }884 if (!ArrayBuffer.isView(view)) {885 throw new TypeError('You can only respond with array buffer views');886 }887 ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);888 }889}890class ReadableByteStreamController {891 constructor(stream, underlyingByteSource, highWaterMark) {892 if (IsReadableStream(stream) === false) {893 throw new TypeError('ReadableByteStreamController can only be constructed with a ReadableStream instance given ' +894 'a byte source');895 }896 if (stream._readableStreamController !== undefined) {897 throw new TypeError(898 'ReadableByteStreamController instances can only be created by the ReadableStream constructor given a byte ' +899 'source');900 }901 this._controlledReadableStream = stream;902 this._underlyingByteSource = underlyingByteSource;903 this._pullAgain = false;904 this._pulling = false;905 ReadableByteStreamControllerClearPendingPullIntos(this);906 this._queue = [];907 this._totalQueuedBytes = 0;908 this._closeRequested = false;909 this._started = false;910 this._strategyHWM = ValidateAndNormalizeHighWaterMark(highWaterMark);911 const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;912 if (autoAllocateChunkSize !== undefined) {913 if (Number.isInteger(autoAllocateChunkSize) === false || autoAllocateChunkSize <= 0) {914 throw new RangeError('autoAllocateChunkSize must be a positive integer');915 }916 }917 this._autoAllocateChunkSize = autoAllocateChunkSize;918 this._pendingPullIntos = [];919 const controller = this;920 const startResult = InvokeOrNoop(underlyingByteSource, 'start', [this]);921 Promise.resolve(startResult).then(922 () => {923 controller._started = true;924 assert(controller._pulling === false);925 assert(controller._pullAgain === false);926 ReadableByteStreamControllerCallPullIfNeeded(controller);927 },928 r => {929 if (stream._state === 'readable') {930 ReadableByteStreamControllerError(controller, r);931 }932 }933 )934 .catch(rethrowAssertionErrorRejection);935 }936 get byobRequest() {937 if (IsReadableByteStreamController(this) === false) {938 throw byteStreamControllerBrandCheckException('byobRequest');939 }940 if (this._byobRequest === undefined && this._pendingPullIntos.length > 0) {941 const firstDescriptor = this._pendingPullIntos[0];942 const view = new Uint8Array(firstDescriptor.buffer,943 firstDescriptor.byteOffset + firstDescriptor.bytesFilled,944 firstDescriptor.byteLength - firstDescriptor.bytesFilled);945 this._byobRequest = new ReadableStreamBYOBRequest(this, view);946 }947 return this._byobRequest;948 }949 get desiredSize() {950 if (IsReadableByteStreamController(this) === false) {951 throw byteStreamControllerBrandCheckException('desiredSize');952 }953 return ReadableByteStreamControllerGetDesiredSize(this);954 }955 close() {956 if (IsReadableByteStreamController(this) === false) {957 throw byteStreamControllerBrandCheckException('close');958 }959 if (this._closeRequested === true) {960 throw new TypeError('The stream has already been closed; do not close it again!');961 }962 const state = this._controlledReadableStream._state;963 if (state !== 'readable') {964 throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be closed`);965 }966 ReadableByteStreamControllerClose(this);967 }968 enqueue(chunk) {969 if (IsReadableByteStreamController(this) === false) {970 throw byteStreamControllerBrandCheckException('enqueue');971 }972 if (this._closeRequested === true) {973 throw new TypeError('stream is closed or draining');974 }975 const state = this._controlledReadableStream._state;976 if (state !== 'readable') {977 throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be enqueued to`);978 }979 if (!ArrayBuffer.isView(chunk)) {980 throw new TypeError('You can only enqueue array buffer views when using a ReadableByteStreamController');981 }982 ReadableByteStreamControllerEnqueue(this, chunk);983 }984 error(e) {985 if (IsReadableByteStreamController(this) === false) {986 throw byteStreamControllerBrandCheckException('error');987 }988 const stream = this._controlledReadableStream;989 if (stream._state !== 'readable') {990 throw new TypeError(`The stream is ${stream._state} and so cannot be errored`);991 }992 ReadableByteStreamControllerError(this, e);993 }994 [InternalCancel](reason) {995 if (this._pendingPullIntos.length > 0) {996 const firstDescriptor = this._pendingPullIntos[0];997 firstDescriptor.bytesFilled = 0;998 }999 this._queue = [];1000 this._totalQueuedBytes = 0;1001 return PromiseInvokeOrNoop(this._underlyingByteSource, 'cancel', [reason]);1002 }1003 [InternalPull]() {1004 const stream = this._controlledReadableStream;1005 if (ReadableStreamGetNumReadRequests(stream) === 0) {1006 if (this._totalQueuedBytes > 0) {1007 const entry = this._queue.shift();1008 this._totalQueuedBytes -= entry.byteLength;1009 ReadableByteStreamControllerHandleQueueDrain(this);1010 let view;1011 try {1012 view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);1013 } catch (viewE) {1014 return Promise.reject(viewE);1015 }1016 return Promise.resolve(CreateIterResultObject(view, false));1017 }1018 const autoAllocateChunkSize = this._autoAllocateChunkSize;1019 if (autoAllocateChunkSize !== undefined) {1020 let buffer;1021 try {1022 buffer = new ArrayBuffer(autoAllocateChunkSize);1023 } catch (bufferE) {1024 return Promise.reject(bufferE);1025 }1026 const pullIntoDescriptor = {1027 buffer,1028 byteOffset: 0,1029 byteLength: autoAllocateChunkSize,1030 bytesFilled: 0,1031 elementSize: 1,1032 ctor: Uint8Array,1033 readerType: 'default'1034 };1035 this._pendingPullIntos.push(pullIntoDescriptor);1036 }1037 } else {1038 assert(this._autoAllocateChunkSize === undefined);1039 }1040 const promise = ReadableStreamAddReadRequest(stream);1041 ReadableByteStreamControllerCallPullIfNeeded(this);1042 return promise;1043 }1044}1045// Abstract operations for the ReadableByteStreamController.1046function IsReadableByteStreamController(x) {1047 if (!typeIsObject(x)) {1048 return false;1049 }1050 if (!Object.prototype.hasOwnProperty.call(x, '_underlyingByteSource')) {1051 return false;1052 }1053 return true;1054}1055function IsReadableStreamBYOBRequest(x) {1056 if (!typeIsObject(x)) {1057 return false;1058 }1059 if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {1060 return false;1061 }1062 return true;1063}1064function ReadableByteStreamControllerCallPullIfNeeded(controller) {1065 const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);1066 if (shouldPull === false) {1067 return undefined;1068 }1069 if (controller._pulling === true) {1070 controller._pullAgain = true;1071 return undefined;1072 }1073 assert(controller._pullAgain === false);1074 controller._pulling = true;1075 // TODO: Test controller argument1076 const pullPromise = PromiseInvokeOrNoop(controller._underlyingByteSource, 'pull', [controller]);1077 pullPromise.then(1078 () => {1079 controller._pulling = false;1080 if (controller._pullAgain === true) {1081 controller._pullAgain = false;1082 ReadableByteStreamControllerCallPullIfNeeded(controller);1083 }1084 },1085 e => {1086 if (controller._controlledReadableStream._state === 'readable') {1087 ReadableByteStreamControllerError(controller, e);1088 }1089 }1090 )1091 .catch(rethrowAssertionErrorRejection);1092 return undefined;1093}1094function ReadableByteStreamControllerClearPendingPullIntos(controller) {1095 ReadableByteStreamControllerInvalidateBYOBRequest(controller);1096 controller._pendingPullIntos = [];1097}1098function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {1099 assert(stream._state !== 'errored', 'state must not be errored');1100 let done = false;1101 if (stream._state === 'closed') {1102 assert(pullIntoDescriptor.bytesFilled === 0);1103 done = true;1104 }1105 const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);1106 if (pullIntoDescriptor.readerType === 'default') {1107 ReadableStreamFulfillReadRequest(stream, filledView, done);1108 } else {1109 assert(pullIntoDescriptor.readerType === 'byob');1110 ReadableStreamFulfillReadIntoRequest(stream, filledView, done);1111 }1112}1113function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {1114 const bytesFilled = pullIntoDescriptor.bytesFilled;1115 const elementSize = pullIntoDescriptor.elementSize;1116 assert(bytesFilled <= pullIntoDescriptor.byteLength);1117 assert(bytesFilled % elementSize === 0);1118 return new pullIntoDescriptor.ctor(1119 pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);1120}1121function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {1122 controller._queue.push({ buffer, byteOffset, byteLength });1123 controller._totalQueuedBytes += byteLength;1124}1125function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {1126 const elementSize = pullIntoDescriptor.elementSize;1127 const currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize;1128 const maxBytesToCopy = Math.min(controller._totalQueuedBytes,1129 pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);1130 const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;1131 const maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize;1132 let totalBytesToCopyRemaining = maxBytesToCopy;1133 let ready = false;1134 if (maxAlignedBytes > currentAlignedBytes) {1135 totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;1136 ready = true;1137 }1138 const queue = controller._queue;1139 while (totalBytesToCopyRemaining > 0) {1140 const headOfQueue = queue[0];1141 const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);1142 const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;1143 ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);1144 if (headOfQueue.byteLength === bytesToCopy) {1145 queue.shift();1146 } else {1147 headOfQueue.byteOffset += bytesToCopy;1148 headOfQueue.byteLength -= bytesToCopy;1149 }1150 controller._totalQueuedBytes -= bytesToCopy;1151 ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);1152 totalBytesToCopyRemaining -= bytesToCopy;1153 }1154 if (ready === false) {1155 assert(controller._totalQueuedBytes === 0, 'queue must be empty');1156 assert(pullIntoDescriptor.bytesFilled > 0);1157 assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize);1158 }1159 return ready;1160}1161function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {1162 assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos[0] === pullIntoDescriptor);1163 ReadableByteStreamControllerInvalidateBYOBRequest(controller);1164 pullIntoDescriptor.bytesFilled += size;1165}1166function ReadableByteStreamControllerHandleQueueDrain(controller) {1167 assert(controller._controlledReadableStream._state === 'readable');1168 if (controller._totalQueuedBytes === 0 && controller._closeRequested === true) {1169 ReadableStreamClose(controller._controlledReadableStream);1170 } else {1171 ReadableByteStreamControllerCallPullIfNeeded(controller);1172 }1173}1174function ReadableByteStreamControllerInvalidateBYOBRequest(controller) {1175 if (controller._byobRequest === undefined) {1176 return;1177 }1178 controller._byobRequest._associatedReadableByteStreamController = undefined;1179 controller._byobRequest._view = undefined;1180 controller._byobRequest = undefined;1181}1182function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {1183 assert(controller._closeRequested === false);1184 while (controller._pendingPullIntos.length > 0) {1185 if (controller._totalQueuedBytes === 0) {1186 return;1187 }1188 const pullIntoDescriptor = controller._pendingPullIntos[0];1189 if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) {1190 ReadableByteStreamControllerShiftPendingPullInto(controller);1191 ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor);1192 }1193 }1194}1195function ReadableByteStreamControllerPullInto(controller, view) {1196 const stream = controller._controlledReadableStream;1197 let elementSize = 1;1198 if (view.constructor !== DataView) {1199 elementSize = view.constructor.BYTES_PER_ELEMENT;1200 }1201 const ctor = view.constructor;1202 const pullIntoDescriptor = {1203 buffer: view.buffer,1204 byteOffset: view.byteOffset,1205 byteLength: view.byteLength,1206 bytesFilled: 0,1207 elementSize,1208 ctor,1209 readerType: 'byob'1210 };1211 if (controller._pendingPullIntos.length > 0) {1212 pullIntoDescriptor.buffer = SameRealmTransfer(pullIntoDescriptor.buffer);1213 controller._pendingPullIntos.push(pullIntoDescriptor);1214 // No ReadableByteStreamControllerCallPullIfNeeded() call since:1215 // - No change happens on desiredSize1216 // - The source has already been notified of that there's at least 1 pending read(view)1217 return ReadableStreamAddReadIntoRequest(stream);1218 }1219 if (stream._state === 'closed') {1220 const emptyView = new view.constructor(view.buffer, view.byteOffset, 0);1221 return Promise.resolve(CreateIterResultObject(emptyView, true));1222 }1223 if (controller._totalQueuedBytes > 0) {1224 if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) {1225 const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);1226 ReadableByteStreamControllerHandleQueueDrain(controller);1227 return Promise.resolve(CreateIterResultObject(filledView, false));1228 }1229 if (controller._closeRequested === true) {1230 const e = new TypeError('Insufficient bytes to fill elements in the given buffer');1231 ReadableByteStreamControllerError(controller, e);1232 return Promise.reject(e);1233 }1234 }1235 pullIntoDescriptor.buffer = SameRealmTransfer(pullIntoDescriptor.buffer);1236 controller._pendingPullIntos.push(pullIntoDescriptor);1237 const promise = ReadableStreamAddReadIntoRequest(stream);1238 ReadableByteStreamControllerCallPullIfNeeded(controller);1239 return promise;1240}1241function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {1242 firstDescriptor.buffer = SameRealmTransfer(firstDescriptor.buffer);1243 assert(firstDescriptor.bytesFilled === 0, 'bytesFilled must be 0');1244 const stream = controller._controlledReadableStream;1245 while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {1246 const pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);1247 ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);1248 }1249}1250function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {1251 if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {1252 throw new RangeError('bytesWritten out of range');1253 }1254 ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);1255 if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {1256 // TODO: Figure out whether we should detach the buffer or not here.1257 return;1258 }1259 ReadableByteStreamControllerShiftPendingPullInto(controller);1260 const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;1261 if (remainderSize > 0) {1262 const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;1263 const remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end);1264 ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);1265 }1266 pullIntoDescriptor.buffer = SameRealmTransfer(pullIntoDescriptor.buffer);1267 pullIntoDescriptor.bytesFilled -= remainderSize;1268 ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor);1269 ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);1270}1271function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {1272 const firstDescriptor = controller._pendingPullIntos[0];1273 const stream = controller._controlledReadableStream;1274 if (stream._state === 'closed') {1275 if (bytesWritten !== 0) {1276 throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');1277 }1278 ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);1279 } else {1280 assert(stream._state === 'readable');1281 ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);1282 }1283}1284function ReadableByteStreamControllerShiftPendingPullInto(controller) {1285 const descriptor = controller._pendingPullIntos.shift();1286 ReadableByteStreamControllerInvalidateBYOBRequest(controller);1287 return descriptor;1288}1289function ReadableByteStreamControllerShouldCallPull(controller) {1290 const stream = controller._controlledReadableStream;1291 if (stream._state !== 'readable') {1292 return false;1293 }1294 if (controller._closeRequested === true) {1295 return false;1296 }1297 if (controller._started === false) {1298 return false;1299 }1300 if (ReadableStreamHasDefaultReader(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {1301 return true;1302 }1303 if (ReadableStreamHasBYOBReader(stream) && ReadableStreamGetNumReadIntoRequests(stream) > 0) {1304 return true;1305 }1306 if (ReadableByteStreamControllerGetDesiredSize(controller) > 0) {1307 return true;1308 }1309 return false;1310}1311// A client of ReadableByteStreamController may use these functions directly to bypass state check.1312function ReadableByteStreamControllerClose(controller) {1313 const stream = controller._controlledReadableStream;1314 assert(controller._closeRequested === false);1315 assert(stream._state === 'readable');1316 if (controller._totalQueuedBytes > 0) {1317 controller._closeRequested = true;1318 return;1319 }1320 if (controller._pendingPullIntos.length > 0) {1321 const firstPendingPullInto = controller._pendingPullIntos[0];1322 if (firstPendingPullInto.bytesFilled > 0) {1323 const e = new TypeError('Insufficient bytes to fill elements in the given buffer');1324 ReadableByteStreamControllerError(controller, e);1325 throw e;1326 }1327 }1328 ReadableStreamClose(stream);1329}1330function ReadableByteStreamControllerEnqueue(controller, chunk) {1331 const stream = controller._controlledReadableStream;1332 assert(controller._closeRequested === false);1333 assert(stream._state === 'readable');1334 const buffer = chunk.buffer;1335 const byteOffset = chunk.byteOffset;1336 const byteLength = chunk.byteLength;1337 const transferredBuffer = SameRealmTransfer(buffer);1338 if (ReadableStreamHasDefaultReader(stream) === true) {1339 if (ReadableStreamGetNumReadRequests(stream) === 0) {1340 ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);1341 } else {1342 assert(controller._queue.length === 0);1343 const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);1344 ReadableStreamFulfillReadRequest(stream, transferredView, false);1345 }1346 } else if (ReadableStreamHasBYOBReader(stream) === true) {1347 // TODO: Ideally in this branch detaching should happen only if the buffer is not consumed fully.1348 ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);1349 ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);1350 } else {1351 assert(IsReadableStreamLocked(stream) === false, 'stream must not be locked');1352 ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);1353 }1354}1355function ReadableByteStreamControllerError(controller, e) {1356 const stream = controller._controlledReadableStream;1357 assert(stream._state === 'readable');1358 ReadableByteStreamControllerClearPendingPullIntos(controller);1359 controller._queue = [];1360 ReadableStreamError(stream, e);1361}1362function ReadableByteStreamControllerGetDesiredSize(controller) {1363 return controller._strategyHWM - controller._totalQueuedBytes;1364}1365function ReadableByteStreamControllerRespond(controller, bytesWritten) {1366 bytesWritten = Number(bytesWritten);1367 if (IsFiniteNonNegativeNumber(bytesWritten) === false) {1368 throw new RangeError('bytesWritten must be a finite');1369 }1370 assert(controller._pendingPullIntos.length > 0);1371 ReadableByteStreamControllerRespondInternal(controller, bytesWritten);1372}1373function ReadableByteStreamControllerRespondWithNewView(controller, view) {1374 assert(controller._pendingPullIntos.length > 0);1375 const firstDescriptor = controller._pendingPullIntos[0];1376 if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {1377 throw new RangeError('The region specified by view does not match byobRequest');1378 }1379 if (firstDescriptor.byteLength !== view.byteLength) {1380 throw new RangeError('The buffer of view has different capacity than byobRequest');1381 }1382 firstDescriptor.buffer = view.buffer;1383 ReadableByteStreamControllerRespondInternal(controller, view.byteLength);1384}1385// Helper functions for the ReadableStream.1386function streamBrandCheckException(name) {1387 return new TypeError(`ReadableStream.prototype.${name} can only be used on a ReadableStream`);1388}1389// Helper functions for the readers.1390function readerLockException(name) {1391 return new TypeError('Cannot ' + name + ' a stream using a released reader');1392}1393// Helper functions for the ReadableStreamDefaultReader.1394function defaultReaderBrandCheckException(name) {1395 return new TypeError(1396 `ReadableStreamDefaultReader.prototype.${name} can only be used on a ReadableStreamDefaultReader`);1397}1398function defaultReaderClosedPromiseInitialize(reader) {1399 reader._closedPromise = new Promise((resolve, reject) => {1400 reader._closedPromise_resolve = resolve;1401 reader._closedPromise_reject = reject;1402 });1403}1404function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) {1405 reader._closedPromise = Promise.reject(reason);1406 reader._closedPromise_resolve = undefined;1407 reader._closedPromise_reject = undefined;1408}1409function defaultReaderClosedPromiseInitializeAsResolved(reader) {1410 reader._closedPromise = Promise.resolve(undefined);1411 reader._closedPromise_resolve = undefined;1412 reader._closedPromise_reject = undefined;1413}1414function defaultReaderClosedPromiseReject(reader, reason) {1415 assert(reader._closedPromise_resolve !== undefined);1416 assert(reader._closedPromise_reject !== undefined);1417 reader._closedPromise_reject(reason);1418 reader._closedPromise_resolve = undefined;1419 reader._closedPromise_reject = undefined;1420}1421function defaultReaderClosedPromiseResetToRejected(reader, reason) {1422 assert(reader._closedPromise_resolve === undefined);1423 assert(reader._closedPromise_reject === undefined);1424 reader._closedPromise = Promise.reject(reason);1425}1426function defaultReaderClosedPromiseResolve(reader) {1427 assert(reader._closedPromise_resolve !== undefined);1428 assert(reader._closedPromise_reject !== undefined);1429 reader._closedPromise_resolve(undefined);1430 reader._closedPromise_resolve = undefined;1431 reader._closedPromise_reject = undefined;1432}1433// Helper functions for the ReadableStreamDefaultReader.1434function byobReaderBrandCheckException(name) {1435 return new TypeError(1436 `ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`);1437}1438// Helper functions for the ReadableStreamDefaultController.1439function defaultControllerBrandCheckException(name) {1440 return new TypeError(1441 `ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);1442}1443// Helper functions for the ReadableStreamBYOBRequest.1444function byobRequestBrandCheckException(name) {1445 return new TypeError(1446 `ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);1447}1448// Helper functions for the ReadableByteStreamController....

Full Screen

Full Screen

byob-reader.ts

Source:byob-reader.ts Github

copy

Full Screen

...101 * the reader's lock is released before the stream finishes closing.102 */103 get closed(): Promise<void> {104 if (!IsReadableStreamBYOBReader(this)) {105 return promiseRejectedWith(byobReaderBrandCheckException('closed'));106 }107 return this._closedPromise;108 }109 /**110 * If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.111 */112 cancel(reason: any = undefined): Promise<void> {113 if (!IsReadableStreamBYOBReader(this)) {114 return promiseRejectedWith(byobReaderBrandCheckException('cancel'));115 }116 if (this._ownerReadableStream === undefined) {117 return promiseRejectedWith(readerLockException('cancel'));118 }119 return ReadableStreamReaderGenericCancel(this, reason);120 }121 /**122 * Attempts to reads bytes into view, and returns a promise resolved with the result.123 *124 * If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.125 */126 read<T extends ArrayBufferView>(view: T): Promise<ReadableStreamBYOBReadResult<T>> {127 if (!IsReadableStreamBYOBReader(this)) {128 return promiseRejectedWith(byobReaderBrandCheckException('read'));129 }130 if (!ArrayBuffer.isView(view)) {131 return promiseRejectedWith(new TypeError('view must be an array buffer view'));132 }133 if (view.byteLength === 0) {134 return promiseRejectedWith(new TypeError('view must have non-zero byteLength'));135 }136 if (view.buffer.byteLength === 0) {137 return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));138 }139 if (this._ownerReadableStream === undefined) {140 return promiseRejectedWith(readerLockException('read from'));141 }142 let resolvePromise!: (result: ReadableStreamBYOBReadResult<T>) => void;143 let rejectPromise!: (reason: any) => void;144 const promise = newPromise<ReadableStreamBYOBReadResult<T>>((resolve, reject) => {145 resolvePromise = resolve;146 rejectPromise = reject;147 });148 const readIntoRequest: ReadIntoRequest<T> = {149 _chunkSteps: chunk => resolvePromise({ value: chunk, done: false }),150 _closeSteps: chunk => resolvePromise({ value: chunk, done: true }),151 _errorSteps: e => rejectPromise(e)152 };153 ReadableStreamBYOBReaderRead(this, view, readIntoRequest);154 return promise;155 }156 /**157 * Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.158 * If the associated stream is errored when the lock is released, the reader will appear errored in the same way159 * from now on; otherwise, the reader will appear closed.160 *161 * A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by162 * the reader's {@link ReadableStreamBYOBReader.read | read()} method has not yet been settled. Attempting to163 * do so will throw a `TypeError` and leave the reader locked to the stream.164 */165 releaseLock(): void {166 if (!IsReadableStreamBYOBReader(this)) {167 throw byobReaderBrandCheckException('releaseLock');168 }169 if (this._ownerReadableStream === undefined) {170 return;171 }172 if (this._readIntoRequests.length > 0) {173 throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');174 }175 ReadableStreamReaderGenericRelease(this);176 }177}178Object.defineProperties(ReadableStreamBYOBReader.prototype, {179 cancel: { enumerable: true },180 read: { enumerable: true },181 releaseLock: { enumerable: true },182 closed: { enumerable: true }183});184if (typeof Symbol.toStringTag === 'symbol') {185 Object.defineProperty(ReadableStreamBYOBReader.prototype, Symbol.toStringTag, {186 value: 'ReadableStreamBYOBReader',187 configurable: true188 });189}190// Abstract operations for the readers.191export function IsReadableStreamBYOBReader(x: any): x is ReadableStreamBYOBReader {192 if (!typeIsObject(x)) {193 return false;194 }195 if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {196 return false;197 }198 return true;199}200function ReadableStreamBYOBReaderRead<T extends ArrayBufferView>(reader: ReadableStreamBYOBReader,201 view: T,202 readIntoRequest: ReadIntoRequest<T>): void {203 const stream = reader._ownerReadableStream;204 assert(stream !== undefined);205 stream._disturbed = true;206 if (stream._state === 'errored') {207 readIntoRequest._errorSteps(stream._storedError);208 } else {209 ReadableByteStreamControllerPullInto(210 stream._readableStreamController as ReadableByteStreamController,211 view,212 readIntoRequest213 );214 }215}216// Helper functions for the ReadableStreamBYOBReader.217function byobReaderBrandCheckException(name: string): TypeError {218 return new TypeError(219 `ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function byobReaderBrandCheckException() {2 var byobReader = new ReadableStream({3 start(controller) {4 controller.enqueue(new Uint8Array(1));5 }6 }).getReader({mode: 'byob'});7 var view = new Uint8Array(1);8 byobReader.read(view);9 byobReader.read(view);10}11function byobReaderReadIntoException() {12 var byobReader = new ReadableStream({13 start(controller) {14 controller.enqueue(new Uint8Array(1));15 }16 }).getReader({mode: 'byob'});17 var view = new Uint8Array(1);18 byobReader.read(view);19 byobReader.read(view);20}21function byobReaderReadIntoException() {22 var byobReader = new ReadableStream({23 start(controller) {24 controller.enqueue(new Uint8Array(1));25 }26 }).getReader({mode: 'byob'});27 var view = new Uint8Array(1);28 byobReader.read(view);29 byobReader.read(view);30}31function byobReaderReadIntoException() {32 var byobReader = new ReadableStream({33 start(controller) {34 controller.enqueue(new Uint8Array(1));35 }36 }).getReader({mode: 'byob'});37 var view = new Uint8Array(1);38 byobReader.read(view);39 byobReader.read(view);40}41function byobReaderReadIntoException() {42 var byobReader = new ReadableStream({43 start(controller) {44 controller.enqueue(new Uint8Array(1));45 }46 }).getReader({mode: 'byob'});47 var view = new Uint8Array(1);48 byobReader.read(view);49 byobReader.read(view);50}51function byobReaderReadIntoException() {

Full Screen

Using AI Code Generation

copy

Full Screen

1function byobReaderBrandCheckException() {2 return new ReadableStream({3 start(controller) {4 const view = new Uint8Array([1, 2, 3]).buffer;5 const reader = controller.byobRequest.getReader();6 assert_throws_js(TypeError, () => reader.read(view));7 }8 });9}10function byobRequestBrandCheckException() {11 return new ReadableStream({12 start(controller) {13 const view = new Uint8Array([1, 2, 3]).buffer;14 const reader = controller.byobRequest.getReader();15 assert_throws_js(TypeError, () => reader.read(view));16 }17 });18}19function byobRequestBrandCheckException() {20 return new ReadableStream({21 start(controller) {22 const view = new Uint8Array([1, 2, 3]).buffer;23 const reader = controller.byobRequest.getReader();24 assert_throws_js(TypeError, () => reader.read(view));25 }26 });27}28function byobRequestBrandCheckException() {29 return new ReadableStream({30 start(controller) {31 const view = new Uint8Array([1, 2, 3]).buffer;32 const reader = controller.byobRequest.getReader();33 assert_throws_js(TypeError, () => reader.read(view));34 }35 });36}37function byobRequestBrandCheckException() {38 return new ReadableStream({39 start(controller) {40 const view = new Uint8Array([1, 2, 3]).buffer;41 const reader = controller.byobRequest.getReader();42 assert_throws_js(TypeError, () => reader.read(view));43 }44 });45}46function byobRequestBrandCheckException() {47 return new ReadableStream({48 start(controller) {49 const view = new Uint8Array([1, 2, 3]).buffer;

Full Screen

Using AI Code Generation

copy

Full Screen

1function byobReaderBrandCheckException(t) {2 const controller = new ReadableStreamDefaultController({});3 assert_throws_js(TypeError, () => {4 controller.byobRequest;5 }, 'byobRequest getter should throw a TypeError');6}7function byobReaderBrandCheckException(t) {8 const controller = new ReadableStreamDefaultController({});9 assert_throws_js(TypeError, () => {10 controller.byobRequest;11 }, 'byobRequest getter should throw a TypeError');12}13function byobReaderBrandCheckException(t) {14 const controller = new ReadableStreamDefaultController({});15 assert_throws_js(TypeError, () => {16 controller.byobRequest;17 }, 'byobRequest getter should throw a TypeError');18}19function byobReaderBrandCheckException(t) {20 const controller = new ReadableStreamDefaultController({});21 assert_throws_js(TypeError, () => {22 controller.byobRequest;23 }, 'byobRequest getter should throw a TypeError');24}25function byobReaderBrandCheckException(t) {26 const controller = new ReadableStreamDefaultController({});27 assert_throws_js(TypeError, () => {28 controller.byobRequest;29 }, 'byobRequest getter should throw a TypeError');30}31function byobReaderBrandCheckException(t) {32 const controller = new ReadableStreamDefaultController({});33 assert_throws_js(TypeError, () => {34 controller.byobRequest;35 }, 'byobRequest getter should throw a TypeError');36}37function byobReaderBrandCheckException(t) {38 const controller = new ReadableStreamDefaultController({});39 assert_throws_js(TypeError, () => {40 controller.byobRequest;41 }, 'byobRequest getter should throw a TypeError');42}43function byobReaderBrandCheckException(t) {44 const controller = new ReadableStreamDefaultController({});45 assert_throws_js(TypeError, () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1var decoder = new TextDecoder();2var bytes = new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A]);3var string = decoder.decode(bytes);4var decoder = new TextDecoder();5var bytes = new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A]);6var string = decoder.decode(bytes);7var decoder = new TextDecoder();8var bytes = new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72,

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = async_test("BYOB reader brand check exception test");2test.step(function() {3 var controller;4 var reader = new ReadableStream({5 start: function(c) {6 controller = c;7 }8 }).getReader({mode: "byob"});9 var view = new Uint8Array(1);10 var promise = reader.read(view);11 promise.catch(function() {12 test.done();13 });14 controller.error();15});16var test = async_test("BYOB reader brand check exception test");17test.step(function() {18 var controller;19 var reader = new ReadableStream({20 start: function(c) {21 controller = c;22 }23 }).getReader({mode: "byob"});24 var view = new Uint8Array(1);25 var promise = reader.read(view);26 promise.catch(function() {27 test.done();28 });29 controller.error();30});31var test = async_test("BYOB reader brand check exception test");32test.step(function() {33 var controller;34 var reader = new ReadableStream({35 start: function(c) {36 controller = c;37 }38 }).getReader({mode: "byob"});39 var view = new Uint8Array(1);40 var promise = reader.read(view);41 promise.catch(function() {42 test.done();43 });44 controller.error();45});46var test = async_test("BYOB reader brand check exception test");47test.step(function() {48 var controller;49 var reader = new ReadableStream({50 start: function(c) {51 controller = c;52 }53 }).getReader({mode: "byob"});54 var view = new Uint8Array(1);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful