Best JavaScript code snippet using wpt
ReadableByteStreamInternals.js
Source:ReadableByteStreamInternals.js
1/*2 * Copyright (C) 2016 Canon Inc. All rights reserved.3 *4 * Redistribution and use in source and binary forms, with or without5 * modification, are permitted provided that the following conditions6 * are met:7 * 1. Redistributions of source code must retain the above copyright8 * notice, this list of conditions and the following disclaimer.9 * 2. Redistributions in binary form must reproduce the above copyright10 * notice, this list of conditions and the following disclaimer in the11 * documentation and/or other materials provided with the distribution.12 *13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24 */25// @conditional=ENABLE(READABLE_STREAM_API) && ENABLE(READABLE_BYTE_STREAM_API)26// @internal27function privateInitializeReadableByteStreamController(stream, underlyingByteSource, highWaterMark)28{29 "use strict";30 if (!@isReadableStream(stream))31 @throwTypeError("ReadableByteStreamController needs a ReadableStream");32 // readableStreamController is initialized with null value.33 if (stream.@readableStreamController !== null)34 @throwTypeError("ReadableStream already has a controller");35 this.@controlledReadableStream = stream;36 this.@underlyingByteSource = underlyingByteSource;37 this.@pullAgain = false;38 this.@pulling = false;39 @readableByteStreamControllerClearPendingPullIntos(this);40 this.@queue = [];41 this.@totalQueuedBytes = 0;42 this.@started = false;43 this.@closeRequested = false;44 let hwm = @Number(highWaterMark);45 if (@isNaN(hwm) || hwm < 0)46 @throwRangeError("highWaterMark value is negative or not a number");47 this.@strategyHWM = hwm;48 let autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;49 if (autoAllocateChunkSize !== @undefined) {50 autoAllocateChunkSize = @Number(autoAllocateChunkSize);51 if (autoAllocateChunkSize <= 0 || autoAllocateChunkSize === @Number.POSITIVE_INFINITY || autoAllocateChunkSize === @Number.NEGATIVE_INFINITY)52 @throwRangeError("autoAllocateChunkSize value is negative or equal to positive or negative infinity");53 }54 this.@autoAllocateChunkSize = autoAllocateChunkSize;55 this.@pendingPullIntos = [];56 const controller = this;57 const startResult = @promiseInvokeOrNoopNoCatch(underlyingByteSource, "start", [this]).@then(() => {58 controller.@started = true;59 @assert(!controller.@pulling);60 @assert(!controller.@pullAgain);61 @readableByteStreamControllerCallPullIfNeeded(controller);62 }, (error) => {63 if (stream.@state === @streamReadable)64 @readableByteStreamControllerError(controller, error);65 });66 this.@cancel = @readableByteStreamControllerCancel;67 this.@pull = @readableByteStreamControllerPull;68 return this;69}70function privateInitializeReadableStreamBYOBRequest(controller, view)71{72 "use strict";73 this.@associatedReadableByteStreamController = controller;74 this.@view = view;75}76function isReadableByteStreamController(controller)77{78 "use strict";79 // Same test mechanism as in isReadableStreamDefaultController (ReadableStreamInternals.js).80 // See corresponding function for explanations.81 return @isObject(controller) && !!controller.@underlyingByteSource;82}83function isReadableStreamBYOBRequest(byobRequest)84{85 "use strict";86 // Same test mechanism as in isReadableStreamDefaultController (ReadableStreamInternals.js).87 // See corresponding function for explanations.88 return @isObject(byobRequest) && !!byobRequest.@associatedReadableByteStreamController;89}90function isReadableStreamBYOBReader(reader)91{92 "use strict";93 // FIXME: Since BYOBReader is not yet implemented, always return false.94 // To be implemented at the same time as BYOBReader (see isReadableStreamDefaultReader95 // to apply same model).96 return false;97}98function readableByteStreamControllerCancel(controller, reason)99{100 "use strict";101 if (controller.@pendingPullIntos.length > 0)102 controller.@pendingPullIntos[0].bytesFilled = 0;103 controller.@queue = [];104 controller.@totalQueuedBytes = 0;105 return @promiseInvokeOrNoop(controller.@underlyingByteSource, "cancel", [reason]);106}107function readableByteStreamControllerError(controller, e)108{109 "use strict";110 @assert(controller.@controlledReadableStream.@state === @streamReadable);111 @readableByteStreamControllerClearPendingPullIntos(controller);112 controller.@queue = [];113 @readableStreamError(controller.@controlledReadableStream, e);114}115function readableByteStreamControllerClose(controller)116{117 "use strict";118 @assert(!controller.@closeRequested);119 @assert(controller.@controlledReadableStream.@state === @streamReadable);120 if (controller.@totalQueuedBytes > 0) {121 controller.@closeRequested = true;122 return;123 }124 if (controller.@pendingPullIntos.length > 0) {125 if (controller.@pendingPullIntos[0].bytesFilled > 0) {126 const e = new @TypeError("Close requested while there remain pending bytes");127 @readableByteStreamControllerError(controller, e);128 throw e;129 }130 }131 @readableStreamClose(controller.@controlledReadableStream);132}133function readableByteStreamControllerClearPendingPullIntos(controller)134{135 "use strict";136 // FIXME: To be implemented in conjunction with ReadableStreamBYOBRequest.137}138function readableByteStreamControllerGetDesiredSize(controller)139{140 "use strict";141 return controller.@strategyHWM - controller.@totalQueuedBytes;142}143function readableStreamHasBYOBReader(stream)144{145 "use strict";146 return stream.@reader !== @undefined && @isReadableStreamBYOBReader(stream.@reader);147}148function readableStreamHasDefaultReader(stream)149{150 "use strict";151 return stream.@reader !== @undefined && @isReadableStreamDefaultReader(stream.@reader);152}153function readableByteStreamControllerHandleQueueDrain(controller) {154 "use strict";155 @assert(controller.@controlledReadableStream.@state === @streamReadable);156 if (!controller.@totalQueuedBytes && controller.@closeRequested)157 @readableStreamClose(controller.@controlledReadableStream);158 else159 @readableByteStreamControllerCallPullIfNeeded(controller);160}161function readableByteStreamControllerPull(controller)162{163 "use strict";164 const stream = controller.@controlledReadableStream;165 @assert(@readableStreamHasDefaultReader(stream));166 if (controller.@totalQueuedBytes > 0) {167 @assert(stream.@reader.@readRequests.length === 0);168 const entry = controller.@queue.@shift();169 controller.@totalQueuedBytes -= entry.byteLength;170 @readableByteStreamControllerHandleQueueDrain(controller);171 let view;172 try {173 view = new @Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);174 } catch (error) {175 return @Promise.@reject(error);176 }177 return @Promise.@resolve({value: view, done: false});178 }179 if (controller.@autoAllocateChunkSize !== @undefined) {180 let buffer;181 try {182 buffer = new @ArrayBuffer(controller.@autoAllocateChunkSize);183 } catch (error) {184 return @Promise.@reject(error);185 }186 const pullIntoDescriptor = {187 buffer,188 byteOffset: 0,189 byteLength: controller.@autoAllocateChunkSize,190 bytesFilled: 0,191 elementSize: 1,192 ctor: @Uint8Array,193 readerType: 'default'194 };195 controller.@pendingPullIntos.@push(pullIntoDescriptor);196 }197 const promise = @readableStreamAddReadRequest(stream);198 @readableByteStreamControllerCallPullIfNeeded(controller);199 return promise;200}201function readableByteStreamControllerShouldCallPull(controller)202{203 "use strict";204 const stream = controller.@controlledReadableStream;205 if (stream.@state !== @streamReadable)206 return false;207 if (controller.@closeRequested)208 return false;209 if (!controller.@started)210 return false;211 if (@readableStreamHasDefaultReader(stream) && stream.@reader.@readRequests.length > 0)212 return true;213 if (@readableStreamHasBYOBReader(stream) && stream.@reader.@readIntoRequests.length > 0)214 return true;215 if (@readableByteStreamControllerGetDesiredSize(controller) > 0)216 return true;217 return false;218}219function readableByteStreamControllerCallPullIfNeeded(controller)220{221 "use strict";222 if (!@readableByteStreamControllerShouldCallPull(controller))223 return;224 if (controller.@pulling) {225 controller.@pullAgain = true;226 return;227 }228 @assert(!controller.@pullAgain);229 controller.@pulling = true;230 @promiseInvokeOrNoop(controller.@underlyingByteSource, "pull", [controller]).@then(() => {231 controller.@pulling = false;232 if (controller.@pullAgain) {233 controller.@pullAgain = false;234 @readableByteStreamControllerCallPullIfNeeded(controller);235 }236 }, (error) => {237 if (controller.@controlledReadableStream.@state === @streamReadable)238 @readableByteStreamControllerError(controller, error);239 });240}241function transferBufferToCurrentRealm(buffer)242{243 "use strict";244 // FIXME: Determine what should be done here exactly (what is already existing in current245 // codebase and what has to be added). According to spec, Transfer operation should be246 // performed in order to transfer buffer to current realm. For the moment, simply return247 // received buffer.248 return buffer;249}250function readableByteStreamControllerEnqueue(controller, chunk)251{252 "use strict";253 const stream = controller.@controlledReadableStream;254 @assert(!controller.@closeRequested);255 @assert(stream.@state === @streamReadable);256 const buffer = chunk.buffer;257 const byteOffset = chunk.byteOffset;258 const byteLength = chunk.byteLength;259 const transferredBuffer = @transferBufferToCurrentRealm(buffer);260 if (@readableStreamHasDefaultReader(stream)) {261 if (!stream.@reader.@readRequests.length)262 @readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);263 else {264 @assert(!controller.@queue.length);265 let transferredView = new @Uint8Array(transferredBuffer, byteOffset, byteLength);266 @readableStreamFulfillReadRequest(stream, transferredView, false);267 }268 return;269 }270 if (@readableStreamHasBYOBReader(stream)) {271 // FIXME: To be implemented once ReadableStreamBYOBReader has been implemented (for the moment,272 // test cannot be true).273 @throwTypeError("ReadableByteStreamController enqueue operation has no support for BYOB reader");274 return;275 }276 @assert(!@isReadableStreamLocked(stream));277 @readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);278}279function readableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength)280{281 "use strict";282 controller.@queue.@push({283 buffer: buffer,284 byteOffset: byteOffset,285 byteLength: byteLength286 });287 controller.@totalQueuedBytes += byteLength;...
Using AI Code Generation
1var rs = new ReadableStream({2 start(controller) {3 var view = controller.byobRequest.view;4 view[0] = 0x61;5 view[1] = 0x62;6 view[2] = 0x63;7 controller.byobRequest.respond(3);8 }9});10var reader = rs.getReader({ mode: "byob" });11var view = new Uint8Array(3);12var result = await reader.read(view);13assert_array_equals(view, [0x61, 0x62, 0x63], "view should contain the data written to the stream");14assert_equals(result.value, undefined, "result.value");15assert_false(result.done, "result.done");16var rs = new ReadableStream({17 start(controller) {18 controller.enqueue("a");19 controller.enqueue("b");20 controller.enqueue("c");21 }22});23var reader = rs.getReader();24var result = await reader.read();25assert_equals(result.value, "a", "result.value");26assert_false(result.done, "result.done");27var rs = new ReadableStream();28var reader = rs.getReader();29assert_false(rs.locked, "stream should not be locked");30assert_false(rs.disturbed, "stream should not be disturbed");31var result = await reader.read();32assert_true(rs.locked, "stream should be locked");33assert_true(rs.disturbed, "stream should be disturbed");34var rs = new ReadableStream();35var reader = rs.getReader();36assert_false(rs.locked, "stream should not be locked");37assert_false(rs.disturbed, "stream should not be disturbed");38var result = await reader.read();39assert_true(rs.locked, "stream should be locked");40assert_true(rs.disturbed, "stream should be disturbed");41var rs = new ReadableStream({42 start(controller) {43 controller.enqueue("a");44 controller.enqueue("b");45 controller.enqueue("c");46 controller.close();47 }48});49var [branch1, branch2] = rs.tee();
Using AI Code Generation
1var rs = new ReadableStream({2 pull: function(controller) {3 controller.enqueue(new Uint8Array([0x01, 0x02, 0x03]));4 controller.close();5 }6});7var reader = rs.getReader({ mode: 'byob' });8assert_true(ReadableStreamHasBYOBReader(rs), 'ReadableStreamHasBYOBReader should return true');9assert_true(reader instanceof ReadableStreamBYOBReader, 'reader should be a ReadableStreamBYOBReader');10var rs = new ReadableStream({11 pull: function(controller) {12 controller.enqueue(new Uint8Array([0x01, 0x02, 0x03]));13 controller.close();14 }15});16var reader = rs.getReader();17assert_true(ReadableStreamHasDefaultReader(rs), 'ReadableStreamHasDefaultReader should return true');18assert_true(reader instanceof ReadableStreamDefaultReader, 'reader should be a ReadableStreamDefaultReader');19var rs = new ReadableStream({20 pull: function(controller) {21 controller.enqueue(new Uint8Array([0x01, 0x02, 0x03]));22 controller.close();23 }24});25var reader = rs.getReader({ mode: 'byob' });26assert_true(ReadableStreamHasBYOBReader(rs), 'ReadableStreamHasBYOBReader should return true');27assert_true(reader instanceof ReadableStreamBYOBReader, 'reader should be a ReadableStreamBYOBReader');28var rs = new ReadableStream({29 pull: function(controller) {30 controller.enqueue(new Uint8Array([0x01, 0x02, 0x03]));31 controller.close();32 }33});34var reader = rs.getReader();35assert_true(ReadableStreamHasDefaultReader(rs), 'ReadableStreamHasDefaultReader should return true');36assert_true(reader instanceof ReadableStreamDefaultReader, 'reader should be a ReadableStreamDefaultReader');
Using AI Code Generation
1var rs = new ReadableStream({2 pull: function(c) {3 c.enqueue(new Uint8Array([0x01, 0x02]));4 c.close();5 }6});7var reader = rs.getReader({ mode: 'byob' });8assert_true(ReadableStreamHasBYOBReader(rs), 'ReadableStreamHasBYOBReader should return true');9assert_equals(ReadableStreamHasBYOBReader(new ReadableStream()), false, 'ReadableStreamHasBYOBReader should return false');10var rs = new ReadableStream({11 pull: function(c) {12 c.enqueue(new Uint8Array([0x01, 0x02]));13 c.close();14 }15});16var reader = rs.getReader();17assert_false(ReadableStreamHasBYOBReader(rs), 'ReadableStreamHasBYOBReader should return false');18var rs = new ReadableStream({19 pull: function(c) {20 c.enqueue(new Uint8Array([0x01, 0x02]));21 c.close();22 }23});24var reader = rs.getReader({ mode: 'byob' });25var byobRequest1 = reader.read(new Uint8Array(1));26var byobRequest2 = reader.read(new Uint8Array(1));27assert_equals(ReadableStreamGetNumReadIntoRequests(rs), 2, 'ReadableStreamGetNumReadIntoRequests should return 2');28assert_equals(ReadableStreamGetNumReadIntoRequests(new ReadableStream()), 0, 'ReadableStreamGetNumReadIntoRequests should return 0');29var rs = new ReadableStream({30 pull: function(c) {31 c.enqueue(new Uint8Array([0x01, 0x02]));32 c.close();33 }34});35var reader = rs.getReader();36var readRequest = reader.read();37assert_equals(ReadableStreamGetNumReadIntoRequests(rs), 0, 'ReadableStreamGetNumReadIntoRequests should return 0');38var rs = new ReadableStream({39 pull: function(c) {40 c.enqueue(new Uint8Array([0x01, 0x
Using AI Code Generation
1const { ReadableStream, ReadableStreamBYOBRequest } = require('stream/web');2const reader = new ReadableStream().getReader({ mode: 'byob' });3assert_true(reader instanceof ReadableStreamBYOBRequest);4assert_equals(typeof reader.constructor, 'function');5assert_equals(reader.constructor.name, 'ReadableStreamBYOBReader');6assert_equals(Object.getPrototypeOf(reader), ReadableStreamBYOBReader.prototype);7const { ReadableStream, ReadableStreamDefaultRequest } = require('stream/web');8const reader = new ReadableStream().getReader();9assert_true(reader instanceof ReadableStreamDefaultRequest);10assert_equals(typeof reader.constructor, 'function');11assert_equals(reader.constructor.name, 'ReadableStreamDefaultReader');12assert_equals(Object.getPrototypeOf(reader), ReadableStreamDefaultReader.prototype);13const { ReadableStream } = require('stream/web');14const rs = new ReadableStream();15assert_true(rs[Symbol.asyncIterator] instanceof Function);16const { ReadableStream } = require('stream/web');17const rs = new ReadableStream();18assert_true(rs[Symbol.asyncIterator].prototype instanceof Object);19const { ReadableStream } = require('stream/web');20const rs = new ReadableStream();21assert_true(rs[Symbol.asyncIterator].prototype.next instanceof Function);22const { ReadableStream } = require('stream/web');23const rs = new ReadableStream();24assert_true(rs[Symbol.asyncIterator].prototype.return instanceof Function);25const { ReadableStream } = require('stream/web');26const rs = new ReadableStream();27assert_true(rs[Symbol.asyncIterator].prototype.throw instanceof Function);28const { ReadableStream } = require('stream/web');29const rs = new ReadableStream();
Using AI Code Generation
1const { ReadableStream, ReadableStreamBYOBReader } = require('stream/web');2const stream = new ReadableStream({3 pull(c) {4 }5});6const reader = stream.getReader({ mode: 'byob' });7assert_true(reader instanceof ReadableStreamBYOBReader);8assert_true(reader instanceof ReadableStreamDefaultReader);9assert_true(ReadableStreamHasBYOBReader(stream));10assert_true(reader instanceof ReadableStreamDefaultReader);11assert_false(ReadableStreamHasDefaultReader(stream));12assert_false(reader instanceof ReadableStreamBYOBReader);13assert_false(ReadableStreamHasBYOBReader(stream));14assert_true(ReadableStreamHasDefaultReader(stream));15const { ReadableStream, ReadableStreamDefaultReader } = require('stream/web');16const stream = new ReadableStream({17 pull(c) {18 }19});20const reader = stream.getReader({ mode: 'byob' });21assert_true(reader instanceof ReadableStreamBYOBReader);22assert_true(reader instanceof ReadableStreamDefaultReader);23assert_true(ReadableStreamHasBYOBReader(stream));24assert_true(reader instanceof ReadableStreamDefaultReader);25assert_false(ReadableStreamHasDefaultReader(stream));26assert_false(reader instanceof ReadableStreamBYOBReader);27assert_false(ReadableStreamHasBYOBReader(stream));28assert_true(ReadableStreamHasDefaultReader(stream));29const { ReadableStream, ReadableStreamDefaultReader } = require('stream/web');30const stream = new ReadableStream({31 pull(c) {32 }33});34const reader = stream.getReader({ mode: 'byob' });35assert_true(reader instanceof ReadableStreamBYOBReader);36assert_true(reader instanceof ReadableStreamDefaultReader);37assert_true(ReadableStreamHasBYOBReader(stream));38assert_true(reader instanceof
Using AI Code Generation
1const assert = require('assert');2const { ReadableStream, ReadableStreamBYOBRequest } = require('stream/web');3const { ReadableStreamHasBYOBReader } = require('stream/web');4const { ReadableStreamBYOBReader } = require('stream/web');5const { ReadableStreamDefaultReader } = require('stream/web');6const { ReadableStreamDefaultController } = require('stream/web');7const { ReadableByteStreamController } = require('stream/web');8const rs = new ReadableStream({9 pull(controller) {10 controller.enqueue(new Uint8Array([1, 2, 3, 4]));11 }12});13const reader = rs.getReader({ mode: 'byob' });14assert(ReadableStreamHasBYOBReader(rs) === true);15assert(ReadableStreamHasBYOBReader(reader) === true);16assert(ReadableStreamHasBYOBReader(new ReadableStream()) === false);17assert(ReadableStreamHasBYOBReader(new ReadableStreamDefaultReader(new ReadableStream())) === false);18assert(ReadableStreamHasBYOBReader(new ReadableStreamBYOBReader(new ReadableStream())) === true);19assert(ReadableStreamHasBYOBReader(new ReadableStreamDefaultController()) === false);20assert(ReadableStreamHasBYOBReader(new ReadableByteStreamController()) === false);21assert(ReadableStreamHasBYOBReader() === false);22const assert = require('assert');23const { ReadableStream, ReadableStreamBYOBRequest } = require('stream/web');24const { ReadableStreamHasDefaultReader } = require('stream/web');25const { ReadableStreamBYOBReader } = require('stream/web');26const { ReadableStreamDefaultReader } = require('stream/web');27const { ReadableStreamDefaultController } = require('stream/web');28const { ReadableByteStreamController } = require('stream/web');29const rs = new ReadableStream({30 pull(controller) {31 controller.enqueue('a');32 controller.enqueue('b');33 controller.enqueue('c');34 }35});36const reader = rs.getReader();37assert(ReadableStreamHasDefaultReader(rs) === true);38assert(ReadableStreamHasDefaultReader(reader) === true);39assert(ReadableStreamHasDefaultReader(new ReadableStream()) === false);40assert(ReadableStreamHasDefaultReader(new ReadableStreamDefaultReader(new Readable
Using AI Code Generation
1const { ReadableStream, ReadableStreamBYOBReader } = require('stream/web');2const readable = new ReadableStream({3 pull(c) {4 }5});6const reader = new ReadableStreamBYOBReader(readable);7const { ReadableStream, ReadableStreamDefaultReader } = require('stream/web');8const readable = new ReadableStream({9 pull(c) {10 }11});12const reader = new ReadableStreamDefaultReader(readable);13const { WritableStream } = require('stream/web');14const ws = new WritableStream({15 write() {16 return Promise.reject(new Error('oh no!'));17 }18});19const { WritableStream } = require('stream/web');20const ws = new WritableStream({21 write() {22 return Promise.reject(new Error('oh no!'));23 }24});25const { WritableStream } = require('stream/web');26const ws = new WritableStream({27 write() {28 return Promise.reject(new Error('oh no!'));29 }30});31const writer = ws.getWriter();32const { WritableStream } = require('stream/web');33const ws = new WritableStream({34 write() {35 return Promise.reject(new Error('oh no!'));36 }37});38const writer = ws.getWriter();
Using AI Code Generation
1var test = async_test("ReadableStreamHasBYOBReader method exists");2test.step(function() {3 assert_true("ReadableStreamHasBYOBReader" in self, 'ReadableStreamHasBYOBReader method exists' );4 test.done();5});6promise_test(() => {7 const rs = new ReadableStream({8 start(controller) {9 controller.enqueue(new Uint8Array([1, 2, 3]));10 }11 });12 const reader = rs.getReader({ mode: "byob" });13 return reader.read(new Uint8Array(3)).then(result => {14 assert_object_equals(result, { value: new Uint8Array([1, 2, 3]), done: false }, "result");15 assert_false(ReadableStreamHasBYOBReader(rs), "ReadableStreamHasBYOBReader should return false");16 });17}, "ReadableStreamHasBYOBReader should return false when there is no BYOB reader");18promise_test(() => {19 const rs = new ReadableStream({20 start(controller) {21 controller.enqueue(new Uint8Array([1, 2, 3]));22 }23 });24 const reader = rs.getReader();25 return reader.read().then(result => {26 assert_object_equals(result, { value: new Uint8Array([1, 2, 3]), done: false }, "result");27 assert_false(ReadableStreamHasBYOBReader(rs), "ReadableStreamHasBYOBReader should return false");28 });29}, "ReadableStreamHasBYOBReader should return false when there is no BYOB reader");
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!