How to use ReadableStreamDefaultControllerCallPullIfNeeded method in wpt

Best JavaScript code snippet using wpt

ReadableStreamInternals.js

Source:ReadableStreamInternals.js Github

copy

Full Screen

1/*2 * Copyright (C) 2015 Canon Inc. All rights reserved.3 * Copyright (C) 2015 Igalia.4 *5 * Redistribution and use in source and binary forms, with or without6 * modification, are permitted provided that the following conditions7 * are met:8 * 1. Redistributions of source code must retain the above copyright9 * notice, this list of conditions and the following disclaimer.10 * 2. Redistributions in binary form must reproduce the above copyright11 * notice, this list of conditions and the following disclaimer in the12 * documentation and/or other materials provided with the distribution.13 *14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25 */26// @conditional=ENABLE(READABLE_STREAM_API)27// @internal28function privateInitializeReadableStreamDefaultReader(stream)29{30 "use strict";31 if (!@isReadableStream(stream))32 @throwTypeError("ReadableStreamDefaultReader needs a ReadableStream");33 if (@isReadableStreamLocked(stream))34 @throwTypeError("ReadableStream is locked");35 @readableStreamReaderGenericInitialize(this, stream);36 this.@readRequests = [];37 return this;38}39function readableStreamReaderGenericInitialize(reader, stream)40{41 "use strict";42 reader.@ownerReadableStream = stream;43 stream.@reader = reader;44 if (stream.@state === @streamReadable)45 reader.@closedPromiseCapability = @newPromiseCapability(@Promise);46 else if (stream.@state === @streamClosed)47 reader.@closedPromiseCapability = { @promise: @Promise.@resolve() };48 else {49 @assert(stream.@state === @streamErrored);50 reader.@closedPromiseCapability = { @promise: @Promise.@reject(stream.@storedError) };51 }52}53function privateInitializeReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark)54{55 "use strict";56 if (!@isReadableStream(stream))57 @throwTypeError("ReadableStreamDefaultController needs a ReadableStream");58 // readableStreamController is initialized with null value.59 if (stream.@readableStreamController !== null)60 @throwTypeError("ReadableStream already has a controller");61 this.@controlledReadableStream = stream;62 this.@underlyingSource = underlyingSource;63 this.@queue = @newQueue();64 this.@started = false;65 this.@closeRequested = false;66 this.@pullAgain = false;67 this.@pulling = false;68 this.@strategy = @validateAndNormalizeQueuingStrategy(size, highWaterMark);69 const controller = this;70 @promiseInvokeOrNoopNoCatch(underlyingSource, "start", [this]).@then(() => {71 controller.@started = true;72 @assert(!controller.@pulling);73 @assert(!controller.@pullAgain);74 @readableStreamDefaultControllerCallPullIfNeeded(controller);75 }, (error) => {76 if (stream.@state === @streamReadable)77 @readableStreamDefaultControllerError(controller, error);78 });79 this.@cancel = @readableStreamDefaultControllerCancel;80 this.@pull = @readableStreamDefaultControllerPull;81 return this;82}83function readableStreamDefaultControllerError(controller, error)84{85 "use strict";86 const stream = controller.@controlledReadableStream;87 @assert(stream.@state === @streamReadable);88 controller.@queue = @newQueue();89 @readableStreamError(stream, error);90}91function readableStreamTee(stream, shouldClone)92{93 "use strict";94 @assert(@isReadableStream(stream));95 @assert(typeof(shouldClone) === "boolean");96 const reader = new @ReadableStreamDefaultReader(stream);97 const teeState = {98 closedOrErrored: false,99 canceled1: false,100 canceled2: false,101 reason1: @undefined,102 reason2: @undefined,103 };104 teeState.cancelPromiseCapability = @newPromiseCapability(@InternalPromise);105 const pullFunction = @readableStreamTeePullFunction(teeState, reader, shouldClone);106 const branch1 = new @ReadableStream({107 "pull": pullFunction,108 "cancel": @readableStreamTeeBranch1CancelFunction(teeState, stream)109 });110 const branch2 = new @ReadableStream({111 "pull": pullFunction,112 "cancel": @readableStreamTeeBranch2CancelFunction(teeState, stream)113 });114 reader.@closedPromiseCapability.@promise.@then(@undefined, function(e) {115 if (teeState.closedOrErrored)116 return;117 @readableStreamDefaultControllerError(branch1.@readableStreamController, e);118 @readableStreamDefaultControllerError(branch2.@readableStreamController, e);119 teeState.closedOrErrored = true;120 });121 // Additional fields compared to the spec, as they are needed within pull/cancel functions.122 teeState.branch1 = branch1;123 teeState.branch2 = branch2;124 return [branch1, branch2];125}126function doStructuredClone(object)127{128 "use strict";129 // FIXME: We should implement http://w3c.github.io/html/infrastructure.html#ref-for-structured-clone-4130 // Implementation is currently limited to ArrayBuffer/ArrayBufferView to meet Fetch API needs.131 if (object instanceof @ArrayBuffer)132 return @structuredCloneArrayBuffer(object);133 if (@ArrayBuffer.@isView(object))134 return @structuredCloneArrayBufferView(object);135 @throwTypeError("structuredClone not implemented for: " + object);136}137function readableStreamTeePullFunction(teeState, reader, shouldClone)138{139 "use strict";140 return function() {141 @Promise.prototype.@then.@call(@readableStreamDefaultReaderRead(reader), function(result) {142 @assert(@isObject(result));143 @assert(typeof result.done === "boolean");144 if (result.done && !teeState.closedOrErrored) {145 if (!teeState.canceled1)146 @readableStreamDefaultControllerClose(teeState.branch1.@readableStreamController);147 if (!teeState.canceled2)148 @readableStreamDefaultControllerClose(teeState.branch2.@readableStreamController);149 teeState.closedOrErrored = true;150 }151 if (teeState.closedOrErrored)152 return;153 if (!teeState.canceled1)154 @readableStreamDefaultControllerEnqueue(teeState.branch1.@readableStreamController, result.value);155 if (!teeState.canceled2)156 @readableStreamDefaultControllerEnqueue(teeState.branch2.@readableStreamController, shouldClone ? @doStructuredClone(result.value) : result.value);157 });158 }159}160function readableStreamTeeBranch1CancelFunction(teeState, stream)161{162 "use strict";163 return function(r) {164 teeState.canceled1 = true;165 teeState.reason1 = r;166 if (teeState.canceled2) {167 @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(168 teeState.cancelPromiseCapability.@resolve,169 teeState.cancelPromiseCapability.@reject);170 }171 return teeState.cancelPromiseCapability.@promise;172 }173}174function readableStreamTeeBranch2CancelFunction(teeState, stream)175{176 "use strict";177 return function(r) {178 teeState.canceled2 = true;179 teeState.reason2 = r;180 if (teeState.canceled1) {181 @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(182 teeState.cancelPromiseCapability.@resolve,183 teeState.cancelPromiseCapability.@reject);184 }185 return teeState.cancelPromiseCapability.@promise;186 }187}188function isReadableStream(stream)189{190 "use strict";191 // Spec tells to return true only if stream has a readableStreamController internal slot.192 // However, since it is a private slot, it cannot be checked using hasOwnProperty().193 // Therefore, readableStreamController is initialized with null value.194 return @isObject(stream) && stream.@readableStreamController !== @undefined;195}196function isReadableStreamDefaultReader(reader)197{198 "use strict";199 // Spec tells to return true only if reader has a readRequests internal slot.200 // However, since it is a private slot, it cannot be checked using hasOwnProperty().201 // Since readRequests is initialized with an empty array, the following test is ok.202 return @isObject(reader) && !!reader.@readRequests;203}204function isReadableStreamDefaultController(controller)205{206 "use strict";207 // Spec tells to return true only if controller has an underlyingSource internal slot.208 // However, since it is a private slot, it cannot be checked using hasOwnProperty().209 // underlyingSource is obtained in ReadableStream constructor: if undefined, it is set210 // to an empty object. Therefore, following test is ok.211 return @isObject(controller) && !!controller.@underlyingSource;212}213function readableStreamError(stream, error)214{215 "use strict";216 @assert(@isReadableStream(stream));217 @assert(stream.@state === @streamReadable);218 stream.@state = @streamErrored;219 stream.@storedError = error;220 if (!stream.@reader)221 return;222 const reader = stream.@reader;223 if (@isReadableStreamDefaultReader(reader)) {224 const requests = reader.@readRequests;225 for (let index = 0, length = requests.length; index < length; ++index)226 requests[index].@reject.@call(@undefined, error);227 reader.@readRequests = [];228 } else229 // FIXME: Implement ReadableStreamBYOBReader.230 @throwTypeError("Only ReadableStreamDefaultReader is currently supported");231 reader.@closedPromiseCapability.@reject.@call(@undefined, error);232}233function readableStreamDefaultControllerCallPullIfNeeded(controller)234{235 "use strict";236 const stream = controller.@controlledReadableStream;237 if (stream.@state === @streamClosed || stream.@state === @streamErrored)238 return;239 if (controller.@closeRequested)240 return;241 if (!controller.@started)242 return;243 if ((!@isReadableStreamLocked(stream) || !stream.@reader.@readRequests.length) && @readableStreamDefaultControllerGetDesiredSize(controller) <= 0)244 return;245 if (controller.@pulling) {246 controller.@pullAgain = true;247 return;248 }249 @assert(!controller.@pullAgain);250 controller.@pulling = true;251 @promiseInvokeOrNoop(controller.@underlyingSource, "pull", [controller]).@then(function() {252 controller.@pulling = false;253 if (controller.@pullAgain) {254 controller.@pullAgain = false;255 @readableStreamDefaultControllerCallPullIfNeeded(controller);256 }257 }, function(error) {258 if (stream.@state === @streamReadable)259 @readableStreamDefaultControllerError(controller, error);260 });261}262function isReadableStreamLocked(stream)263{264 "use strict";265 @assert(@isReadableStream(stream));266 return !!stream.@reader;267}268function readableStreamDefaultControllerGetDesiredSize(controller)269{270 "use strict";271 return controller.@strategy.highWaterMark - controller.@queue.size;272}273function readableStreamReaderGenericCancel(reader, reason)274{275 "use strict";276 const stream = reader.@ownerReadableStream;277 @assert(!!stream);278 return @readableStreamCancel(stream, reason);279}280function readableStreamCancel(stream, reason)281{282 "use strict";283 stream.@disturbed = true;284 if (stream.@state === @streamClosed)285 return @Promise.@resolve();286 if (stream.@state === @streamErrored)287 return @Promise.@reject(stream.@storedError);288 @readableStreamClose(stream);289 return stream.@readableStreamController.@cancel(stream.@readableStreamController, reason).@then(function() { });290}291function readableStreamDefaultControllerCancel(controller, reason)292{293 "use strict";294 controller.@queue = @newQueue();295 return @promiseInvokeOrNoop(controller.@underlyingSource, "cancel", [reason]);296}297function readableStreamDefaultControllerPull(controller)298{299 "use strict";300 const stream = controller.@controlledReadableStream;301 if (controller.@queue.content.length) {302 const chunk = @dequeueValue(controller.@queue);303 if (controller.@closeRequested && controller.@queue.content.length === 0)304 @readableStreamClose(stream);305 else306 @readableStreamDefaultControllerCallPullIfNeeded(controller);307 return @Promise.@resolve({value: chunk, done: false});308 }309 const pendingPromise = @readableStreamAddReadRequest(stream);310 @readableStreamDefaultControllerCallPullIfNeeded(controller);311 return pendingPromise;312}313function readableStreamDefaultControllerClose(controller)314{315 "use strict";316 const stream = controller.@controlledReadableStream;317 @assert(!controller.@closeRequested);318 @assert(stream.@state === @streamReadable);319 controller.@closeRequested = true;320 if (controller.@queue.content.length === 0)321 @readableStreamClose(stream);322}323function readableStreamClose(stream)324{325 "use strict";326 @assert(stream.@state === @streamReadable);327 stream.@state = @streamClosed;328 const reader = stream.@reader;329 if (!reader)330 return;331 if (@isReadableStreamDefaultReader(reader)) {332 const requests = reader.@readRequests;333 for (let index = 0, length = requests.length; index < length; ++index)334 requests[index].@resolve.@call(@undefined, {value:@undefined, done: true});335 reader.@readRequests = [];336 }337 reader.@closedPromiseCapability.@resolve.@call();338}339function readableStreamFulfillReadRequest(stream, chunk, done)340{341 "use strict";342 stream.@reader.@readRequests.@shift().@resolve.@call(@undefined, {value: chunk, done: done});343}344function readableStreamDefaultControllerEnqueue(controller, chunk)345{346 "use strict";347 const stream = controller.@controlledReadableStream;348 @assert(!controller.@closeRequested);349 @assert(stream.@state === @streamReadable);350 if (@isReadableStreamLocked(stream) && stream.@reader.@readRequests.length) {351 @readableStreamFulfillReadRequest(stream, chunk, false);352 @readableStreamDefaultControllerCallPullIfNeeded(controller);353 return;354 }355 try {356 let chunkSize = 1;357 if (controller.@strategy.size !== @undefined)358 chunkSize = controller.@strategy.size(chunk);359 @enqueueValueWithSize(controller.@queue, chunk, chunkSize);360 }361 catch(error) {362 if (stream.@state === @streamReadable)363 @readableStreamDefaultControllerError(controller, error);364 throw error;365 }366 @readableStreamDefaultControllerCallPullIfNeeded(controller);367}368function readableStreamDefaultReaderRead(reader)369{370 "use strict";371 const stream = reader.@ownerReadableStream;372 @assert(!!stream);373 stream.@disturbed = true;374 if (stream.@state === @streamClosed)375 return @Promise.@resolve({value: @undefined, done: true});376 if (stream.@state === @streamErrored)377 return @Promise.@reject(stream.@storedError);378 @assert(stream.@state === @streamReadable);379 return stream.@readableStreamController.@pull(stream.@readableStreamController);380}381function readableStreamAddReadRequest(stream)382{383 "use strict";384 @assert(@isReadableStreamDefaultReader(stream.@reader));385 @assert(stream.@state == @streamReadable);386 const readRequest = @newPromiseCapability(@Promise);387 stream.@reader.@readRequests.@push(readRequest);388 return readRequest.@promise;389}390function isReadableStreamDisturbed(stream)391{392 "use strict";393 @assert(@isReadableStream(stream));394 return stream.@disturbed;395}396function readableStreamReaderGenericRelease(reader)397{398 "use strict";399 @assert(!!reader.@ownerReadableStream);400 @assert(reader.@ownerReadableStream.@reader === reader);401 if (reader.@ownerReadableStream.@state === @streamReadable)402 reader.@closedPromiseCapability.@reject.@call(@undefined, new @TypeError("releasing lock of reader whose stream is still in readable state"));403 else404 reader.@closedPromiseCapability = { @promise: @Promise.@reject(new @TypeError("reader released lock")) };405 reader.@ownerReadableStream.@reader = @undefined;406 reader.@ownerReadableStream = null;...

Full Screen

Full Screen

default-controller.ts

Source:default-controller.ts Github

copy

Full Screen

...104 if (this._closeRequested && this._queue.length === 0) {105 ReadableStreamDefaultControllerClearAlgorithms(this);106 ReadableStreamClose(stream);107 } else {108 ReadableStreamDefaultControllerCallPullIfNeeded(this);109 }110 readRequest._chunkSteps(chunk);111 } else {112 ReadableStreamAddReadRequest(stream, readRequest);113 ReadableStreamDefaultControllerCallPullIfNeeded(this);114 }115 }116}117Object.defineProperties(ReadableStreamDefaultController.prototype, {118 close: { enumerable: true },119 enqueue: { enumerable: true },120 error: { enumerable: true },121 desiredSize: { enumerable: true }122});123if (typeof Symbol.toStringTag === 'symbol') {124 Object.defineProperty(ReadableStreamDefaultController.prototype, Symbol.toStringTag, {125 value: 'ReadableStreamDefaultController',126 configurable: true127 });128}129// Abstract operations for the ReadableStreamDefaultController.130function IsReadableStreamDefaultController<R = any>(x: any): x is ReadableStreamDefaultController<R> {131 if (!typeIsObject(x)) {132 return false;133 }134 if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {135 return false;136 }137 return true;138}139function ReadableStreamDefaultControllerCallPullIfNeeded(controller: ReadableStreamDefaultController<any>): void {140 const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);141 if (!shouldPull) {142 return;143 }144 if (controller._pulling) {145 controller._pullAgain = true;146 return;147 }148 assert(!controller._pullAgain);149 controller._pulling = true;150 const pullPromise = controller._pullAlgorithm();151 uponPromise(152 pullPromise,153 () => {154 controller._pulling = false;155 if (controller._pullAgain) {156 controller._pullAgain = false;157 ReadableStreamDefaultControllerCallPullIfNeeded(controller);158 }159 },160 e => {161 ReadableStreamDefaultControllerError(controller, e);162 }163 );164}165function ReadableStreamDefaultControllerShouldCallPull(controller: ReadableStreamDefaultController<any>): boolean {166 const stream = controller._controlledReadableStream;167 if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {168 return false;169 }170 if (!controller._started) {171 return false;172 }173 if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {174 return true;175 }176 const desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);177 assert(desiredSize !== null);178 if (desiredSize! > 0) {179 return true;180 }181 return false;182}183function ReadableStreamDefaultControllerClearAlgorithms(controller: ReadableStreamDefaultController<any>) {184 controller._pullAlgorithm = undefined!;185 controller._cancelAlgorithm = undefined!;186 controller._strategySizeAlgorithm = undefined!;187}188// A client of ReadableStreamDefaultController may use these functions directly to bypass state check.189export function ReadableStreamDefaultControllerClose(controller: ReadableStreamDefaultController<any>) {190 if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {191 return;192 }193 const stream = controller._controlledReadableStream;194 controller._closeRequested = true;195 if (controller._queue.length === 0) {196 ReadableStreamDefaultControllerClearAlgorithms(controller);197 ReadableStreamClose(stream);198 }199}200export function ReadableStreamDefaultControllerEnqueue<R>(controller: ReadableStreamDefaultController<R>, chunk: R): void {201 if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {202 return;203 }204 const stream = controller._controlledReadableStream;205 if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {206 ReadableStreamFulfillReadRequest(stream, chunk, false);207 } else {208 let chunkSize;209 try {210 chunkSize = controller._strategySizeAlgorithm(chunk);211 } catch (chunkSizeE) {212 ReadableStreamDefaultControllerError(controller, chunkSizeE);213 throw chunkSizeE;214 }215 try {216 EnqueueValueWithSize(controller, chunk, chunkSize);217 } catch (enqueueE) {218 ReadableStreamDefaultControllerError(controller, enqueueE);219 throw enqueueE;220 }221 }222 ReadableStreamDefaultControllerCallPullIfNeeded(controller);223}224export function ReadableStreamDefaultControllerError(controller: ReadableStreamDefaultController<any>, e: any) {225 const stream = controller._controlledReadableStream;226 if (stream._state !== 'readable') {227 return;228 }229 ResetQueue(controller);230 ReadableStreamDefaultControllerClearAlgorithms(controller);231 ReadableStreamError(stream, e);232}233export function ReadableStreamDefaultControllerGetDesiredSize(controller: ReadableStreamDefaultController<any>): number | null {234 const stream = controller._controlledReadableStream;235 const state = stream._state;236 if (state === 'errored') {237 return null;238 }239 if (state === 'closed') {240 return 0;241 }242 return controller._strategyHWM - controller._queueTotalSize;243}244// This is used in the implementation of TransformStream.245export function ReadableStreamDefaultControllerHasBackpressure(controller: ReadableStreamDefaultController<any>): boolean {246 if (ReadableStreamDefaultControllerShouldCallPull(controller)) {247 return false;248 }249 return true;250}251export function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller: ReadableStreamDefaultController<any>): boolean {252 const state = controller._controlledReadableStream._state;253 if (!controller._closeRequested && state === 'readable') {254 return true;255 }256 return false;257}258export function SetUpReadableStreamDefaultController<R>(stream: ReadableStream<R>,259 controller: ReadableStreamDefaultController<R>,260 startAlgorithm: () => void | PromiseLike<void>,261 pullAlgorithm: () => Promise<void>,262 cancelAlgorithm: (reason: any) => Promise<void>,263 highWaterMark: number,264 sizeAlgorithm: QueuingStrategySizeCallback<R>) {265 assert(stream._readableStreamController === undefined);266 controller._controlledReadableStream = stream;267 controller._queue = undefined!;268 controller._queueTotalSize = undefined!;269 ResetQueue(controller);270 controller._started = false;271 controller._closeRequested = false;272 controller._pullAgain = false;273 controller._pulling = false;274 controller._strategySizeAlgorithm = sizeAlgorithm;275 controller._strategyHWM = highWaterMark;276 controller._pullAlgorithm = pullAlgorithm;277 controller._cancelAlgorithm = cancelAlgorithm;278 stream._readableStreamController = controller;279 const startResult = startAlgorithm();280 uponPromise(281 promiseResolvedWith(startResult),282 () => {283 controller._started = true;284 assert(!controller._pulling);285 assert(!controller._pullAgain);286 ReadableStreamDefaultControllerCallPullIfNeeded(controller);287 },288 r => {289 ReadableStreamDefaultControllerError(controller, r);290 }291 );292}293export function SetUpReadableStreamDefaultControllerFromUnderlyingSource<R>(294 stream: ReadableStream<R>,295 underlyingSource: ValidatedUnderlyingSource<R>,296 highWaterMark: number,297 sizeAlgorithm: QueuingStrategySizeCallback<R>298) {299 const controller: ReadableStreamDefaultController<R> = Object.create(ReadableStreamDefaultController.prototype);300 let startAlgorithm: () => void | PromiseLike<void> = () => undefined;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1'use strict';2if (this.importScripts) {3 importScripts('/resources/testharness.js');4}5test(() => {6 const rs = new ReadableStream();7 const reader = rs.getReader();8 const controller = rs.getReader().[[ownerReadableStream]].[[readableStreamController]];9 assert_throws_js(TypeError, () => controller.callPullIfNeeded());10}, 'ReadableStreamDefaultControllerCallPullIfNeeded throws a TypeError if this is not a ReadableStreamDefaultController');11test(() => {12 const rs = new ReadableStream({13 start(c) {14 c.callPullIfNeeded();15 }16 });17 return rs.getReader().read();18}, 'ReadableStreamDefaultControllerCallPullIfNeeded can be called in start');19test(() => {20 let controller;21 const rs = new ReadableStream({22 start(c) {23 controller = c;24 }25 });26 const reader = rs.getReader();27 reader.read();28 return delay(0).then(() => {29 controller.callPullIfNeeded();30 return reader.read();31 });32}, 'ReadableStreamDefaultControllerCallPullIfNeeded can be called in pull');33promise_test(() => {34 const rs = recordingReadableStream({35 pull(controller) {36 controller.callPullIfNeeded();37 }38 });39 const reader = rs.getReader();40 return reader.read().then(() => {41 assert_array_equals(rs.events, ['pull', 'pull']);42 });43}, 'ReadableStreamDefaultControllerCallPullIfNeeded can be called recursively');44test(() => {45 const rs = new ReadableStream({46 start(c) {47 c.callPullIfNeeded();48 c.callPullIfNeeded();49 }50 });51 return rs.getReader().read();52}, 'ReadableStreamDefaultControllerCallPullIfNeeded can be called twice in start');53test(() => {54 let controller;55 const rs = new ReadableStream({56 start(c) {57 controller = c;58 }59 });60 const reader = rs.getReader();61 reader.read();62 return delay(0).then(() => {63 controller.callPullIfNeeded();64 controller.callPullIfNeeded();65 return reader.read();66 });67}, 'ReadableStreamDefaultControllerCallPullIfNeeded can be called twice in pull');68promise_test(() => {69 let controller;70 const rs = recordingReadableStream({71 start(c) {72 controller = c;73 },74 pull() {75 controller.callPullIfNeeded();76 }77 });

Full Screen

Using AI Code Generation

copy

Full Screen

1test(function() {2 var rs = new ReadableStream({3 pull: function(controller) {4 assert_equals(controller.desiredSize, 0);5 controller.enqueue(new Uint8Array([1, 2, 3]));6 }7 });8 var reader = rs.getReader();9 var readPromise = reader.read();10 return readPromise.then(function(result) {11 assert_false(result.done, 'done');12 assert_array_equals(result.value, [1, 2, 3], 'value');13 return reader.closed;14 });15}, 'ReadableStream with byte source: call ReadableStreamDefaultControllerCallPullIfNeeded ' +16 'when desiredSize is 0');

Full Screen

Using AI Code Generation

copy

Full Screen

1var rs = new ReadableStream({2 pull(controller) {3 controller.enqueue('a');4 controller.close();5 }6});7var reader = rs.getReader();8reader.read().then(result => {9 assert_equals(result.value, 'a');10 assert_false(result.done);11 return reader.read();12}).then(result => {13 assert_equals(result.value, undefined);14 assert_true(result.done);15 return reader.closed;16}).then(() => {17 assert_true(true, 'closed fulfilled');18}, () => {19 assert_unreached('closed rejected');20});21var rs = new ReadableStream({22 pull(controller) {23 controller.enqueue('a');24 controller.close();25 }26});27var reader = rs.getReader();28reader.read().then(result => {29 assert_equals(result.value, 'a');30 assert_false(result.done);31 return reader.read();32}).then(result => {33 assert_equals(result.value, undefined);34 assert_true(result.done);35 return reader.closed;36}).then(() => {37 assert_true(true, 'closed fulfilled');38}, () => {39 assert_unreached('closed rejected');40});41var rs = new ReadableStream({42 pull(controller) {43 controller.enqueue('a');44 controller.close();45 }46});47var reader = rs.getReader();48reader.read().then(result => {49 assert_equals(result.value, 'a');50 assert_false(result.done);51 return reader.read();52}).then(result => {53 assert_equals(result.value, undefined);54 assert_true(result.done);55 return reader.closed;56}).then(() => {57 assert_true(true, 'closed fulfilled');58}, () => {59 assert_unreached('closed rejected');60});61var rs = new ReadableStream({62 pull(controller) {63 controller.enqueue('a');64 controller.close();65 }66});67var reader = rs.getReader();68reader.read().then(result => {69 assert_equals(result.value,

Full Screen

Using AI Code Generation

copy

Full Screen

1var rs = new ReadableStream({2 start(controller) {3 controller.enqueue('a');4 }5});6rs.getReader().read().then(({ value, done }) => {7 assert_equals(value, 'a');8 assert_false(done);9}, unreached_rejection('read() should not reject'));10rs.getReader().read().then(({ value, done }) => {11 assert_equals(value, undefined);12 assert_true(done);13}, unreached_rejection('read() should not reject'));14rs.getReader().read().then(({ value, done }) => {15 assert_equals(value, undefined);16 assert_true(done);17}, unreached_rejection('read() should not reject'));18rs.getReader().read().then(({ value, done }) => {19 assert_equals(value, undefined);20 assert_true(done);21}, unreached_rejection('read() should not reject'));22rs.getReader().read().then(({ value, done }) => {23 assert_equals(value, undefined);24 assert_true(done);25}, unreached_rejection('read() should not reject'));26rs.getReader().read().then(({ value, done }) => {27 assert_equals(value, undefined);28 assert_true(done);29}, unreached_rejection('read() should not reject'));30rs.getReader().read().then(({ value, done }) => {31 assert_equals(value, undefined);32 assert_true(done);33}, unreached_rejection('read() should not reject'));34rs.getReader().read().then(({ value, done }) => {35 assert_equals(value, undefined);36 assert_true(done);37}, unreached_rejection('read() should not reject'));38rs.getReader().read().then(({ value, done }) => {39 assert_equals(value, undefined);40 assert_true(done);41}, unreached_rejection('read() should not reject'));42rs.getReader().read().then(({ value, done }) => {43 assert_equals(value, undefined);44 assert_true(done);45}, unreached_rejection('read() should not reject'));46rs.getReader().read().then(({ value, done }) => {47 assert_equals(value, undefined);48 assert_true(done);49}, unreached_rejection('read() should not reject'));50rs.getReader().read().then(({ value, done }) => {51 assert_equals(value, undefined);52 assert_true(done);53}, unreached_rejection('read()

Full Screen

Using AI Code Generation

copy

Full Screen

1promise_test(t => {2 let rs = recordingReadableStream({3 start(c) {4 c.enqueue('a');5 c.enqueue('b');6 c.enqueue('c');7 }8 });9 let reader = rs.getReader();10 return reader.read().then(result1 => {11 assert_equals(result1.value, 'a');12 assert_false(result1.done);13 return reader.read();14 }).then(result2 => {15 assert_equals(result2.value, 'b');16 assert_false(result2.done);17 return reader.read();18 }).then(result3 => {19 assert_equals(result3.value, 'c');20 assert_false(result3.done);21 return reader.read();22 }).then(result4 => {23 assert_equals(result4.value, undefined);24 assert_true(result4.done);25 });26}, 'ReadableStreamDefaultControllerCallPullIfNeeded method normal test');27promise_test(t => {28 let rs = recordingReadableStream({29 start(c) {30 c.enqueue('a');31 c.enqueue('b');32 c.enqueue('c');33 }34 });35 let reader = rs.getReader();36 return reader.read().then(result1 => {37 assert_equals(result1.value, 'a');38 assert_false(result1.done);39 return reader.read();40 }).then(result2 => {41 assert_equals(result2.value, 'b');42 assert_false(result2.done);43 return reader.read();44 }).then(result3 => {45 assert_equals(result3.value, 'c');46 assert_false(result3.done);47 return reader.read();48 }).then(result4 => {49 assert_equals(result4.value, undefined);50 assert_true(result4.done);51 return reader.read();52 }).then(result5 => {53 assert_equals(result5.value, undefined);54 assert_true(result5.done);55 });56}, 'ReadableStreamDefaultControllerCallPullIfNeeded method normal test2');57promise_test(t => {58 let rs = recordingReadableStream({59 start(c) {60 c.enqueue('a');61 c.enqueue('b');62 c.enqueue('c');63 }64 });65 let reader = rs.getReader();66 return reader.read().then(result1 => {67 assert_equals(result1.value, 'a');68 assert_false(result1.done);69 return reader.read();70 }).then(result2 => {71 assert_equals(result2.value, 'b');

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