11cb0ef41Sopenharmony_ci// META: global=window,worker
21cb0ef41Sopenharmony_ci// META: script=../resources/rs-utils.js
31cb0ef41Sopenharmony_ci// META: script=../resources/test-utils.js
41cb0ef41Sopenharmony_ci'use strict';
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst error1 = new Error('error1');
71cb0ef41Sopenharmony_cierror1.name = 'error1';
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_citest(() => {
101cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => new ReadableStream().getReader({ mode: 'byob' }));
111cb0ef41Sopenharmony_ci}, 'getReader({mode: "byob"}) throws on non-bytes streams');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_citest(() => {
151cb0ef41Sopenharmony_ci  // Constructing ReadableStream with an empty underlying byte source object as parameter shouldn't throw.
161cb0ef41Sopenharmony_ci  new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' });
171cb0ef41Sopenharmony_ci  // Constructor must perform ToString(type).
181cb0ef41Sopenharmony_ci  new ReadableStream({ type: { toString() {return 'bytes';} } })
191cb0ef41Sopenharmony_ci    .getReader({ mode: 'byob' });
201cb0ef41Sopenharmony_ci  new ReadableStream({ type: { toString: null, valueOf() {return 'bytes';} } })
211cb0ef41Sopenharmony_ci    .getReader({ mode: 'byob' });
221cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source can be constructed with no errors');
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_citest(() => {
251cb0ef41Sopenharmony_ci  const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
261cb0ef41Sopenharmony_ci  const rs = new ReadableStream({ type: 'bytes' });
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  let reader = rs.getReader({ mode: { toString() { return 'byob'; } } });
291cb0ef41Sopenharmony_ci  assert_true(reader instanceof ReadableStreamBYOBReader, 'must give a BYOB reader');
301cb0ef41Sopenharmony_ci  reader.releaseLock();
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  reader = rs.getReader({ mode: { toString: null, valueOf() {return 'byob';} } });
331cb0ef41Sopenharmony_ci  assert_true(reader instanceof ReadableStreamBYOBReader, 'must give a BYOB reader');
341cb0ef41Sopenharmony_ci  reader.releaseLock();
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  reader = rs.getReader({ mode: 'byob', notmode: 'ignored' });
371cb0ef41Sopenharmony_ci  assert_true(reader instanceof ReadableStreamBYOBReader, 'must give a BYOB reader');
381cb0ef41Sopenharmony_ci}, 'getReader({mode}) must perform ToString()');
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cipromise_test(() => {
411cb0ef41Sopenharmony_ci  let startCalled = false;
421cb0ef41Sopenharmony_ci  let startCalledBeforePull = false;
431cb0ef41Sopenharmony_ci  let desiredSize;
441cb0ef41Sopenharmony_ci  let controller;
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  let resolveTestPromise;
471cb0ef41Sopenharmony_ci  const testPromise = new Promise(resolve => {
481cb0ef41Sopenharmony_ci    resolveTestPromise = resolve;
491cb0ef41Sopenharmony_ci  });
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  new ReadableStream({
521cb0ef41Sopenharmony_ci    start(c) {
531cb0ef41Sopenharmony_ci      controller = c;
541cb0ef41Sopenharmony_ci      startCalled = true;
551cb0ef41Sopenharmony_ci    },
561cb0ef41Sopenharmony_ci    pull() {
571cb0ef41Sopenharmony_ci      startCalledBeforePull = startCalled;
581cb0ef41Sopenharmony_ci      desiredSize = controller.desiredSize;
591cb0ef41Sopenharmony_ci      resolveTestPromise();
601cb0ef41Sopenharmony_ci    },
611cb0ef41Sopenharmony_ci    type: 'bytes'
621cb0ef41Sopenharmony_ci  }, {
631cb0ef41Sopenharmony_ci    highWaterMark: 256
641cb0ef41Sopenharmony_ci  });
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  return testPromise.then(() => {
671cb0ef41Sopenharmony_ci    assert_true(startCalledBeforePull, 'start should be called before pull');
681cb0ef41Sopenharmony_ci    assert_equals(desiredSize, 256, 'desiredSize should equal highWaterMark');
691cb0ef41Sopenharmony_ci  });
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Construct and expect start and pull being called');
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_cipromise_test(() => {
741cb0ef41Sopenharmony_ci  let pullCount = 0;
751cb0ef41Sopenharmony_ci  let checkedNoPull = false;
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  let resolveTestPromise;
781cb0ef41Sopenharmony_ci  const testPromise = new Promise(resolve => {
791cb0ef41Sopenharmony_ci    resolveTestPromise = resolve;
801cb0ef41Sopenharmony_ci  });
811cb0ef41Sopenharmony_ci  let resolveStartPromise;
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci  new ReadableStream({
841cb0ef41Sopenharmony_ci    start() {
851cb0ef41Sopenharmony_ci      return new Promise(resolve => {
861cb0ef41Sopenharmony_ci        resolveStartPromise = resolve;
871cb0ef41Sopenharmony_ci      });
881cb0ef41Sopenharmony_ci    },
891cb0ef41Sopenharmony_ci    pull() {
901cb0ef41Sopenharmony_ci      if (checkedNoPull) {
911cb0ef41Sopenharmony_ci        resolveTestPromise();
921cb0ef41Sopenharmony_ci      }
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci      ++pullCount;
951cb0ef41Sopenharmony_ci    },
961cb0ef41Sopenharmony_ci    type: 'bytes'
971cb0ef41Sopenharmony_ci  }, {
981cb0ef41Sopenharmony_ci    highWaterMark: 256
991cb0ef41Sopenharmony_ci  });
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci  Promise.resolve().then(() => {
1021cb0ef41Sopenharmony_ci    assert_equals(pullCount, 0);
1031cb0ef41Sopenharmony_ci    checkedNoPull = true;
1041cb0ef41Sopenharmony_ci    resolveStartPromise();
1051cb0ef41Sopenharmony_ci  });
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ci  return testPromise;
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: No automatic pull call if start doesn\'t finish');
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_citest(() => {
1121cb0ef41Sopenharmony_ci  assert_throws_js(Error, () => new ReadableStream({ start() { throw new Error(); }, type:'bytes' }),
1131cb0ef41Sopenharmony_ci      'start() can throw an exception with type: bytes');
1141cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: start() throws an exception');
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_cipromise_test(t => {
1171cb0ef41Sopenharmony_ci  new ReadableStream({
1181cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
1191cb0ef41Sopenharmony_ci    type: 'bytes'
1201cb0ef41Sopenharmony_ci  }, {
1211cb0ef41Sopenharmony_ci    highWaterMark: 0
1221cb0ef41Sopenharmony_ci  });
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci  return Promise.resolve();
1251cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Construct with highWaterMark of 0');
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_citest(() => {
1281cb0ef41Sopenharmony_ci  new ReadableStream({
1291cb0ef41Sopenharmony_ci    start(c) {
1301cb0ef41Sopenharmony_ci      assert_equals(c.desiredSize, 10, 'desiredSize must start at the highWaterMark');
1311cb0ef41Sopenharmony_ci      c.close();
1321cb0ef41Sopenharmony_ci      assert_equals(c.desiredSize, 0, 'after closing, desiredSize must be 0');
1331cb0ef41Sopenharmony_ci    },
1341cb0ef41Sopenharmony_ci    type: 'bytes'
1351cb0ef41Sopenharmony_ci  }, {
1361cb0ef41Sopenharmony_ci    highWaterMark: 10
1371cb0ef41Sopenharmony_ci  });
1381cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: desiredSize when closed');
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_citest(() => {
1411cb0ef41Sopenharmony_ci  new ReadableStream({
1421cb0ef41Sopenharmony_ci    start(c) {
1431cb0ef41Sopenharmony_ci      assert_equals(c.desiredSize, 10, 'desiredSize must start at the highWaterMark');
1441cb0ef41Sopenharmony_ci      c.error();
1451cb0ef41Sopenharmony_ci      assert_equals(c.desiredSize, null, 'after erroring, desiredSize must be null');
1461cb0ef41Sopenharmony_ci    },
1471cb0ef41Sopenharmony_ci    type: 'bytes'
1481cb0ef41Sopenharmony_ci  }, {
1491cb0ef41Sopenharmony_ci    highWaterMark: 10
1501cb0ef41Sopenharmony_ci  });
1511cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: desiredSize when errored');
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_cipromise_test(t => {
1541cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1551cb0ef41Sopenharmony_ci    type: 'bytes'
1561cb0ef41Sopenharmony_ci  });
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ci  const reader = stream.getReader();
1591cb0ef41Sopenharmony_ci  reader.releaseLock();
1601cb0ef41Sopenharmony_ci
1611cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError, reader.closed, 'closed must reject');
1621cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: getReader(), then releaseLock()');
1631cb0ef41Sopenharmony_ci
1641cb0ef41Sopenharmony_cipromise_test(t => {
1651cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1661cb0ef41Sopenharmony_ci    type: 'bytes'
1671cb0ef41Sopenharmony_ci  });
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
1701cb0ef41Sopenharmony_ci  reader.releaseLock();
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError, reader.closed, 'closed must reject');
1731cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: getReader() with mode set to byob, then releaseLock()');
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_cipromise_test(t => {
1761cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1771cb0ef41Sopenharmony_ci    start(c) {
1781cb0ef41Sopenharmony_ci      c.close();
1791cb0ef41Sopenharmony_ci    },
1801cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
1811cb0ef41Sopenharmony_ci    type: 'bytes'
1821cb0ef41Sopenharmony_ci  });
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci  const reader = stream.getReader();
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ci  return reader.closed.then(() => {
1871cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => stream.getReader(), 'getReader() must throw');
1881cb0ef41Sopenharmony_ci  });
1891cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Test that closing a stream does not release a reader automatically');
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_cipromise_test(t => {
1921cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1931cb0ef41Sopenharmony_ci    start(c) {
1941cb0ef41Sopenharmony_ci      c.close();
1951cb0ef41Sopenharmony_ci    },
1961cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
1971cb0ef41Sopenharmony_ci    type: 'bytes'
1981cb0ef41Sopenharmony_ci  });
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ci  return reader.closed.then(() => {
2031cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => stream.getReader({ mode: 'byob' }), 'getReader() must throw');
2041cb0ef41Sopenharmony_ci  });
2051cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Test that closing a stream does not release a BYOB reader automatically');
2061cb0ef41Sopenharmony_ci
2071cb0ef41Sopenharmony_cipromise_test(t => {
2081cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2091cb0ef41Sopenharmony_ci    start(c) {
2101cb0ef41Sopenharmony_ci      c.error(error1);
2111cb0ef41Sopenharmony_ci    },
2121cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
2131cb0ef41Sopenharmony_ci    type: 'bytes'
2141cb0ef41Sopenharmony_ci  });
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ci  const reader = stream.getReader();
2171cb0ef41Sopenharmony_ci
2181cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, error1, reader.closed, 'closed must reject').then(() => {
2191cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => stream.getReader(), 'getReader() must throw');
2201cb0ef41Sopenharmony_ci  });
2211cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Test that erroring a stream does not release a reader automatically');
2221cb0ef41Sopenharmony_ci
2231cb0ef41Sopenharmony_cipromise_test(t => {
2241cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2251cb0ef41Sopenharmony_ci    start(c) {
2261cb0ef41Sopenharmony_ci      c.error(error1);
2271cb0ef41Sopenharmony_ci    },
2281cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
2291cb0ef41Sopenharmony_ci    type: 'bytes'
2301cb0ef41Sopenharmony_ci  });
2311cb0ef41Sopenharmony_ci
2321cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, error1, reader.closed, 'closed must reject').then(() => {
2351cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => stream.getReader({ mode: 'byob' }), 'getReader() must throw');
2361cb0ef41Sopenharmony_ci  });
2371cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Test that erroring a stream does not release a BYOB reader automatically');
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_cipromise_test(async t => {
2401cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2411cb0ef41Sopenharmony_ci    type: 'bytes'
2421cb0ef41Sopenharmony_ci  });
2431cb0ef41Sopenharmony_ci
2441cb0ef41Sopenharmony_ci  const reader = stream.getReader();
2451cb0ef41Sopenharmony_ci  const read = reader.read();
2461cb0ef41Sopenharmony_ci  reader.releaseLock();
2471cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read, 'pending read must reject');
2481cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: releaseLock() on ReadableStreamDefaultReader must reject pending read()');
2491cb0ef41Sopenharmony_ci
2501cb0ef41Sopenharmony_cipromise_test(async t => {
2511cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2521cb0ef41Sopenharmony_ci    type: 'bytes'
2531cb0ef41Sopenharmony_ci  });
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
2561cb0ef41Sopenharmony_ci  const read = reader.read(new Uint8Array(1));
2571cb0ef41Sopenharmony_ci  reader.releaseLock();
2581cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read, 'pending read must reject');
2591cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: releaseLock() on ReadableStreamBYOBReader must reject pending read()');
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_cipromise_test(() => {
2621cb0ef41Sopenharmony_ci  let pullCount = 0;
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2651cb0ef41Sopenharmony_ci    pull() {
2661cb0ef41Sopenharmony_ci      ++pullCount;
2671cb0ef41Sopenharmony_ci    },
2681cb0ef41Sopenharmony_ci    type: 'bytes'
2691cb0ef41Sopenharmony_ci  }, {
2701cb0ef41Sopenharmony_ci    highWaterMark: 8
2711cb0ef41Sopenharmony_ci  });
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ci  stream.getReader();
2741cb0ef41Sopenharmony_ci
2751cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_ci  return Promise.resolve().then(() => {
2781cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull must be invoked');
2791cb0ef41Sopenharmony_ci  });
2801cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Automatic pull() after start()');
2811cb0ef41Sopenharmony_ci
2821cb0ef41Sopenharmony_cipromise_test(() => {
2831cb0ef41Sopenharmony_ci  let pullCount = 0;
2841cb0ef41Sopenharmony_ci
2851cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2861cb0ef41Sopenharmony_ci    pull() {
2871cb0ef41Sopenharmony_ci      ++pullCount;
2881cb0ef41Sopenharmony_ci    },
2891cb0ef41Sopenharmony_ci    type: 'bytes'
2901cb0ef41Sopenharmony_ci  }, {
2911cb0ef41Sopenharmony_ci    highWaterMark: 0
2921cb0ef41Sopenharmony_ci  });
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ci  const reader = stream.getReader();
2951cb0ef41Sopenharmony_ci  reader.read();
2961cb0ef41Sopenharmony_ci
2971cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');
2981cb0ef41Sopenharmony_ci
2991cb0ef41Sopenharmony_ci  return Promise.resolve().then(() => {
3001cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull must be invoked');
3011cb0ef41Sopenharmony_ci  });
3021cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Automatic pull() after start() and read()');
3031cb0ef41Sopenharmony_ci
3041cb0ef41Sopenharmony_ci// View buffers are detached after pull() returns, so record the information at the time that pull() was called.
3051cb0ef41Sopenharmony_cifunction extractViewInfo(view) {
3061cb0ef41Sopenharmony_ci  return {
3071cb0ef41Sopenharmony_ci    constructor: view.constructor,
3081cb0ef41Sopenharmony_ci    bufferByteLength: view.buffer.byteLength,
3091cb0ef41Sopenharmony_ci    byteOffset: view.byteOffset,
3101cb0ef41Sopenharmony_ci    byteLength: view.byteLength
3111cb0ef41Sopenharmony_ci  };
3121cb0ef41Sopenharmony_ci}
3131cb0ef41Sopenharmony_ci
3141cb0ef41Sopenharmony_cipromise_test(() => {
3151cb0ef41Sopenharmony_ci  let pullCount = 0;
3161cb0ef41Sopenharmony_ci  let controller;
3171cb0ef41Sopenharmony_ci  const byobRequests = [];
3181cb0ef41Sopenharmony_ci
3191cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
3201cb0ef41Sopenharmony_ci    start(c) {
3211cb0ef41Sopenharmony_ci      controller = c;
3221cb0ef41Sopenharmony_ci    },
3231cb0ef41Sopenharmony_ci    pull() {
3241cb0ef41Sopenharmony_ci      const byobRequest = controller.byobRequest;
3251cb0ef41Sopenharmony_ci      const view = byobRequest.view;
3261cb0ef41Sopenharmony_ci      byobRequests[pullCount] = {
3271cb0ef41Sopenharmony_ci        nonNull: byobRequest !== null,
3281cb0ef41Sopenharmony_ci        viewNonNull: view !== null,
3291cb0ef41Sopenharmony_ci        viewInfo: extractViewInfo(view)
3301cb0ef41Sopenharmony_ci      };
3311cb0ef41Sopenharmony_ci      if (pullCount === 0) {
3321cb0ef41Sopenharmony_ci        view[0] = 0x01;
3331cb0ef41Sopenharmony_ci        byobRequest.respond(1);
3341cb0ef41Sopenharmony_ci      } else if (pullCount === 1) {
3351cb0ef41Sopenharmony_ci        view[0] = 0x02;
3361cb0ef41Sopenharmony_ci        view[1] = 0x03;
3371cb0ef41Sopenharmony_ci        byobRequest.respond(2);
3381cb0ef41Sopenharmony_ci      }
3391cb0ef41Sopenharmony_ci
3401cb0ef41Sopenharmony_ci      ++pullCount;
3411cb0ef41Sopenharmony_ci    },
3421cb0ef41Sopenharmony_ci    type: 'bytes',
3431cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 16
3441cb0ef41Sopenharmony_ci  }, {
3451cb0ef41Sopenharmony_ci    highWaterMark: 0
3461cb0ef41Sopenharmony_ci  });
3471cb0ef41Sopenharmony_ci
3481cb0ef41Sopenharmony_ci  const reader = stream.getReader();
3491cb0ef41Sopenharmony_ci  const p0 = reader.read();
3501cb0ef41Sopenharmony_ci  const p1 = reader.read();
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'No pull() as start() just finished and is not yet reflected to the state of the stream');
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci  return Promise.resolve().then(() => {
3551cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull() must have been invoked once');
3561cb0ef41Sopenharmony_ci    const byobRequest = byobRequests[0];
3571cb0ef41Sopenharmony_ci    assert_true(byobRequest.nonNull, 'first byobRequest must not be null');
3581cb0ef41Sopenharmony_ci    assert_true(byobRequest.viewNonNull, 'first byobRequest.view must not be null');
3591cb0ef41Sopenharmony_ci    const viewInfo = byobRequest.viewInfo;
3601cb0ef41Sopenharmony_ci    assert_equals(viewInfo.constructor, Uint8Array, 'first view.constructor should be Uint8Array');
3611cb0ef41Sopenharmony_ci    assert_equals(viewInfo.bufferByteLength, 16, 'first view.buffer.byteLength should be 16');
3621cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteOffset, 0, 'first view.byteOffset should be 0');
3631cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteLength, 16, 'first view.byteLength should be 16');
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_ci    return p0;
3661cb0ef41Sopenharmony_ci  }).then(result => {
3671cb0ef41Sopenharmony_ci    assert_equals(pullCount, 2, 'pull() must have been invoked twice');
3681cb0ef41Sopenharmony_ci    const value = result.value;
3691cb0ef41Sopenharmony_ci    assert_not_equals(value, undefined, 'first read should have a value');
3701cb0ef41Sopenharmony_ci    assert_equals(value.constructor, Uint8Array, 'first value should be a Uint8Array');
3711cb0ef41Sopenharmony_ci    assert_equals(value.buffer.byteLength, 16, 'first value.buffer.byteLength should be 16');
3721cb0ef41Sopenharmony_ci    assert_equals(value.byteOffset, 0, 'first value.byteOffset should be 0');
3731cb0ef41Sopenharmony_ci    assert_equals(value.byteLength, 1, 'first value.byteLength should be 1');
3741cb0ef41Sopenharmony_ci    assert_equals(value[0], 0x01, 'first value[0] should be 0x01');
3751cb0ef41Sopenharmony_ci    const byobRequest = byobRequests[1];
3761cb0ef41Sopenharmony_ci    assert_true(byobRequest.nonNull, 'second byobRequest must not be null');
3771cb0ef41Sopenharmony_ci    assert_true(byobRequest.viewNonNull, 'second byobRequest.view must not be null');
3781cb0ef41Sopenharmony_ci    const viewInfo = byobRequest.viewInfo;
3791cb0ef41Sopenharmony_ci    assert_equals(viewInfo.constructor, Uint8Array, 'second view.constructor should be Uint8Array');
3801cb0ef41Sopenharmony_ci    assert_equals(viewInfo.bufferByteLength, 16, 'second view.buffer.byteLength should be 16');
3811cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteOffset, 0, 'second view.byteOffset should be 0');
3821cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteLength, 16, 'second view.byteLength should be 16');
3831cb0ef41Sopenharmony_ci
3841cb0ef41Sopenharmony_ci    return p1;
3851cb0ef41Sopenharmony_ci  }).then(result => {
3861cb0ef41Sopenharmony_ci    assert_equals(pullCount, 2, 'pull() should only be invoked twice');
3871cb0ef41Sopenharmony_ci    const value = result.value;
3881cb0ef41Sopenharmony_ci    assert_not_equals(value, undefined, 'second read should have a value');
3891cb0ef41Sopenharmony_ci    assert_equals(value.constructor, Uint8Array, 'second value should be a Uint8Array');
3901cb0ef41Sopenharmony_ci    assert_equals(value.buffer.byteLength, 16, 'second value.buffer.byteLength should be 16');
3911cb0ef41Sopenharmony_ci    assert_equals(value.byteOffset, 0, 'second value.byteOffset should be 0');
3921cb0ef41Sopenharmony_ci    assert_equals(value.byteLength, 2, 'second value.byteLength should be 2');
3931cb0ef41Sopenharmony_ci    assert_equals(value[0], 0x02, 'second value[0] should be 0x02');
3941cb0ef41Sopenharmony_ci    assert_equals(value[1], 0x03, 'second value[1] should be 0x03');
3951cb0ef41Sopenharmony_ci  });
3961cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: autoAllocateChunkSize');
3971cb0ef41Sopenharmony_ci
3981cb0ef41Sopenharmony_cipromise_test(() => {
3991cb0ef41Sopenharmony_ci  let pullCount = 0;
4001cb0ef41Sopenharmony_ci  let controller;
4011cb0ef41Sopenharmony_ci  const byobRequests = [];
4021cb0ef41Sopenharmony_ci
4031cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
4041cb0ef41Sopenharmony_ci    start(c) {
4051cb0ef41Sopenharmony_ci      controller = c;
4061cb0ef41Sopenharmony_ci    },
4071cb0ef41Sopenharmony_ci    pull() {
4081cb0ef41Sopenharmony_ci      const byobRequest = controller.byobRequest;
4091cb0ef41Sopenharmony_ci      const view = byobRequest.view;
4101cb0ef41Sopenharmony_ci      byobRequests[pullCount] = {
4111cb0ef41Sopenharmony_ci        nonNull: byobRequest !== null,
4121cb0ef41Sopenharmony_ci        viewNonNull: view !== null,
4131cb0ef41Sopenharmony_ci        viewInfo: extractViewInfo(view)
4141cb0ef41Sopenharmony_ci      };
4151cb0ef41Sopenharmony_ci      if (pullCount === 0) {
4161cb0ef41Sopenharmony_ci        view[0] = 0x01;
4171cb0ef41Sopenharmony_ci        byobRequest.respond(1);
4181cb0ef41Sopenharmony_ci      } else if (pullCount === 1) {
4191cb0ef41Sopenharmony_ci        view[0] = 0x02;
4201cb0ef41Sopenharmony_ci        view[1] = 0x03;
4211cb0ef41Sopenharmony_ci        byobRequest.respond(2);
4221cb0ef41Sopenharmony_ci      }
4231cb0ef41Sopenharmony_ci
4241cb0ef41Sopenharmony_ci      ++pullCount;
4251cb0ef41Sopenharmony_ci    },
4261cb0ef41Sopenharmony_ci    type: 'bytes',
4271cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 16
4281cb0ef41Sopenharmony_ci  }, {
4291cb0ef41Sopenharmony_ci    highWaterMark: 0
4301cb0ef41Sopenharmony_ci  });
4311cb0ef41Sopenharmony_ci
4321cb0ef41Sopenharmony_ci  const reader = stream.getReader();
4331cb0ef41Sopenharmony_ci  return reader.read().then(result => {
4341cb0ef41Sopenharmony_ci    const value = result.value;
4351cb0ef41Sopenharmony_ci    assert_not_equals(value, undefined, 'first read should have a value');
4361cb0ef41Sopenharmony_ci    assert_equals(value.constructor, Uint8Array, 'first value should be a Uint8Array');
4371cb0ef41Sopenharmony_ci    assert_equals(value.buffer.byteLength, 16, 'first value.buffer.byteLength should be 16');
4381cb0ef41Sopenharmony_ci    assert_equals(value.byteOffset, 0, 'first value.byteOffset should be 0');
4391cb0ef41Sopenharmony_ci    assert_equals(value.byteLength, 1, 'first value.byteLength should be 1');
4401cb0ef41Sopenharmony_ci    assert_equals(value[0], 0x01, 'first value[0] should be 0x01');
4411cb0ef41Sopenharmony_ci    const byobRequest = byobRequests[0];
4421cb0ef41Sopenharmony_ci    assert_true(byobRequest.nonNull, 'first byobRequest must not be null');
4431cb0ef41Sopenharmony_ci    assert_true(byobRequest.viewNonNull, 'first byobRequest.view must not be null');
4441cb0ef41Sopenharmony_ci    const viewInfo = byobRequest.viewInfo;
4451cb0ef41Sopenharmony_ci    assert_equals(viewInfo.constructor, Uint8Array, 'first view.constructor should be Uint8Array');
4461cb0ef41Sopenharmony_ci    assert_equals(viewInfo.bufferByteLength, 16, 'first view.buffer.byteLength should be 16');
4471cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteOffset, 0, 'first view.byteOffset should be 0');
4481cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteLength, 16, 'first view.byteLength should be 16');
4491cb0ef41Sopenharmony_ci
4501cb0ef41Sopenharmony_ci    reader.releaseLock();
4511cb0ef41Sopenharmony_ci    const byobReader = stream.getReader({ mode: 'byob' });
4521cb0ef41Sopenharmony_ci    return byobReader.read(new Uint8Array(32));
4531cb0ef41Sopenharmony_ci  }).then(result => {
4541cb0ef41Sopenharmony_ci    const value = result.value;
4551cb0ef41Sopenharmony_ci    assert_not_equals(value, undefined, 'second read should have a value');
4561cb0ef41Sopenharmony_ci    assert_equals(value.constructor, Uint8Array, 'second value should be a Uint8Array');
4571cb0ef41Sopenharmony_ci    assert_equals(value.buffer.byteLength, 32, 'second value.buffer.byteLength should be 32');
4581cb0ef41Sopenharmony_ci    assert_equals(value.byteOffset, 0, 'second value.byteOffset should be 0');
4591cb0ef41Sopenharmony_ci    assert_equals(value.byteLength, 2, 'second value.byteLength should be 2');
4601cb0ef41Sopenharmony_ci    assert_equals(value[0], 0x02, 'second value[0] should be 0x02');
4611cb0ef41Sopenharmony_ci    assert_equals(value[1], 0x03, 'second value[1] should be 0x03');
4621cb0ef41Sopenharmony_ci    const byobRequest = byobRequests[1];
4631cb0ef41Sopenharmony_ci    assert_true(byobRequest.nonNull, 'second byobRequest must not be null');
4641cb0ef41Sopenharmony_ci    assert_true(byobRequest.viewNonNull, 'second byobRequest.view must not be null');
4651cb0ef41Sopenharmony_ci    const viewInfo = byobRequest.viewInfo;
4661cb0ef41Sopenharmony_ci    assert_equals(viewInfo.constructor, Uint8Array, 'second view.constructor should be Uint8Array');
4671cb0ef41Sopenharmony_ci    assert_equals(viewInfo.bufferByteLength, 32, 'second view.buffer.byteLength should be 32');
4681cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteOffset, 0, 'second view.byteOffset should be 0');
4691cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteLength, 32, 'second view.byteLength should be 32');
4701cb0ef41Sopenharmony_ci    assert_equals(pullCount, 2, 'pullCount should be 2');
4711cb0ef41Sopenharmony_ci  });
4721cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Mix of auto allocate and BYOB');
4731cb0ef41Sopenharmony_ci
4741cb0ef41Sopenharmony_cipromise_test(() => {
4751cb0ef41Sopenharmony_ci  let pullCount = 0;
4761cb0ef41Sopenharmony_ci
4771cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
4781cb0ef41Sopenharmony_ci    pull() {
4791cb0ef41Sopenharmony_ci      ++pullCount;
4801cb0ef41Sopenharmony_ci    },
4811cb0ef41Sopenharmony_ci    type: 'bytes'
4821cb0ef41Sopenharmony_ci  }, {
4831cb0ef41Sopenharmony_ci    highWaterMark: 0
4841cb0ef41Sopenharmony_ci  });
4851cb0ef41Sopenharmony_ci
4861cb0ef41Sopenharmony_ci  const reader = stream.getReader();
4871cb0ef41Sopenharmony_ci  reader.read(new Uint8Array(8));
4881cb0ef41Sopenharmony_ci
4891cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');
4901cb0ef41Sopenharmony_ci
4911cb0ef41Sopenharmony_ci  return Promise.resolve().then(() => {
4921cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull must be invoked');
4931cb0ef41Sopenharmony_ci  });
4941cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Automatic pull() after start() and read(view)');
4951cb0ef41Sopenharmony_ci
4961cb0ef41Sopenharmony_cipromise_test(() => {
4971cb0ef41Sopenharmony_ci  let pullCount = 0;
4981cb0ef41Sopenharmony_ci
4991cb0ef41Sopenharmony_ci  let controller;
5001cb0ef41Sopenharmony_ci  let desiredSizeInStart;
5011cb0ef41Sopenharmony_ci  let desiredSizeInPull;
5021cb0ef41Sopenharmony_ci
5031cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
5041cb0ef41Sopenharmony_ci    start(c) {
5051cb0ef41Sopenharmony_ci      c.enqueue(new Uint8Array(16));
5061cb0ef41Sopenharmony_ci      desiredSizeInStart = c.desiredSize;
5071cb0ef41Sopenharmony_ci      controller = c;
5081cb0ef41Sopenharmony_ci    },
5091cb0ef41Sopenharmony_ci    pull() {
5101cb0ef41Sopenharmony_ci      ++pullCount;
5111cb0ef41Sopenharmony_ci
5121cb0ef41Sopenharmony_ci      if (pullCount === 1) {
5131cb0ef41Sopenharmony_ci        desiredSizeInPull = controller.desiredSize;
5141cb0ef41Sopenharmony_ci      }
5151cb0ef41Sopenharmony_ci    },
5161cb0ef41Sopenharmony_ci    type: 'bytes'
5171cb0ef41Sopenharmony_ci  }, {
5181cb0ef41Sopenharmony_ci    highWaterMark: 8
5191cb0ef41Sopenharmony_ci  });
5201cb0ef41Sopenharmony_ci
5211cb0ef41Sopenharmony_ci  return Promise.resolve().then(() => {
5221cb0ef41Sopenharmony_ci    assert_equals(pullCount, 0, 'No pull as the queue was filled by start()');
5231cb0ef41Sopenharmony_ci    assert_equals(desiredSizeInStart, -8, 'desiredSize after enqueue() in start()');
5241cb0ef41Sopenharmony_ci
5251cb0ef41Sopenharmony_ci    const reader = stream.getReader();
5261cb0ef41Sopenharmony_ci
5271cb0ef41Sopenharmony_ci    const promise = reader.read();
5281cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'The first pull() should be made on read()');
5291cb0ef41Sopenharmony_ci    assert_equals(desiredSizeInPull, 8, 'desiredSize in pull()');
5301cb0ef41Sopenharmony_ci
5311cb0ef41Sopenharmony_ci    return promise.then(result => {
5321cb0ef41Sopenharmony_ci      assert_false(result.done, 'result.done');
5331cb0ef41Sopenharmony_ci
5341cb0ef41Sopenharmony_ci      const view = result.value;
5351cb0ef41Sopenharmony_ci      assert_equals(view.constructor, Uint8Array, 'view.constructor');
5361cb0ef41Sopenharmony_ci      assert_equals(view.buffer.byteLength, 16, 'view.buffer');
5371cb0ef41Sopenharmony_ci      assert_equals(view.byteOffset, 0, 'view.byteOffset');
5381cb0ef41Sopenharmony_ci      assert_equals(view.byteLength, 16, 'view.byteLength');
5391cb0ef41Sopenharmony_ci    });
5401cb0ef41Sopenharmony_ci  });
5411cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), getReader(), then read()');
5421cb0ef41Sopenharmony_ci
5431cb0ef41Sopenharmony_cipromise_test(() => {
5441cb0ef41Sopenharmony_ci  let controller;
5451cb0ef41Sopenharmony_ci
5461cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
5471cb0ef41Sopenharmony_ci    start(c) {
5481cb0ef41Sopenharmony_ci      controller = c;
5491cb0ef41Sopenharmony_ci    },
5501cb0ef41Sopenharmony_ci    type: 'bytes'
5511cb0ef41Sopenharmony_ci  });
5521cb0ef41Sopenharmony_ci
5531cb0ef41Sopenharmony_ci  const reader = stream.getReader();
5541cb0ef41Sopenharmony_ci
5551cb0ef41Sopenharmony_ci  const promise = reader.read().then(result => {
5561cb0ef41Sopenharmony_ci    assert_false(result.done);
5571cb0ef41Sopenharmony_ci
5581cb0ef41Sopenharmony_ci    const view = result.value;
5591cb0ef41Sopenharmony_ci    assert_equals(view.constructor, Uint8Array);
5601cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 1);
5611cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
5621cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 1);
5631cb0ef41Sopenharmony_ci  });
5641cb0ef41Sopenharmony_ci
5651cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array(1));
5661cb0ef41Sopenharmony_ci
5671cb0ef41Sopenharmony_ci  return promise;
5681cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Push source that doesn\'t understand pull signal');
5691cb0ef41Sopenharmony_ci
5701cb0ef41Sopenharmony_citest(() => {
5711cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => new ReadableStream({
5721cb0ef41Sopenharmony_ci    pull: 'foo',
5731cb0ef41Sopenharmony_ci    type: 'bytes'
5741cb0ef41Sopenharmony_ci  }), 'constructor should throw');
5751cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: pull() function is not callable');
5761cb0ef41Sopenharmony_ci
5771cb0ef41Sopenharmony_cipromise_test(() => {
5781cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
5791cb0ef41Sopenharmony_ci    start(c) {
5801cb0ef41Sopenharmony_ci      c.enqueue(new Uint16Array(16));
5811cb0ef41Sopenharmony_ci    },
5821cb0ef41Sopenharmony_ci    type: 'bytes'
5831cb0ef41Sopenharmony_ci  });
5841cb0ef41Sopenharmony_ci
5851cb0ef41Sopenharmony_ci  const reader = stream.getReader();
5861cb0ef41Sopenharmony_ci
5871cb0ef41Sopenharmony_ci  return reader.read().then(result => {
5881cb0ef41Sopenharmony_ci    assert_false(result.done);
5891cb0ef41Sopenharmony_ci
5901cb0ef41Sopenharmony_ci    const view = result.value;
5911cb0ef41Sopenharmony_ci    assert_equals(view.constructor, Uint8Array);
5921cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 32);
5931cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
5941cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 32);
5951cb0ef41Sopenharmony_ci  });
5961cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue() with Uint16Array, getReader(), then read()');
5971cb0ef41Sopenharmony_ci
5981cb0ef41Sopenharmony_cipromise_test(t => {
5991cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
6001cb0ef41Sopenharmony_ci    start(c) {
6011cb0ef41Sopenharmony_ci      const view = new Uint8Array(16);
6021cb0ef41Sopenharmony_ci      view[0] = 0x01;
6031cb0ef41Sopenharmony_ci      view[8] = 0x02;
6041cb0ef41Sopenharmony_ci      c.enqueue(view);
6051cb0ef41Sopenharmony_ci    },
6061cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
6071cb0ef41Sopenharmony_ci    type: 'bytes'
6081cb0ef41Sopenharmony_ci  });
6091cb0ef41Sopenharmony_ci
6101cb0ef41Sopenharmony_ci  const byobReader = stream.getReader({ mode: 'byob' });
6111cb0ef41Sopenharmony_ci
6121cb0ef41Sopenharmony_ci  return byobReader.read(new Uint8Array(8)).then(result => {
6131cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
6141cb0ef41Sopenharmony_ci
6151cb0ef41Sopenharmony_ci    const view = result.value;
6161cb0ef41Sopenharmony_ci    assert_equals(view.constructor, Uint8Array, 'value.constructor');
6171cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 8, 'value.buffer.byteLength');
6181cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, 'value.byteOffset');
6191cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 8, 'value.byteLength');
6201cb0ef41Sopenharmony_ci    assert_equals(view[0], 0x01);
6211cb0ef41Sopenharmony_ci
6221cb0ef41Sopenharmony_ci    byobReader.releaseLock();
6231cb0ef41Sopenharmony_ci
6241cb0ef41Sopenharmony_ci    const reader = stream.getReader();
6251cb0ef41Sopenharmony_ci
6261cb0ef41Sopenharmony_ci    return reader.read();
6271cb0ef41Sopenharmony_ci  }).then(result => {
6281cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
6291cb0ef41Sopenharmony_ci
6301cb0ef41Sopenharmony_ci    const view = result.value;
6311cb0ef41Sopenharmony_ci    assert_equals(view.constructor, Uint8Array, 'value.constructor');
6321cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 16, 'value.buffer.byteLength');
6331cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 8, 'value.byteOffset');
6341cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 8, 'value.byteLength');
6351cb0ef41Sopenharmony_ci    assert_equals(view[0], 0x02);
6361cb0ef41Sopenharmony_ci  });
6371cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), read(view) partially, then read()');
6381cb0ef41Sopenharmony_ci
6391cb0ef41Sopenharmony_cipromise_test(t => {
6401cb0ef41Sopenharmony_ci  let controller;
6411cb0ef41Sopenharmony_ci
6421cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
6431cb0ef41Sopenharmony_ci    start(c) {
6441cb0ef41Sopenharmony_ci      controller = c;
6451cb0ef41Sopenharmony_ci    },
6461cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
6471cb0ef41Sopenharmony_ci    type: 'bytes'
6481cb0ef41Sopenharmony_ci  });
6491cb0ef41Sopenharmony_ci
6501cb0ef41Sopenharmony_ci  const reader = stream.getReader();
6511cb0ef41Sopenharmony_ci
6521cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array(16));
6531cb0ef41Sopenharmony_ci  controller.close();
6541cb0ef41Sopenharmony_ci
6551cb0ef41Sopenharmony_ci  return reader.read().then(result => {
6561cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
6571cb0ef41Sopenharmony_ci
6581cb0ef41Sopenharmony_ci    const view = result.value;
6591cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, 'byteOffset');
6601cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 16, 'byteLength');
6611cb0ef41Sopenharmony_ci
6621cb0ef41Sopenharmony_ci    return reader.read();
6631cb0ef41Sopenharmony_ci  }).then(result => {
6641cb0ef41Sopenharmony_ci    assert_true(result.done, 'done');
6651cb0ef41Sopenharmony_ci    assert_equals(result.value, undefined, 'value');
6661cb0ef41Sopenharmony_ci  });
6671cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: getReader(), enqueue(), close(), then read()');
6681cb0ef41Sopenharmony_ci
6691cb0ef41Sopenharmony_cipromise_test(t => {
6701cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
6711cb0ef41Sopenharmony_ci    start(c) {
6721cb0ef41Sopenharmony_ci      c.enqueue(new Uint8Array(16));
6731cb0ef41Sopenharmony_ci      c.close();
6741cb0ef41Sopenharmony_ci    },
6751cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
6761cb0ef41Sopenharmony_ci    type: 'bytes'
6771cb0ef41Sopenharmony_ci  });
6781cb0ef41Sopenharmony_ci
6791cb0ef41Sopenharmony_ci  const reader = stream.getReader();
6801cb0ef41Sopenharmony_ci
6811cb0ef41Sopenharmony_ci  return reader.read().then(result => {
6821cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
6831cb0ef41Sopenharmony_ci
6841cb0ef41Sopenharmony_ci    const view = result.value;
6851cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, 'byteOffset');
6861cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 16, 'byteLength');
6871cb0ef41Sopenharmony_ci
6881cb0ef41Sopenharmony_ci    return reader.read();
6891cb0ef41Sopenharmony_ci  }).then(result => {
6901cb0ef41Sopenharmony_ci    assert_true(result.done, 'done');
6911cb0ef41Sopenharmony_ci    assert_equals(result.value, undefined, 'value');
6921cb0ef41Sopenharmony_ci  });
6931cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), close(), getReader(), then read()');
6941cb0ef41Sopenharmony_ci
6951cb0ef41Sopenharmony_cipromise_test(() => {
6961cb0ef41Sopenharmony_ci  let controller;
6971cb0ef41Sopenharmony_ci  let byobRequest;
6981cb0ef41Sopenharmony_ci
6991cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
7001cb0ef41Sopenharmony_ci    start(c) {
7011cb0ef41Sopenharmony_ci      controller = c;
7021cb0ef41Sopenharmony_ci    },
7031cb0ef41Sopenharmony_ci    pull() {
7041cb0ef41Sopenharmony_ci      controller.enqueue(new Uint8Array(16));
7051cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
7061cb0ef41Sopenharmony_ci    },
7071cb0ef41Sopenharmony_ci    type: 'bytes'
7081cb0ef41Sopenharmony_ci  });
7091cb0ef41Sopenharmony_ci
7101cb0ef41Sopenharmony_ci  const reader = stream.getReader();
7111cb0ef41Sopenharmony_ci
7121cb0ef41Sopenharmony_ci  return reader.read().then(result => {
7131cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
7141cb0ef41Sopenharmony_ci    assert_equals(result.value.byteLength, 16, 'byteLength');
7151cb0ef41Sopenharmony_ci    assert_equals(byobRequest, null, 'byobRequest must be null');
7161cb0ef41Sopenharmony_ci  });
7171cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Respond to pull() by enqueue()');
7181cb0ef41Sopenharmony_ci
7191cb0ef41Sopenharmony_cipromise_test(() => {
7201cb0ef41Sopenharmony_ci  let pullCount = 0;
7211cb0ef41Sopenharmony_ci
7221cb0ef41Sopenharmony_ci  let controller;
7231cb0ef41Sopenharmony_ci  let byobRequest;
7241cb0ef41Sopenharmony_ci  const desiredSizes = [];
7251cb0ef41Sopenharmony_ci
7261cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
7271cb0ef41Sopenharmony_ci    start(c) {
7281cb0ef41Sopenharmony_ci      controller = c;
7291cb0ef41Sopenharmony_ci    },
7301cb0ef41Sopenharmony_ci    pull() {
7311cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
7321cb0ef41Sopenharmony_ci      desiredSizes.push(controller.desiredSize);
7331cb0ef41Sopenharmony_ci      controller.enqueue(new Uint8Array(1));
7341cb0ef41Sopenharmony_ci      desiredSizes.push(controller.desiredSize);
7351cb0ef41Sopenharmony_ci      controller.enqueue(new Uint8Array(1));
7361cb0ef41Sopenharmony_ci      desiredSizes.push(controller.desiredSize);
7371cb0ef41Sopenharmony_ci
7381cb0ef41Sopenharmony_ci      ++pullCount;
7391cb0ef41Sopenharmony_ci    },
7401cb0ef41Sopenharmony_ci    type: 'bytes'
7411cb0ef41Sopenharmony_ci  }, {
7421cb0ef41Sopenharmony_ci    highWaterMark: 0
7431cb0ef41Sopenharmony_ci  });
7441cb0ef41Sopenharmony_ci
7451cb0ef41Sopenharmony_ci  const reader = stream.getReader();
7461cb0ef41Sopenharmony_ci
7471cb0ef41Sopenharmony_ci  const p0 = reader.read();
7481cb0ef41Sopenharmony_ci  const p1 = reader.read();
7491cb0ef41Sopenharmony_ci  const p2 = reader.read();
7501cb0ef41Sopenharmony_ci
7511cb0ef41Sopenharmony_ci  // Respond to the first pull call.
7521cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array(1));
7531cb0ef41Sopenharmony_ci
7541cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'pullCount after the enqueue() outside pull');
7551cb0ef41Sopenharmony_ci
7561cb0ef41Sopenharmony_ci  return Promise.all([p0, p1, p2]).then(result => {
7571cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pullCount after completion of all read()s');
7581cb0ef41Sopenharmony_ci
7591cb0ef41Sopenharmony_ci    assert_equals(result[0].done, false, 'result[0].done');
7601cb0ef41Sopenharmony_ci    assert_equals(result[0].value.byteLength, 1, 'result[0].value.byteLength');
7611cb0ef41Sopenharmony_ci    assert_equals(result[1].done, false, 'result[1].done');
7621cb0ef41Sopenharmony_ci    assert_equals(result[1].value.byteLength, 1, 'result[1].value.byteLength');
7631cb0ef41Sopenharmony_ci    assert_equals(result[2].done, false, 'result[2].done');
7641cb0ef41Sopenharmony_ci    assert_equals(result[2].value.byteLength, 1, 'result[2].value.byteLength');
7651cb0ef41Sopenharmony_ci    assert_equals(byobRequest, null, 'byobRequest should be null');
7661cb0ef41Sopenharmony_ci    assert_equals(desiredSizes[0], 0, 'desiredSize on pull should be 0');
7671cb0ef41Sopenharmony_ci    assert_equals(desiredSizes[1], 0, 'desiredSize after 1st enqueue() should be 0');
7681cb0ef41Sopenharmony_ci    assert_equals(desiredSizes[2], 0, 'desiredSize after 2nd enqueue() should be 0');
7691cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull() should only be called once');
7701cb0ef41Sopenharmony_ci  });
7711cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Respond to pull() by enqueue() asynchronously');
7721cb0ef41Sopenharmony_ci
7731cb0ef41Sopenharmony_cipromise_test(() => {
7741cb0ef41Sopenharmony_ci  let pullCount = 0;
7751cb0ef41Sopenharmony_ci
7761cb0ef41Sopenharmony_ci  let byobRequest;
7771cb0ef41Sopenharmony_ci  const desiredSizes = [];
7781cb0ef41Sopenharmony_ci
7791cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
7801cb0ef41Sopenharmony_ci    pull(c) {
7811cb0ef41Sopenharmony_ci      byobRequest = c.byobRequest;
7821cb0ef41Sopenharmony_ci      desiredSizes.push(c.desiredSize);
7831cb0ef41Sopenharmony_ci
7841cb0ef41Sopenharmony_ci      if (pullCount < 3) {
7851cb0ef41Sopenharmony_ci        c.enqueue(new Uint8Array(1));
7861cb0ef41Sopenharmony_ci      } else {
7871cb0ef41Sopenharmony_ci        c.close();
7881cb0ef41Sopenharmony_ci      }
7891cb0ef41Sopenharmony_ci
7901cb0ef41Sopenharmony_ci      ++pullCount;
7911cb0ef41Sopenharmony_ci    },
7921cb0ef41Sopenharmony_ci    type: 'bytes'
7931cb0ef41Sopenharmony_ci  }, {
7941cb0ef41Sopenharmony_ci    highWaterMark: 256
7951cb0ef41Sopenharmony_ci  });
7961cb0ef41Sopenharmony_ci
7971cb0ef41Sopenharmony_ci  const reader = stream.getReader();
7981cb0ef41Sopenharmony_ci
7991cb0ef41Sopenharmony_ci  const p0 = reader.read();
8001cb0ef41Sopenharmony_ci  const p1 = reader.read();
8011cb0ef41Sopenharmony_ci  const p2 = reader.read();
8021cb0ef41Sopenharmony_ci
8031cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');
8041cb0ef41Sopenharmony_ci
8051cb0ef41Sopenharmony_ci  return Promise.all([p0, p1, p2]).then(result => {
8061cb0ef41Sopenharmony_ci    assert_equals(pullCount, 4, 'pullCount after completion of all read()s');
8071cb0ef41Sopenharmony_ci
8081cb0ef41Sopenharmony_ci    assert_equals(result[0].done, false, 'result[0].done');
8091cb0ef41Sopenharmony_ci    assert_equals(result[0].value.byteLength, 1, 'result[0].value.byteLength');
8101cb0ef41Sopenharmony_ci    assert_equals(result[1].done, false, 'result[1].done');
8111cb0ef41Sopenharmony_ci    assert_equals(result[1].value.byteLength, 1, 'result[1].value.byteLength');
8121cb0ef41Sopenharmony_ci    assert_equals(result[2].done, false, 'result[2].done');
8131cb0ef41Sopenharmony_ci    assert_equals(result[2].value.byteLength, 1, 'result[2].value.byteLength');
8141cb0ef41Sopenharmony_ci    assert_equals(byobRequest, null, 'byobRequest should be null');
8151cb0ef41Sopenharmony_ci    assert_equals(desiredSizes[0], 256, 'desiredSize on pull should be 256');
8161cb0ef41Sopenharmony_ci    assert_equals(desiredSizes[1], 256, 'desiredSize after 1st enqueue() should be 256');
8171cb0ef41Sopenharmony_ci    assert_equals(desiredSizes[2], 256, 'desiredSize after 2nd enqueue() should be 256');
8181cb0ef41Sopenharmony_ci    assert_equals(desiredSizes[3], 256, 'desiredSize after 3rd enqueue() should be 256');
8191cb0ef41Sopenharmony_ci  });
8201cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Respond to multiple pull() by separate enqueue()');
8211cb0ef41Sopenharmony_ci
8221cb0ef41Sopenharmony_cipromise_test(() => {
8231cb0ef41Sopenharmony_ci  let controller;
8241cb0ef41Sopenharmony_ci
8251cb0ef41Sopenharmony_ci  let pullCount = 0;
8261cb0ef41Sopenharmony_ci  const byobRequestDefined = [];
8271cb0ef41Sopenharmony_ci  let byobRequestViewDefined;
8281cb0ef41Sopenharmony_ci
8291cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
8301cb0ef41Sopenharmony_ci    start(c) {
8311cb0ef41Sopenharmony_ci      controller = c;
8321cb0ef41Sopenharmony_ci    },
8331cb0ef41Sopenharmony_ci    pull() {
8341cb0ef41Sopenharmony_ci      byobRequestDefined.push(controller.byobRequest !== null);
8351cb0ef41Sopenharmony_ci      const initialByobRequest = controller.byobRequest;
8361cb0ef41Sopenharmony_ci
8371cb0ef41Sopenharmony_ci      const view = controller.byobRequest.view;
8381cb0ef41Sopenharmony_ci      view[0] = 0x01;
8391cb0ef41Sopenharmony_ci      controller.byobRequest.respond(1);
8401cb0ef41Sopenharmony_ci
8411cb0ef41Sopenharmony_ci      byobRequestDefined.push(controller.byobRequest !== null);
8421cb0ef41Sopenharmony_ci      byobRequestViewDefined = initialByobRequest.view !== null;
8431cb0ef41Sopenharmony_ci
8441cb0ef41Sopenharmony_ci      ++pullCount;
8451cb0ef41Sopenharmony_ci    },
8461cb0ef41Sopenharmony_ci    type: 'bytes'
8471cb0ef41Sopenharmony_ci  });
8481cb0ef41Sopenharmony_ci
8491cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
8501cb0ef41Sopenharmony_ci
8511cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(1)).then(result => {
8521cb0ef41Sopenharmony_ci    assert_false(result.done, 'result.done');
8531cb0ef41Sopenharmony_ci    assert_equals(result.value.byteLength, 1, 'result.value.byteLength');
8541cb0ef41Sopenharmony_ci    assert_equals(result.value[0], 0x01, 'result.value[0]');
8551cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull() should be called only once');
8561cb0ef41Sopenharmony_ci    assert_true(byobRequestDefined[0], 'byobRequest must not be null before respond()');
8571cb0ef41Sopenharmony_ci    assert_false(byobRequestDefined[1], 'byobRequest must be null after respond()');
8581cb0ef41Sopenharmony_ci    assert_false(byobRequestViewDefined, 'view of initial byobRequest must be null after respond()');
8591cb0ef41Sopenharmony_ci  });
8601cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view), then respond()');
8611cb0ef41Sopenharmony_ci
8621cb0ef41Sopenharmony_cipromise_test(() => {
8631cb0ef41Sopenharmony_ci  let controller;
8641cb0ef41Sopenharmony_ci
8651cb0ef41Sopenharmony_ci  let pullCount = 0;
8661cb0ef41Sopenharmony_ci  const byobRequestDefined = [];
8671cb0ef41Sopenharmony_ci  let byobRequestViewDefined;
8681cb0ef41Sopenharmony_ci
8691cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
8701cb0ef41Sopenharmony_ci    start(c) {
8711cb0ef41Sopenharmony_ci      controller = c;
8721cb0ef41Sopenharmony_ci    },
8731cb0ef41Sopenharmony_ci    async pull() {
8741cb0ef41Sopenharmony_ci      byobRequestDefined.push(controller.byobRequest !== null);
8751cb0ef41Sopenharmony_ci      const initialByobRequest = controller.byobRequest;
8761cb0ef41Sopenharmony_ci
8771cb0ef41Sopenharmony_ci      const transferredView = await transferArrayBufferView(controller.byobRequest.view);
8781cb0ef41Sopenharmony_ci      transferredView[0] = 0x01;
8791cb0ef41Sopenharmony_ci      controller.byobRequest.respondWithNewView(transferredView);
8801cb0ef41Sopenharmony_ci
8811cb0ef41Sopenharmony_ci      byobRequestDefined.push(controller.byobRequest !== null);
8821cb0ef41Sopenharmony_ci      byobRequestViewDefined = initialByobRequest.view !== null;
8831cb0ef41Sopenharmony_ci
8841cb0ef41Sopenharmony_ci      ++pullCount;
8851cb0ef41Sopenharmony_ci    },
8861cb0ef41Sopenharmony_ci    type: 'bytes'
8871cb0ef41Sopenharmony_ci  });
8881cb0ef41Sopenharmony_ci
8891cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
8901cb0ef41Sopenharmony_ci
8911cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(1)).then(result => {
8921cb0ef41Sopenharmony_ci    assert_false(result.done, 'result.done');
8931cb0ef41Sopenharmony_ci    assert_equals(result.value.byteLength, 1, 'result.value.byteLength');
8941cb0ef41Sopenharmony_ci    assert_equals(result.value[0], 0x01, 'result.value[0]');
8951cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull() should be called only once');
8961cb0ef41Sopenharmony_ci    assert_true(byobRequestDefined[0], 'byobRequest must not be null before respondWithNewView()');
8971cb0ef41Sopenharmony_ci    assert_false(byobRequestDefined[1], 'byobRequest must be null after respondWithNewView()');
8981cb0ef41Sopenharmony_ci    assert_false(byobRequestViewDefined, 'view of initial byobRequest must be null after respondWithNewView()');
8991cb0ef41Sopenharmony_ci  });
9001cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view), then respondWithNewView() with a transferred ArrayBuffer');
9011cb0ef41Sopenharmony_ci
9021cb0ef41Sopenharmony_cipromise_test(() => {
9031cb0ef41Sopenharmony_ci  let controller;
9041cb0ef41Sopenharmony_ci  let byobRequestWasDefined;
9051cb0ef41Sopenharmony_ci  let incorrectRespondException;
9061cb0ef41Sopenharmony_ci
9071cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
9081cb0ef41Sopenharmony_ci    start(c) {
9091cb0ef41Sopenharmony_ci      controller = c;
9101cb0ef41Sopenharmony_ci    },
9111cb0ef41Sopenharmony_ci    pull() {
9121cb0ef41Sopenharmony_ci      byobRequestWasDefined = controller.byobRequest !== null;
9131cb0ef41Sopenharmony_ci
9141cb0ef41Sopenharmony_ci      try {
9151cb0ef41Sopenharmony_ci        controller.byobRequest.respond(2);
9161cb0ef41Sopenharmony_ci      } catch (e) {
9171cb0ef41Sopenharmony_ci        incorrectRespondException = e;
9181cb0ef41Sopenharmony_ci      }
9191cb0ef41Sopenharmony_ci
9201cb0ef41Sopenharmony_ci      controller.byobRequest.respond(1);
9211cb0ef41Sopenharmony_ci    },
9221cb0ef41Sopenharmony_ci    type: 'bytes'
9231cb0ef41Sopenharmony_ci  });
9241cb0ef41Sopenharmony_ci
9251cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
9261cb0ef41Sopenharmony_ci
9271cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(1)).then(() => {
9281cb0ef41Sopenharmony_ci    assert_true(byobRequestWasDefined, 'byobRequest should be non-null');
9291cb0ef41Sopenharmony_ci    assert_not_equals(incorrectRespondException, undefined, 'respond() must throw');
9301cb0ef41Sopenharmony_ci    assert_equals(incorrectRespondException.name, 'RangeError', 'respond() must throw a RangeError');
9311cb0ef41Sopenharmony_ci  });
9321cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view), then respond() with too big value');
9331cb0ef41Sopenharmony_ci
9341cb0ef41Sopenharmony_cipromise_test(() => {
9351cb0ef41Sopenharmony_ci  let pullCount = 0;
9361cb0ef41Sopenharmony_ci
9371cb0ef41Sopenharmony_ci  let controller;
9381cb0ef41Sopenharmony_ci  let byobRequest;
9391cb0ef41Sopenharmony_ci  let viewInfo;
9401cb0ef41Sopenharmony_ci
9411cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
9421cb0ef41Sopenharmony_ci    start(c) {
9431cb0ef41Sopenharmony_ci      controller = c;
9441cb0ef41Sopenharmony_ci    },
9451cb0ef41Sopenharmony_ci    pull() {
9461cb0ef41Sopenharmony_ci      ++pullCount;
9471cb0ef41Sopenharmony_ci
9481cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
9491cb0ef41Sopenharmony_ci      const view = byobRequest.view;
9501cb0ef41Sopenharmony_ci      viewInfo = extractViewInfo(view);
9511cb0ef41Sopenharmony_ci
9521cb0ef41Sopenharmony_ci      view[0] = 0x01;
9531cb0ef41Sopenharmony_ci      view[1] = 0x02;
9541cb0ef41Sopenharmony_ci      view[2] = 0x03;
9551cb0ef41Sopenharmony_ci
9561cb0ef41Sopenharmony_ci      controller.byobRequest.respond(3);
9571cb0ef41Sopenharmony_ci    },
9581cb0ef41Sopenharmony_ci    type: 'bytes'
9591cb0ef41Sopenharmony_ci  });
9601cb0ef41Sopenharmony_ci
9611cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
9621cb0ef41Sopenharmony_ci
9631cb0ef41Sopenharmony_ci  return reader.read(new Uint16Array(2)).then(result => {
9641cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1);
9651cb0ef41Sopenharmony_ci
9661cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
9671cb0ef41Sopenharmony_ci
9681cb0ef41Sopenharmony_ci    const view = result.value;
9691cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, 'byteOffset');
9701cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 2, 'byteLength');
9711cb0ef41Sopenharmony_ci
9721cb0ef41Sopenharmony_ci    const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);
9731cb0ef41Sopenharmony_ci    assert_equals(dataView.getUint16(0), 0x0102);
9741cb0ef41Sopenharmony_ci
9751cb0ef41Sopenharmony_ci    return reader.read(new Uint8Array(1));
9761cb0ef41Sopenharmony_ci  }).then(result => {
9771cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1);
9781cb0ef41Sopenharmony_ci    assert_not_equals(byobRequest, null, 'byobRequest must not be null');
9791cb0ef41Sopenharmony_ci    assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');
9801cb0ef41Sopenharmony_ci    assert_equals(viewInfo.bufferByteLength, 4, 'view.buffer.byteLength should be 4');
9811cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');
9821cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteLength, 4, 'view.byteLength should be 4');
9831cb0ef41Sopenharmony_ci
9841cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
9851cb0ef41Sopenharmony_ci
9861cb0ef41Sopenharmony_ci    const view = result.value;
9871cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, 'byteOffset');
9881cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 1, 'byteLength');
9891cb0ef41Sopenharmony_ci
9901cb0ef41Sopenharmony_ci    assert_equals(view[0], 0x03);
9911cb0ef41Sopenharmony_ci  });
9921cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respond(3) to read(view) with 2 element Uint16Array enqueues the 1 byte ' +
9931cb0ef41Sopenharmony_ci   'remainder');
9941cb0ef41Sopenharmony_ci
9951cb0ef41Sopenharmony_cipromise_test(t => {
9961cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
9971cb0ef41Sopenharmony_ci    start(controller) {
9981cb0ef41Sopenharmony_ci      const view = new Uint8Array(16);
9991cb0ef41Sopenharmony_ci      view[15] = 0x01;
10001cb0ef41Sopenharmony_ci      controller.enqueue(view);
10011cb0ef41Sopenharmony_ci    },
10021cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
10031cb0ef41Sopenharmony_ci    type: 'bytes'
10041cb0ef41Sopenharmony_ci  });
10051cb0ef41Sopenharmony_ci
10061cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
10071cb0ef41Sopenharmony_ci
10081cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(16)).then(result => {
10091cb0ef41Sopenharmony_ci    assert_false(result.done);
10101cb0ef41Sopenharmony_ci
10111cb0ef41Sopenharmony_ci    const view = result.value;
10121cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
10131cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 16);
10141cb0ef41Sopenharmony_ci    assert_equals(view[15], 0x01);
10151cb0ef41Sopenharmony_ci  });
10161cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view)');
10171cb0ef41Sopenharmony_ci
10181cb0ef41Sopenharmony_cipromise_test(t => {
10191cb0ef41Sopenharmony_ci  let cancelCount = 0;
10201cb0ef41Sopenharmony_ci  let reason;
10211cb0ef41Sopenharmony_ci
10221cb0ef41Sopenharmony_ci  const passedReason = new TypeError('foo');
10231cb0ef41Sopenharmony_ci
10241cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
10251cb0ef41Sopenharmony_ci    start(c) {
10261cb0ef41Sopenharmony_ci      c.enqueue(new Uint8Array(16));
10271cb0ef41Sopenharmony_ci    },
10281cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
10291cb0ef41Sopenharmony_ci    cancel(r) {
10301cb0ef41Sopenharmony_ci      if (cancelCount === 0) {
10311cb0ef41Sopenharmony_ci        reason = r;
10321cb0ef41Sopenharmony_ci      }
10331cb0ef41Sopenharmony_ci
10341cb0ef41Sopenharmony_ci      ++cancelCount;
10351cb0ef41Sopenharmony_ci    },
10361cb0ef41Sopenharmony_ci    type: 'bytes'
10371cb0ef41Sopenharmony_ci  });
10381cb0ef41Sopenharmony_ci
10391cb0ef41Sopenharmony_ci  const reader = stream.getReader();
10401cb0ef41Sopenharmony_ci
10411cb0ef41Sopenharmony_ci  return reader.cancel(passedReason).then(result => {
10421cb0ef41Sopenharmony_ci    assert_equals(result, undefined);
10431cb0ef41Sopenharmony_ci    assert_equals(cancelCount, 1);
10441cb0ef41Sopenharmony_ci    assert_equals(reason, passedReason, 'reason should equal the passed reason');
10451cb0ef41Sopenharmony_ci  });
10461cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = not BYOB)');
10471cb0ef41Sopenharmony_ci
10481cb0ef41Sopenharmony_cipromise_test(t => {
10491cb0ef41Sopenharmony_ci  let cancelCount = 0;
10501cb0ef41Sopenharmony_ci  let reason;
10511cb0ef41Sopenharmony_ci
10521cb0ef41Sopenharmony_ci  const passedReason = new TypeError('foo');
10531cb0ef41Sopenharmony_ci
10541cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
10551cb0ef41Sopenharmony_ci    start(c) {
10561cb0ef41Sopenharmony_ci      c.enqueue(new Uint8Array(16));
10571cb0ef41Sopenharmony_ci    },
10581cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
10591cb0ef41Sopenharmony_ci    cancel(r) {
10601cb0ef41Sopenharmony_ci      if (cancelCount === 0) {
10611cb0ef41Sopenharmony_ci        reason = r;
10621cb0ef41Sopenharmony_ci      }
10631cb0ef41Sopenharmony_ci
10641cb0ef41Sopenharmony_ci      ++cancelCount;
10651cb0ef41Sopenharmony_ci    },
10661cb0ef41Sopenharmony_ci    type: 'bytes'
10671cb0ef41Sopenharmony_ci  });
10681cb0ef41Sopenharmony_ci
10691cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
10701cb0ef41Sopenharmony_ci
10711cb0ef41Sopenharmony_ci  return reader.cancel(passedReason).then(result => {
10721cb0ef41Sopenharmony_ci    assert_equals(result, undefined);
10731cb0ef41Sopenharmony_ci    assert_equals(cancelCount, 1);
10741cb0ef41Sopenharmony_ci    assert_equals(reason, passedReason, 'reason should equal the passed reason');
10751cb0ef41Sopenharmony_ci  });
10761cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = BYOB)');
10771cb0ef41Sopenharmony_ci
10781cb0ef41Sopenharmony_cipromise_test(t => {
10791cb0ef41Sopenharmony_ci  let cancelCount = 0;
10801cb0ef41Sopenharmony_ci  let reason;
10811cb0ef41Sopenharmony_ci
10821cb0ef41Sopenharmony_ci  const passedReason = new TypeError('foo');
10831cb0ef41Sopenharmony_ci
10841cb0ef41Sopenharmony_ci  let controller;
10851cb0ef41Sopenharmony_ci
10861cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
10871cb0ef41Sopenharmony_ci    start(c) {
10881cb0ef41Sopenharmony_ci      controller = c;
10891cb0ef41Sopenharmony_ci    },
10901cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
10911cb0ef41Sopenharmony_ci    cancel(r) {
10921cb0ef41Sopenharmony_ci      if (cancelCount === 0) {
10931cb0ef41Sopenharmony_ci        reason = r;
10941cb0ef41Sopenharmony_ci      }
10951cb0ef41Sopenharmony_ci
10961cb0ef41Sopenharmony_ci      ++cancelCount;
10971cb0ef41Sopenharmony_ci
10981cb0ef41Sopenharmony_ci      return 'bar';
10991cb0ef41Sopenharmony_ci    },
11001cb0ef41Sopenharmony_ci    type: 'bytes'
11011cb0ef41Sopenharmony_ci  });
11021cb0ef41Sopenharmony_ci
11031cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
11041cb0ef41Sopenharmony_ci
11051cb0ef41Sopenharmony_ci  const readPromise = reader.read(new Uint8Array(1)).then(result => {
11061cb0ef41Sopenharmony_ci    assert_true(result.done, 'result.done');
11071cb0ef41Sopenharmony_ci    assert_equals(result.value, undefined, 'result.value');
11081cb0ef41Sopenharmony_ci  });
11091cb0ef41Sopenharmony_ci
11101cb0ef41Sopenharmony_ci  const cancelPromise = reader.cancel(passedReason).then(result => {
11111cb0ef41Sopenharmony_ci    assert_equals(result, undefined, 'cancel() return value should be fulfilled with undefined');
11121cb0ef41Sopenharmony_ci    assert_equals(cancelCount, 1, 'cancel() should be called only once');
11131cb0ef41Sopenharmony_ci    assert_equals(reason, passedReason, 'reason should equal the passed reason');
11141cb0ef41Sopenharmony_ci  });
11151cb0ef41Sopenharmony_ci
11161cb0ef41Sopenharmony_ci  return Promise.all([readPromise, cancelPromise]);
11171cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: getReader(), read(view), then cancel()');
11181cb0ef41Sopenharmony_ci
11191cb0ef41Sopenharmony_cipromise_test(() => {
11201cb0ef41Sopenharmony_ci  let pullCount = 0;
11211cb0ef41Sopenharmony_ci
11221cb0ef41Sopenharmony_ci  let controller;
11231cb0ef41Sopenharmony_ci  let byobRequest;
11241cb0ef41Sopenharmony_ci  const viewInfos = [];
11251cb0ef41Sopenharmony_ci
11261cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
11271cb0ef41Sopenharmony_ci    start(c) {
11281cb0ef41Sopenharmony_ci      controller = c;
11291cb0ef41Sopenharmony_ci    },
11301cb0ef41Sopenharmony_ci    pull() {
11311cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
11321cb0ef41Sopenharmony_ci
11331cb0ef41Sopenharmony_ci      viewInfos.push(extractViewInfo(controller.byobRequest.view));
11341cb0ef41Sopenharmony_ci      controller.enqueue(new Uint8Array(1));
11351cb0ef41Sopenharmony_ci      viewInfos.push(extractViewInfo(controller.byobRequest.view));
11361cb0ef41Sopenharmony_ci
11371cb0ef41Sopenharmony_ci      ++pullCount;
11381cb0ef41Sopenharmony_ci    },
11391cb0ef41Sopenharmony_ci    type: 'bytes'
11401cb0ef41Sopenharmony_ci  });
11411cb0ef41Sopenharmony_ci
11421cb0ef41Sopenharmony_ci  return Promise.resolve().then(() => {
11431cb0ef41Sopenharmony_ci    assert_equals(pullCount, 0, 'No pull() as no read(view) yet');
11441cb0ef41Sopenharmony_ci
11451cb0ef41Sopenharmony_ci    const reader = stream.getReader({ mode: 'byob' });
11461cb0ef41Sopenharmony_ci
11471cb0ef41Sopenharmony_ci    const promise = reader.read(new Uint16Array(1)).then(result => {
11481cb0ef41Sopenharmony_ci      assert_true(result.done, 'result.done');
11491cb0ef41Sopenharmony_ci      assert_equals(result.value, undefined, 'result.value');
11501cb0ef41Sopenharmony_ci    });
11511cb0ef41Sopenharmony_ci
11521cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, '1 pull() should have been made in response to partial fill by enqueue()');
11531cb0ef41Sopenharmony_ci    assert_not_equals(byobRequest, null, 'byobRequest should not be null');
11541cb0ef41Sopenharmony_ci    assert_equals(viewInfos[0].byteLength, 2, 'byteLength before enqueue() should be 2');
11551cb0ef41Sopenharmony_ci    assert_equals(viewInfos[1].byteLength, 1, 'byteLength after enqueue() should be 1');
11561cb0ef41Sopenharmony_ci
11571cb0ef41Sopenharmony_ci    reader.cancel();
11581cb0ef41Sopenharmony_ci
11591cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull() should only be called once');
11601cb0ef41Sopenharmony_ci    return promise;
11611cb0ef41Sopenharmony_ci  });
11621cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: cancel() with partially filled pending pull() request');
11631cb0ef41Sopenharmony_ci
11641cb0ef41Sopenharmony_cipromise_test(() => {
11651cb0ef41Sopenharmony_ci  let controller;
11661cb0ef41Sopenharmony_ci  let pullCalled = false;
11671cb0ef41Sopenharmony_ci
11681cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
11691cb0ef41Sopenharmony_ci    start(c) {
11701cb0ef41Sopenharmony_ci      const view = new Uint8Array(8);
11711cb0ef41Sopenharmony_ci      view[7] = 0x01;
11721cb0ef41Sopenharmony_ci      c.enqueue(view);
11731cb0ef41Sopenharmony_ci
11741cb0ef41Sopenharmony_ci      controller = c;
11751cb0ef41Sopenharmony_ci    },
11761cb0ef41Sopenharmony_ci    pull() {
11771cb0ef41Sopenharmony_ci      pullCalled = true;
11781cb0ef41Sopenharmony_ci    },
11791cb0ef41Sopenharmony_ci    type: 'bytes'
11801cb0ef41Sopenharmony_ci  });
11811cb0ef41Sopenharmony_ci
11821cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
11831cb0ef41Sopenharmony_ci
11841cb0ef41Sopenharmony_ci  const buffer = new ArrayBuffer(16);
11851cb0ef41Sopenharmony_ci
11861cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(buffer, 8, 8)).then(result => {
11871cb0ef41Sopenharmony_ci    assert_false(result.done);
11881cb0ef41Sopenharmony_ci
11891cb0ef41Sopenharmony_ci    assert_false(pullCalled, 'pull() must not have been called');
11901cb0ef41Sopenharmony_ci
11911cb0ef41Sopenharmony_ci    const view = result.value;
11921cb0ef41Sopenharmony_ci    assert_equals(view.constructor, Uint8Array);
11931cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 16);
11941cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 8);
11951cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 8);
11961cb0ef41Sopenharmony_ci    assert_equals(view[7], 0x01);
11971cb0ef41Sopenharmony_ci  });
11981cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) where view.buffer is not fully ' +
11991cb0ef41Sopenharmony_ci   'covered by view');
12001cb0ef41Sopenharmony_ci
12011cb0ef41Sopenharmony_cipromise_test(() => {
12021cb0ef41Sopenharmony_ci  let controller;
12031cb0ef41Sopenharmony_ci  let pullCalled = false;
12041cb0ef41Sopenharmony_ci
12051cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
12061cb0ef41Sopenharmony_ci    start(c) {
12071cb0ef41Sopenharmony_ci      let view;
12081cb0ef41Sopenharmony_ci
12091cb0ef41Sopenharmony_ci      view = new Uint8Array(16);
12101cb0ef41Sopenharmony_ci      view[15] = 123;
12111cb0ef41Sopenharmony_ci      c.enqueue(view);
12121cb0ef41Sopenharmony_ci
12131cb0ef41Sopenharmony_ci      view = new Uint8Array(8);
12141cb0ef41Sopenharmony_ci      view[7] = 111;
12151cb0ef41Sopenharmony_ci      c.enqueue(view);
12161cb0ef41Sopenharmony_ci
12171cb0ef41Sopenharmony_ci      controller = c;
12181cb0ef41Sopenharmony_ci    },
12191cb0ef41Sopenharmony_ci    pull() {
12201cb0ef41Sopenharmony_ci      pullCalled = true;
12211cb0ef41Sopenharmony_ci    },
12221cb0ef41Sopenharmony_ci    type: 'bytes'
12231cb0ef41Sopenharmony_ci  });
12241cb0ef41Sopenharmony_ci
12251cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
12261cb0ef41Sopenharmony_ci
12271cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(24)).then(result => {
12281cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
12291cb0ef41Sopenharmony_ci
12301cb0ef41Sopenharmony_ci    assert_false(pullCalled, 'pull() must not have been called');
12311cb0ef41Sopenharmony_ci
12321cb0ef41Sopenharmony_ci    const view = result.value;
12331cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, 'byteOffset');
12341cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 24, 'byteLength');
12351cb0ef41Sopenharmony_ci    assert_equals(view[15], 123, 'Contents are set from the first chunk');
12361cb0ef41Sopenharmony_ci    assert_equals(view[23], 111, 'Contents are set from the second chunk');
12371cb0ef41Sopenharmony_ci  });
12381cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Multiple enqueue(), getReader(), then read(view)');
12391cb0ef41Sopenharmony_ci
12401cb0ef41Sopenharmony_cipromise_test(() => {
12411cb0ef41Sopenharmony_ci  let pullCalled = false;
12421cb0ef41Sopenharmony_ci
12431cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
12441cb0ef41Sopenharmony_ci    start(c) {
12451cb0ef41Sopenharmony_ci      const view = new Uint8Array(16);
12461cb0ef41Sopenharmony_ci      view[15] = 0x01;
12471cb0ef41Sopenharmony_ci      c.enqueue(view);
12481cb0ef41Sopenharmony_ci    },
12491cb0ef41Sopenharmony_ci    pull() {
12501cb0ef41Sopenharmony_ci      pullCalled = true;
12511cb0ef41Sopenharmony_ci    },
12521cb0ef41Sopenharmony_ci    type: 'bytes'
12531cb0ef41Sopenharmony_ci  });
12541cb0ef41Sopenharmony_ci
12551cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
12561cb0ef41Sopenharmony_ci
12571cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(24)).then(result => {
12581cb0ef41Sopenharmony_ci    assert_false(result.done);
12591cb0ef41Sopenharmony_ci
12601cb0ef41Sopenharmony_ci    assert_false(pullCalled, 'pull() must not have been called');
12611cb0ef41Sopenharmony_ci
12621cb0ef41Sopenharmony_ci    const view = result.value;
12631cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
12641cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 16);
12651cb0ef41Sopenharmony_ci    assert_equals(view[15], 0x01);
12661cb0ef41Sopenharmony_ci  });
12671cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) with a bigger view');
12681cb0ef41Sopenharmony_ci
12691cb0ef41Sopenharmony_cipromise_test(() => {
12701cb0ef41Sopenharmony_ci  let pullCalled = false;
12711cb0ef41Sopenharmony_ci
12721cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
12731cb0ef41Sopenharmony_ci    start(c) {
12741cb0ef41Sopenharmony_ci      const view = new Uint8Array(16);
12751cb0ef41Sopenharmony_ci      view[7] = 0x01;
12761cb0ef41Sopenharmony_ci      view[15] = 0x02;
12771cb0ef41Sopenharmony_ci      c.enqueue(view);
12781cb0ef41Sopenharmony_ci    },
12791cb0ef41Sopenharmony_ci    pull() {
12801cb0ef41Sopenharmony_ci      pullCalled = true;
12811cb0ef41Sopenharmony_ci    },
12821cb0ef41Sopenharmony_ci    type: 'bytes'
12831cb0ef41Sopenharmony_ci  });
12841cb0ef41Sopenharmony_ci
12851cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
12861cb0ef41Sopenharmony_ci
12871cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(8)).then(result => {
12881cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
12891cb0ef41Sopenharmony_ci
12901cb0ef41Sopenharmony_ci    const view = result.value;
12911cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
12921cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 8);
12931cb0ef41Sopenharmony_ci    assert_equals(view[7], 0x01);
12941cb0ef41Sopenharmony_ci
12951cb0ef41Sopenharmony_ci    return reader.read(new Uint8Array(8));
12961cb0ef41Sopenharmony_ci  }).then(result => {
12971cb0ef41Sopenharmony_ci    assert_false(result.done, 'done');
12981cb0ef41Sopenharmony_ci
12991cb0ef41Sopenharmony_ci    assert_false(pullCalled, 'pull() must not have been called');
13001cb0ef41Sopenharmony_ci
13011cb0ef41Sopenharmony_ci    const view = result.value;
13021cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
13031cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 8);
13041cb0ef41Sopenharmony_ci    assert_equals(view[7], 0x02);
13051cb0ef41Sopenharmony_ci  });
13061cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) with smaller views');
13071cb0ef41Sopenharmony_ci
13081cb0ef41Sopenharmony_cipromise_test(() => {
13091cb0ef41Sopenharmony_ci  let controller;
13101cb0ef41Sopenharmony_ci  let viewInfo;
13111cb0ef41Sopenharmony_ci
13121cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
13131cb0ef41Sopenharmony_ci    start(c) {
13141cb0ef41Sopenharmony_ci      const view = new Uint8Array(1);
13151cb0ef41Sopenharmony_ci      view[0] = 0xff;
13161cb0ef41Sopenharmony_ci      c.enqueue(view);
13171cb0ef41Sopenharmony_ci
13181cb0ef41Sopenharmony_ci      controller = c;
13191cb0ef41Sopenharmony_ci    },
13201cb0ef41Sopenharmony_ci    pull() {
13211cb0ef41Sopenharmony_ci      if (controller.byobRequest === null) {
13221cb0ef41Sopenharmony_ci        return;
13231cb0ef41Sopenharmony_ci      }
13241cb0ef41Sopenharmony_ci
13251cb0ef41Sopenharmony_ci      const view = controller.byobRequest.view;
13261cb0ef41Sopenharmony_ci      viewInfo = extractViewInfo(view);
13271cb0ef41Sopenharmony_ci
13281cb0ef41Sopenharmony_ci      view[0] = 0xaa;
13291cb0ef41Sopenharmony_ci      controller.byobRequest.respond(1);
13301cb0ef41Sopenharmony_ci    },
13311cb0ef41Sopenharmony_ci    type: 'bytes'
13321cb0ef41Sopenharmony_ci  });
13331cb0ef41Sopenharmony_ci
13341cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
13351cb0ef41Sopenharmony_ci
13361cb0ef41Sopenharmony_ci  return reader.read(new Uint16Array(1)).then(result => {
13371cb0ef41Sopenharmony_ci    assert_false(result.done);
13381cb0ef41Sopenharmony_ci
13391cb0ef41Sopenharmony_ci    const view = result.value;
13401cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
13411cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 2);
13421cb0ef41Sopenharmony_ci
13431cb0ef41Sopenharmony_ci    const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);
13441cb0ef41Sopenharmony_ci    assert_equals(dataView.getUint16(0), 0xffaa);
13451cb0ef41Sopenharmony_ci
13461cb0ef41Sopenharmony_ci    assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');
13471cb0ef41Sopenharmony_ci    assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');
13481cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteOffset, 1, 'view.byteOffset should be 1');
13491cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteLength, 1, 'view.byteLength should be 1');
13501cb0ef41Sopenharmony_ci  });
13511cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue() 1 byte, getReader(), then read(view) with Uint16Array');
13521cb0ef41Sopenharmony_ci
13531cb0ef41Sopenharmony_cipromise_test(() => {
13541cb0ef41Sopenharmony_ci  let pullCount = 0;
13551cb0ef41Sopenharmony_ci
13561cb0ef41Sopenharmony_ci  let controller;
13571cb0ef41Sopenharmony_ci  let byobRequest;
13581cb0ef41Sopenharmony_ci  let viewInfo;
13591cb0ef41Sopenharmony_ci  let desiredSize;
13601cb0ef41Sopenharmony_ci
13611cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
13621cb0ef41Sopenharmony_ci    start(c) {
13631cb0ef41Sopenharmony_ci      const view = new Uint8Array(3);
13641cb0ef41Sopenharmony_ci      view[0] = 0x01;
13651cb0ef41Sopenharmony_ci      view[2] = 0x02;
13661cb0ef41Sopenharmony_ci      c.enqueue(view);
13671cb0ef41Sopenharmony_ci
13681cb0ef41Sopenharmony_ci      controller = c;
13691cb0ef41Sopenharmony_ci    },
13701cb0ef41Sopenharmony_ci    pull() {
13711cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
13721cb0ef41Sopenharmony_ci
13731cb0ef41Sopenharmony_ci      const view = controller.byobRequest.view;
13741cb0ef41Sopenharmony_ci
13751cb0ef41Sopenharmony_ci      viewInfo = extractViewInfo(view);
13761cb0ef41Sopenharmony_ci
13771cb0ef41Sopenharmony_ci      view[0] = 0x03;
13781cb0ef41Sopenharmony_ci      controller.byobRequest.respond(1);
13791cb0ef41Sopenharmony_ci
13801cb0ef41Sopenharmony_ci      desiredSize = controller.desiredSize;
13811cb0ef41Sopenharmony_ci
13821cb0ef41Sopenharmony_ci      ++pullCount;
13831cb0ef41Sopenharmony_ci    },
13841cb0ef41Sopenharmony_ci    type: 'bytes'
13851cb0ef41Sopenharmony_ci  });
13861cb0ef41Sopenharmony_ci
13871cb0ef41Sopenharmony_ci  // Wait for completion of the start method to be reflected.
13881cb0ef41Sopenharmony_ci  return Promise.resolve().then(() => {
13891cb0ef41Sopenharmony_ci    const reader = stream.getReader({ mode: 'byob' });
13901cb0ef41Sopenharmony_ci
13911cb0ef41Sopenharmony_ci    const promise = reader.read(new Uint16Array(2)).then(result => {
13921cb0ef41Sopenharmony_ci      assert_false(result.done, 'done');
13931cb0ef41Sopenharmony_ci
13941cb0ef41Sopenharmony_ci      const view = result.value;
13951cb0ef41Sopenharmony_ci      assert_equals(view.constructor, Uint16Array, 'constructor');
13961cb0ef41Sopenharmony_ci      assert_equals(view.buffer.byteLength, 4, 'buffer.byteLength');
13971cb0ef41Sopenharmony_ci      assert_equals(view.byteOffset, 0, 'byteOffset');
13981cb0ef41Sopenharmony_ci      assert_equals(view.byteLength, 2, 'byteLength');
13991cb0ef41Sopenharmony_ci
14001cb0ef41Sopenharmony_ci      const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);
14011cb0ef41Sopenharmony_ci      assert_equals(dataView.getUint16(0), 0x0100, 'contents are set');
14021cb0ef41Sopenharmony_ci
14031cb0ef41Sopenharmony_ci      const p = reader.read(new Uint16Array(1));
14041cb0ef41Sopenharmony_ci
14051cb0ef41Sopenharmony_ci      assert_equals(pullCount, 1);
14061cb0ef41Sopenharmony_ci
14071cb0ef41Sopenharmony_ci      return p;
14081cb0ef41Sopenharmony_ci    }).then(result => {
14091cb0ef41Sopenharmony_ci      assert_false(result.done, 'done');
14101cb0ef41Sopenharmony_ci
14111cb0ef41Sopenharmony_ci      const view = result.value;
14121cb0ef41Sopenharmony_ci      assert_equals(view.buffer.byteLength, 2, 'buffer.byteLength');
14131cb0ef41Sopenharmony_ci      assert_equals(view.byteOffset, 0, 'byteOffset');
14141cb0ef41Sopenharmony_ci      assert_equals(view.byteLength, 2, 'byteLength');
14151cb0ef41Sopenharmony_ci
14161cb0ef41Sopenharmony_ci      const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);
14171cb0ef41Sopenharmony_ci      assert_equals(dataView.getUint16(0), 0x0203, 'contents are set');
14181cb0ef41Sopenharmony_ci
14191cb0ef41Sopenharmony_ci      assert_not_equals(byobRequest, null, 'byobRequest must not be null');
14201cb0ef41Sopenharmony_ci      assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');
14211cb0ef41Sopenharmony_ci      assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');
14221cb0ef41Sopenharmony_ci      assert_equals(viewInfo.byteOffset, 1, 'view.byteOffset should be 1');
14231cb0ef41Sopenharmony_ci      assert_equals(viewInfo.byteLength, 1, 'view.byteLength should be 1');
14241cb0ef41Sopenharmony_ci      assert_equals(desiredSize, 0, 'desiredSize should be zero');
14251cb0ef41Sopenharmony_ci    });
14261cb0ef41Sopenharmony_ci
14271cb0ef41Sopenharmony_ci    assert_equals(pullCount, 0);
14281cb0ef41Sopenharmony_ci
14291cb0ef41Sopenharmony_ci    return promise;
14301cb0ef41Sopenharmony_ci  });
14311cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue() 3 byte, getReader(), then read(view) with 2-element Uint16Array');
14321cb0ef41Sopenharmony_ci
14331cb0ef41Sopenharmony_cipromise_test(t => {
14341cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
14351cb0ef41Sopenharmony_ci    start(c) {
14361cb0ef41Sopenharmony_ci      const view = new Uint8Array(1);
14371cb0ef41Sopenharmony_ci      view[0] = 0xff;
14381cb0ef41Sopenharmony_ci      c.enqueue(view);
14391cb0ef41Sopenharmony_ci      c.close();
14401cb0ef41Sopenharmony_ci    },
14411cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
14421cb0ef41Sopenharmony_ci    type: 'bytes'
14431cb0ef41Sopenharmony_ci  });
14441cb0ef41Sopenharmony_ci
14451cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
14461cb0ef41Sopenharmony_ci
14471cb0ef41Sopenharmony_ci
14481cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError, reader.read(new Uint16Array(1)), 'read(view) must fail')
14491cb0ef41Sopenharmony_ci      .then(() => promise_rejects_js(t, TypeError, reader.closed, 'reader.closed should reject'));
14501cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view) with Uint16Array on close()-d stream with 1 byte enqueue()-d must ' +
14511cb0ef41Sopenharmony_ci   'fail');
14521cb0ef41Sopenharmony_ci
14531cb0ef41Sopenharmony_cipromise_test(t => {
14541cb0ef41Sopenharmony_ci  let controller;
14551cb0ef41Sopenharmony_ci
14561cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
14571cb0ef41Sopenharmony_ci    start(c) {
14581cb0ef41Sopenharmony_ci      const view = new Uint8Array(1);
14591cb0ef41Sopenharmony_ci      view[0] = 0xff;
14601cb0ef41Sopenharmony_ci      c.enqueue(view);
14611cb0ef41Sopenharmony_ci
14621cb0ef41Sopenharmony_ci      controller = c;
14631cb0ef41Sopenharmony_ci    },
14641cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
14651cb0ef41Sopenharmony_ci    type: 'bytes'
14661cb0ef41Sopenharmony_ci  });
14671cb0ef41Sopenharmony_ci
14681cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
14691cb0ef41Sopenharmony_ci
14701cb0ef41Sopenharmony_ci  const readPromise = reader.read(new Uint16Array(1));
14711cb0ef41Sopenharmony_ci
14721cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => controller.close(), 'controller.close() must throw');
14731cb0ef41Sopenharmony_ci
14741cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError, readPromise, 'read(view) must fail')
14751cb0ef41Sopenharmony_ci      .then(() => promise_rejects_js(t, TypeError, reader.closed, 'reader.closed must reject'));
14761cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: A stream must be errored if close()-d before fulfilling read(view) with ' +
14771cb0ef41Sopenharmony_ci   'Uint16Array');
14781cb0ef41Sopenharmony_ci
14791cb0ef41Sopenharmony_citest(() => {
14801cb0ef41Sopenharmony_ci  let controller;
14811cb0ef41Sopenharmony_ci
14821cb0ef41Sopenharmony_ci  new ReadableStream({
14831cb0ef41Sopenharmony_ci    start(c) {
14841cb0ef41Sopenharmony_ci      controller = c;
14851cb0ef41Sopenharmony_ci    },
14861cb0ef41Sopenharmony_ci    type: 'bytes'
14871cb0ef41Sopenharmony_ci  });
14881cb0ef41Sopenharmony_ci
14891cb0ef41Sopenharmony_ci  // Enqueue a chunk so that the stream doesn't get closed. This is to check duplicate close() calls are rejected
14901cb0ef41Sopenharmony_ci  // even if the stream has not yet entered the closed state.
14911cb0ef41Sopenharmony_ci  const view = new Uint8Array(1);
14921cb0ef41Sopenharmony_ci  controller.enqueue(view);
14931cb0ef41Sopenharmony_ci  controller.close();
14941cb0ef41Sopenharmony_ci
14951cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => controller.close(), 'controller.close() must throw');
14961cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Throw if close()-ed more than once');
14971cb0ef41Sopenharmony_ci
14981cb0ef41Sopenharmony_citest(() => {
14991cb0ef41Sopenharmony_ci  let controller;
15001cb0ef41Sopenharmony_ci
15011cb0ef41Sopenharmony_ci  new ReadableStream({
15021cb0ef41Sopenharmony_ci    start(c) {
15031cb0ef41Sopenharmony_ci      controller = c;
15041cb0ef41Sopenharmony_ci    },
15051cb0ef41Sopenharmony_ci    type: 'bytes'
15061cb0ef41Sopenharmony_ci  });
15071cb0ef41Sopenharmony_ci
15081cb0ef41Sopenharmony_ci  // Enqueue a chunk so that the stream doesn't get closed. This is to check enqueue() after close() is  rejected
15091cb0ef41Sopenharmony_ci  // even if the stream has not yet entered the closed state.
15101cb0ef41Sopenharmony_ci  const view = new Uint8Array(1);
15111cb0ef41Sopenharmony_ci  controller.enqueue(view);
15121cb0ef41Sopenharmony_ci  controller.close();
15131cb0ef41Sopenharmony_ci
15141cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => controller.enqueue(view), 'controller.close() must throw');
15151cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Throw on enqueue() after close()');
15161cb0ef41Sopenharmony_ci
15171cb0ef41Sopenharmony_cipromise_test(() => {
15181cb0ef41Sopenharmony_ci  let controller;
15191cb0ef41Sopenharmony_ci  let byobRequest;
15201cb0ef41Sopenharmony_ci  let viewInfo;
15211cb0ef41Sopenharmony_ci
15221cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
15231cb0ef41Sopenharmony_ci    start(c) {
15241cb0ef41Sopenharmony_ci      controller = c;
15251cb0ef41Sopenharmony_ci    },
15261cb0ef41Sopenharmony_ci    pull() {
15271cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
15281cb0ef41Sopenharmony_ci      const view = controller.byobRequest.view;
15291cb0ef41Sopenharmony_ci      viewInfo = extractViewInfo(view);
15301cb0ef41Sopenharmony_ci
15311cb0ef41Sopenharmony_ci      view[15] = 0x01;
15321cb0ef41Sopenharmony_ci      controller.byobRequest.respond(16);
15331cb0ef41Sopenharmony_ci      controller.close();
15341cb0ef41Sopenharmony_ci    },
15351cb0ef41Sopenharmony_ci    type: 'bytes'
15361cb0ef41Sopenharmony_ci  });
15371cb0ef41Sopenharmony_ci
15381cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
15391cb0ef41Sopenharmony_ci
15401cb0ef41Sopenharmony_ci  return reader.read(new Uint8Array(16)).then(result => {
15411cb0ef41Sopenharmony_ci    assert_false(result.done);
15421cb0ef41Sopenharmony_ci
15431cb0ef41Sopenharmony_ci    const view = result.value;
15441cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
15451cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 16);
15461cb0ef41Sopenharmony_ci    assert_equals(view[15], 0x01);
15471cb0ef41Sopenharmony_ci
15481cb0ef41Sopenharmony_ci    return reader.read(new Uint8Array(16));
15491cb0ef41Sopenharmony_ci  }).then(result => {
15501cb0ef41Sopenharmony_ci    assert_true(result.done);
15511cb0ef41Sopenharmony_ci
15521cb0ef41Sopenharmony_ci    const view = result.value;
15531cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
15541cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 0);
15551cb0ef41Sopenharmony_ci
15561cb0ef41Sopenharmony_ci    assert_not_equals(byobRequest, null, 'byobRequest must not be null');
15571cb0ef41Sopenharmony_ci    assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');
15581cb0ef41Sopenharmony_ci    assert_equals(viewInfo.bufferByteLength, 16, 'view.buffer.byteLength should be 16');
15591cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');
15601cb0ef41Sopenharmony_ci    assert_equals(viewInfo.byteLength, 16, 'view.byteLength should be 16');
15611cb0ef41Sopenharmony_ci  });
15621cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view), then respond() and close() in pull()');
15631cb0ef41Sopenharmony_ci
15641cb0ef41Sopenharmony_cipromise_test(() => {
15651cb0ef41Sopenharmony_ci  let pullCount = 0;
15661cb0ef41Sopenharmony_ci
15671cb0ef41Sopenharmony_ci  let controller;
15681cb0ef41Sopenharmony_ci  const viewInfos = [];
15691cb0ef41Sopenharmony_ci  const viewInfosAfterRespond = [];
15701cb0ef41Sopenharmony_ci
15711cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
15721cb0ef41Sopenharmony_ci    start(c) {
15731cb0ef41Sopenharmony_ci      controller = c;
15741cb0ef41Sopenharmony_ci    },
15751cb0ef41Sopenharmony_ci    pull() {
15761cb0ef41Sopenharmony_ci      if (controller.byobRequest === null) {
15771cb0ef41Sopenharmony_ci        return;
15781cb0ef41Sopenharmony_ci      }
15791cb0ef41Sopenharmony_ci
15801cb0ef41Sopenharmony_ci      for (let i = 0; i < 4; ++i) {
15811cb0ef41Sopenharmony_ci        const view = controller.byobRequest.view;
15821cb0ef41Sopenharmony_ci        viewInfos.push(extractViewInfo(view));
15831cb0ef41Sopenharmony_ci
15841cb0ef41Sopenharmony_ci        view[0] = 0x01;
15851cb0ef41Sopenharmony_ci        controller.byobRequest.respond(1);
15861cb0ef41Sopenharmony_ci        viewInfosAfterRespond.push(extractViewInfo(view));
15871cb0ef41Sopenharmony_ci      }
15881cb0ef41Sopenharmony_ci
15891cb0ef41Sopenharmony_ci      ++pullCount;
15901cb0ef41Sopenharmony_ci    },
15911cb0ef41Sopenharmony_ci    type: 'bytes'
15921cb0ef41Sopenharmony_ci  });
15931cb0ef41Sopenharmony_ci
15941cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
15951cb0ef41Sopenharmony_ci
15961cb0ef41Sopenharmony_ci  return reader.read(new Uint32Array(1)).then(result => {
15971cb0ef41Sopenharmony_ci    assert_false(result.done, 'result.done');
15981cb0ef41Sopenharmony_ci
15991cb0ef41Sopenharmony_ci    const view = result.value;
16001cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
16011cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 4, 'result.value.byteLength');
16021cb0ef41Sopenharmony_ci    assert_equals(view[0], 0x01010101, 'result.value[0]');
16031cb0ef41Sopenharmony_ci
16041cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull() should only be called once');
16051cb0ef41Sopenharmony_ci
16061cb0ef41Sopenharmony_ci    for (let i = 0; i < 4; ++i) {
16071cb0ef41Sopenharmony_ci      assert_equals(viewInfos[i].constructor, Uint8Array, 'view.constructor should be Uint8Array');
16081cb0ef41Sopenharmony_ci      assert_equals(viewInfos[i].bufferByteLength, 4, 'view.buffer.byteLength should be 4');
16091cb0ef41Sopenharmony_ci
16101cb0ef41Sopenharmony_ci      assert_equals(viewInfos[i].byteOffset, i, 'view.byteOffset should be i');
16111cb0ef41Sopenharmony_ci      assert_equals(viewInfos[i].byteLength, 4 - i, 'view.byteLength should be 4 - i');
16121cb0ef41Sopenharmony_ci
16131cb0ef41Sopenharmony_ci      assert_equals(viewInfosAfterRespond[i].bufferByteLength, 0, 'view.buffer should be transferred after respond()');
16141cb0ef41Sopenharmony_ci    }
16151cb0ef41Sopenharmony_ci  });
16161cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view) with Uint32Array, then fill it by multiple respond() calls');
16171cb0ef41Sopenharmony_ci
16181cb0ef41Sopenharmony_cipromise_test(() => {
16191cb0ef41Sopenharmony_ci  let pullCount = 0;
16201cb0ef41Sopenharmony_ci
16211cb0ef41Sopenharmony_ci  let controller;
16221cb0ef41Sopenharmony_ci  const viewInfos = [];
16231cb0ef41Sopenharmony_ci  const viewInfosAfterEnqueue = [];
16241cb0ef41Sopenharmony_ci
16251cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
16261cb0ef41Sopenharmony_ci    start(c) {
16271cb0ef41Sopenharmony_ci      controller = c;
16281cb0ef41Sopenharmony_ci    },
16291cb0ef41Sopenharmony_ci    pull() {
16301cb0ef41Sopenharmony_ci      if (controller.byobRequest === null) {
16311cb0ef41Sopenharmony_ci        return;
16321cb0ef41Sopenharmony_ci      }
16331cb0ef41Sopenharmony_ci
16341cb0ef41Sopenharmony_ci      for (let i = 0; i < 4; ++i) {
16351cb0ef41Sopenharmony_ci        const view = controller.byobRequest.view;
16361cb0ef41Sopenharmony_ci        viewInfos.push(extractViewInfo(view));
16371cb0ef41Sopenharmony_ci
16381cb0ef41Sopenharmony_ci        controller.enqueue(new Uint8Array([0x01]));
16391cb0ef41Sopenharmony_ci        viewInfosAfterEnqueue.push(extractViewInfo(view));
16401cb0ef41Sopenharmony_ci      }
16411cb0ef41Sopenharmony_ci
16421cb0ef41Sopenharmony_ci      ++pullCount;
16431cb0ef41Sopenharmony_ci    },
16441cb0ef41Sopenharmony_ci    type: 'bytes'
16451cb0ef41Sopenharmony_ci  });
16461cb0ef41Sopenharmony_ci
16471cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
16481cb0ef41Sopenharmony_ci
16491cb0ef41Sopenharmony_ci  return reader.read(new Uint32Array(1)).then(result => {
16501cb0ef41Sopenharmony_ci    assert_false(result.done, 'result.done');
16511cb0ef41Sopenharmony_ci
16521cb0ef41Sopenharmony_ci    const view = result.value;
16531cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
16541cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 4, 'result.value.byteLength');
16551cb0ef41Sopenharmony_ci    assert_equals(view[0], 0x01010101, 'result.value[0]');
16561cb0ef41Sopenharmony_ci
16571cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1, 'pull() should only be called once');
16581cb0ef41Sopenharmony_ci
16591cb0ef41Sopenharmony_ci    for (let i = 0; i < 4; ++i) {
16601cb0ef41Sopenharmony_ci      assert_equals(viewInfos[i].constructor, Uint8Array, 'view.constructor should be Uint8Array');
16611cb0ef41Sopenharmony_ci      assert_equals(viewInfos[i].bufferByteLength, 4, 'view.buffer.byteLength should be 4');
16621cb0ef41Sopenharmony_ci
16631cb0ef41Sopenharmony_ci      assert_equals(viewInfos[i].byteOffset, i, 'view.byteOffset should be i');
16641cb0ef41Sopenharmony_ci      assert_equals(viewInfos[i].byteLength, 4 - i, 'view.byteLength should be 4 - i');
16651cb0ef41Sopenharmony_ci
16661cb0ef41Sopenharmony_ci      assert_equals(viewInfosAfterEnqueue[i].bufferByteLength, 0, 'view.buffer should be transferred after enqueue()');
16671cb0ef41Sopenharmony_ci    }
16681cb0ef41Sopenharmony_ci  });
16691cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view) with Uint32Array, then fill it by multiple enqueue() calls');
16701cb0ef41Sopenharmony_ci
16711cb0ef41Sopenharmony_cipromise_test(() => {
16721cb0ef41Sopenharmony_ci  let pullCount = 0;
16731cb0ef41Sopenharmony_ci
16741cb0ef41Sopenharmony_ci  let controller;
16751cb0ef41Sopenharmony_ci  let byobRequest;
16761cb0ef41Sopenharmony_ci
16771cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
16781cb0ef41Sopenharmony_ci    start(c) {
16791cb0ef41Sopenharmony_ci      controller = c;
16801cb0ef41Sopenharmony_ci    },
16811cb0ef41Sopenharmony_ci    pull() {
16821cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
16831cb0ef41Sopenharmony_ci
16841cb0ef41Sopenharmony_ci      ++pullCount;
16851cb0ef41Sopenharmony_ci    },
16861cb0ef41Sopenharmony_ci    type: 'bytes'
16871cb0ef41Sopenharmony_ci  });
16881cb0ef41Sopenharmony_ci
16891cb0ef41Sopenharmony_ci  const reader = stream.getReader();
16901cb0ef41Sopenharmony_ci
16911cb0ef41Sopenharmony_ci  const p0 = reader.read().then(result => {
16921cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1);
16931cb0ef41Sopenharmony_ci
16941cb0ef41Sopenharmony_ci    controller.enqueue(new Uint8Array(2));
16951cb0ef41Sopenharmony_ci
16961cb0ef41Sopenharmony_ci    // Since the queue has data no less than HWM, no more pull.
16971cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1);
16981cb0ef41Sopenharmony_ci
16991cb0ef41Sopenharmony_ci    assert_false(result.done);
17001cb0ef41Sopenharmony_ci
17011cb0ef41Sopenharmony_ci    const view = result.value;
17021cb0ef41Sopenharmony_ci    assert_equals(view.constructor, Uint8Array);
17031cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 1);
17041cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
17051cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 1);
17061cb0ef41Sopenharmony_ci  });
17071cb0ef41Sopenharmony_ci
17081cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'No pull should have been made since the startPromise has not yet been handled');
17091cb0ef41Sopenharmony_ci
17101cb0ef41Sopenharmony_ci  const p1 = reader.read().then(result => {
17111cb0ef41Sopenharmony_ci    assert_equals(pullCount, 1);
17121cb0ef41Sopenharmony_ci
17131cb0ef41Sopenharmony_ci    assert_false(result.done);
17141cb0ef41Sopenharmony_ci
17151cb0ef41Sopenharmony_ci    const view = result.value;
17161cb0ef41Sopenharmony_ci    assert_equals(view.constructor, Uint8Array);
17171cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 2);
17181cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0);
17191cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 2);
17201cb0ef41Sopenharmony_ci
17211cb0ef41Sopenharmony_ci    assert_equals(byobRequest, null, 'byobRequest must be null');
17221cb0ef41Sopenharmony_ci  });
17231cb0ef41Sopenharmony_ci
17241cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'No pull should have been made since the startPromise has not yet been handled');
17251cb0ef41Sopenharmony_ci
17261cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array(1));
17271cb0ef41Sopenharmony_ci
17281cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'No pull should have been made since the startPromise has not yet been handled');
17291cb0ef41Sopenharmony_ci
17301cb0ef41Sopenharmony_ci  return Promise.all([p0, p1]);
17311cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read() twice, then enqueue() twice');
17321cb0ef41Sopenharmony_ci
17331cb0ef41Sopenharmony_cipromise_test(t => {
17341cb0ef41Sopenharmony_ci  let controller;
17351cb0ef41Sopenharmony_ci
17361cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
17371cb0ef41Sopenharmony_ci    start(c) {
17381cb0ef41Sopenharmony_ci      controller = c;
17391cb0ef41Sopenharmony_ci    },
17401cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
17411cb0ef41Sopenharmony_ci    type: 'bytes'
17421cb0ef41Sopenharmony_ci  });
17431cb0ef41Sopenharmony_ci
17441cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
17451cb0ef41Sopenharmony_ci
17461cb0ef41Sopenharmony_ci  const p0 = reader.read(new Uint8Array(16)).then(result => {
17471cb0ef41Sopenharmony_ci    assert_true(result.done, '1st read: done');
17481cb0ef41Sopenharmony_ci
17491cb0ef41Sopenharmony_ci    const view = result.value;
17501cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 16, '1st read: buffer.byteLength');
17511cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, '1st read: byteOffset');
17521cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 0, '1st read: byteLength');
17531cb0ef41Sopenharmony_ci  });
17541cb0ef41Sopenharmony_ci
17551cb0ef41Sopenharmony_ci  const p1 = reader.read(new Uint8Array(32)).then(result => {
17561cb0ef41Sopenharmony_ci    assert_true(result.done, '2nd read: done');
17571cb0ef41Sopenharmony_ci
17581cb0ef41Sopenharmony_ci    const view = result.value;
17591cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 32, '2nd read: buffer.byteLength');
17601cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, '2nd read: byteOffset');
17611cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 0, '2nd read: byteLength');
17621cb0ef41Sopenharmony_ci  });
17631cb0ef41Sopenharmony_ci
17641cb0ef41Sopenharmony_ci  controller.close();
17651cb0ef41Sopenharmony_ci  controller.byobRequest.respond(0);
17661cb0ef41Sopenharmony_ci
17671cb0ef41Sopenharmony_ci  return Promise.all([p0, p1]);
17681cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Multiple read(view), close() and respond()');
17691cb0ef41Sopenharmony_ci
17701cb0ef41Sopenharmony_cipromise_test(t => {
17711cb0ef41Sopenharmony_ci  let controller;
17721cb0ef41Sopenharmony_ci
17731cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
17741cb0ef41Sopenharmony_ci    start(c) {
17751cb0ef41Sopenharmony_ci      controller = c;
17761cb0ef41Sopenharmony_ci    },
17771cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
17781cb0ef41Sopenharmony_ci    type: 'bytes'
17791cb0ef41Sopenharmony_ci  });
17801cb0ef41Sopenharmony_ci
17811cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
17821cb0ef41Sopenharmony_ci
17831cb0ef41Sopenharmony_ci  const p0 = reader.read(new Uint8Array(16)).then(result => {
17841cb0ef41Sopenharmony_ci    assert_false(result.done, '1st read: done');
17851cb0ef41Sopenharmony_ci
17861cb0ef41Sopenharmony_ci    const view = result.value;
17871cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 16, '1st read: buffer.byteLength');
17881cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, '1st read: byteOffset');
17891cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 16, '1st read: byteLength');
17901cb0ef41Sopenharmony_ci  });
17911cb0ef41Sopenharmony_ci
17921cb0ef41Sopenharmony_ci  const p1 = reader.read(new Uint8Array(16)).then(result => {
17931cb0ef41Sopenharmony_ci    assert_false(result.done, '2nd read: done');
17941cb0ef41Sopenharmony_ci
17951cb0ef41Sopenharmony_ci    const view = result.value;
17961cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 16, '2nd read: buffer.byteLength');
17971cb0ef41Sopenharmony_ci    assert_equals(view.byteOffset, 0, '2nd read: byteOffset');
17981cb0ef41Sopenharmony_ci    assert_equals(view.byteLength, 8, '2nd read: byteLength');
17991cb0ef41Sopenharmony_ci  });
18001cb0ef41Sopenharmony_ci
18011cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array(24));
18021cb0ef41Sopenharmony_ci
18031cb0ef41Sopenharmony_ci  return Promise.all([p0, p1]);
18041cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Multiple read(view), big enqueue()');
18051cb0ef41Sopenharmony_ci
18061cb0ef41Sopenharmony_cipromise_test(t => {
18071cb0ef41Sopenharmony_ci  let controller;
18081cb0ef41Sopenharmony_ci
18091cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
18101cb0ef41Sopenharmony_ci    start(c) {
18111cb0ef41Sopenharmony_ci      controller = c;
18121cb0ef41Sopenharmony_ci    },
18131cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
18141cb0ef41Sopenharmony_ci    type: 'bytes'
18151cb0ef41Sopenharmony_ci  });
18161cb0ef41Sopenharmony_ci
18171cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
18181cb0ef41Sopenharmony_ci
18191cb0ef41Sopenharmony_ci  let bytesRead = 0;
18201cb0ef41Sopenharmony_ci
18211cb0ef41Sopenharmony_ci  function pump() {
18221cb0ef41Sopenharmony_ci    return reader.read(new Uint8Array(7)).then(result => {
18231cb0ef41Sopenharmony_ci      if (result.done) {
18241cb0ef41Sopenharmony_ci        assert_equals(bytesRead, 1024);
18251cb0ef41Sopenharmony_ci        return undefined;
18261cb0ef41Sopenharmony_ci      }
18271cb0ef41Sopenharmony_ci
18281cb0ef41Sopenharmony_ci      bytesRead += result.value.byteLength;
18291cb0ef41Sopenharmony_ci
18301cb0ef41Sopenharmony_ci      return pump();
18311cb0ef41Sopenharmony_ci    });
18321cb0ef41Sopenharmony_ci  }
18331cb0ef41Sopenharmony_ci  const promise = pump();
18341cb0ef41Sopenharmony_ci
18351cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array(512));
18361cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array(512));
18371cb0ef41Sopenharmony_ci  controller.close();
18381cb0ef41Sopenharmony_ci
18391cb0ef41Sopenharmony_ci  return promise;
18401cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Multiple read(view) and multiple enqueue()');
18411cb0ef41Sopenharmony_ci
18421cb0ef41Sopenharmony_cipromise_test(t => {
18431cb0ef41Sopenharmony_ci  let pullCalled = false;
18441cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
18451cb0ef41Sopenharmony_ci    pull(controller) {
18461cb0ef41Sopenharmony_ci      pullCalled = true;
18471cb0ef41Sopenharmony_ci    },
18481cb0ef41Sopenharmony_ci    type: 'bytes'
18491cb0ef41Sopenharmony_ci  });
18501cb0ef41Sopenharmony_ci
18511cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
18521cb0ef41Sopenharmony_ci
18531cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError, reader.read(), 'read() must fail')
18541cb0ef41Sopenharmony_ci      .then(() => assert_false(pullCalled, 'pull() must not have been called'));
18551cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view) with passing undefined as view must fail');
18561cb0ef41Sopenharmony_ci
18571cb0ef41Sopenharmony_cipromise_test(t => {
18581cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
18591cb0ef41Sopenharmony_ci    type: 'bytes'
18601cb0ef41Sopenharmony_ci  });
18611cb0ef41Sopenharmony_ci
18621cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
18631cb0ef41Sopenharmony_ci
18641cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError, reader.read({}), 'read(view) must fail');
18651cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view) with passing an empty object as view must fail');
18661cb0ef41Sopenharmony_ci
18671cb0ef41Sopenharmony_cipromise_test(t => {
18681cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
18691cb0ef41Sopenharmony_ci    type: 'bytes'
18701cb0ef41Sopenharmony_ci  });
18711cb0ef41Sopenharmony_ci
18721cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
18731cb0ef41Sopenharmony_ci
18741cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError,
18751cb0ef41Sopenharmony_ci                         reader.read({ buffer: new ArrayBuffer(10), byteOffset: 0, byteLength: 10 }),
18761cb0ef41Sopenharmony_ci                         'read(view) must fail');
18771cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Even read(view) with passing ArrayBufferView like object as view must fail');
18781cb0ef41Sopenharmony_ci
18791cb0ef41Sopenharmony_cipromise_test(t => {
18801cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
18811cb0ef41Sopenharmony_ci    start(c) {
18821cb0ef41Sopenharmony_ci      c.error(error1);
18831cb0ef41Sopenharmony_ci    },
18841cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
18851cb0ef41Sopenharmony_ci    type: 'bytes'
18861cb0ef41Sopenharmony_ci  });
18871cb0ef41Sopenharmony_ci
18881cb0ef41Sopenharmony_ci  const reader = stream.getReader();
18891cb0ef41Sopenharmony_ci
18901cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, error1, reader.read(), 'read() must fail');
18911cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read() on an errored stream');
18921cb0ef41Sopenharmony_ci
18931cb0ef41Sopenharmony_cipromise_test(t => {
18941cb0ef41Sopenharmony_ci  let controller;
18951cb0ef41Sopenharmony_ci
18961cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
18971cb0ef41Sopenharmony_ci    start(c) {
18981cb0ef41Sopenharmony_ci      controller = c;
18991cb0ef41Sopenharmony_ci    },
19001cb0ef41Sopenharmony_ci    type: 'bytes'
19011cb0ef41Sopenharmony_ci  });
19021cb0ef41Sopenharmony_ci
19031cb0ef41Sopenharmony_ci  const reader = stream.getReader();
19041cb0ef41Sopenharmony_ci
19051cb0ef41Sopenharmony_ci  const promise = promise_rejects_exactly(t, error1, reader.read(), 'read() must fail');
19061cb0ef41Sopenharmony_ci
19071cb0ef41Sopenharmony_ci  controller.error(error1);
19081cb0ef41Sopenharmony_ci
19091cb0ef41Sopenharmony_ci  return promise;
19101cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(), then error()');
19111cb0ef41Sopenharmony_ci
19121cb0ef41Sopenharmony_cipromise_test(t => {
19131cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
19141cb0ef41Sopenharmony_ci    start(c) {
19151cb0ef41Sopenharmony_ci      c.error(error1);
19161cb0ef41Sopenharmony_ci    },
19171cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
19181cb0ef41Sopenharmony_ci    type: 'bytes'
19191cb0ef41Sopenharmony_ci  });
19201cb0ef41Sopenharmony_ci
19211cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
19221cb0ef41Sopenharmony_ci
19231cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, error1, reader.read(new Uint8Array(1)), 'read() must fail');
19241cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view) on an errored stream');
19251cb0ef41Sopenharmony_ci
19261cb0ef41Sopenharmony_cipromise_test(t => {
19271cb0ef41Sopenharmony_ci  let controller;
19281cb0ef41Sopenharmony_ci
19291cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
19301cb0ef41Sopenharmony_ci    start(c) {
19311cb0ef41Sopenharmony_ci      controller = c;
19321cb0ef41Sopenharmony_ci    },
19331cb0ef41Sopenharmony_ci    type: 'bytes'
19341cb0ef41Sopenharmony_ci  });
19351cb0ef41Sopenharmony_ci
19361cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
19371cb0ef41Sopenharmony_ci
19381cb0ef41Sopenharmony_ci  const promise = promise_rejects_exactly(t, error1, reader.read(new Uint8Array(1)), 'read() must fail');
19391cb0ef41Sopenharmony_ci
19401cb0ef41Sopenharmony_ci  controller.error(error1);
19411cb0ef41Sopenharmony_ci
19421cb0ef41Sopenharmony_ci  return promise;
19431cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view), then error()');
19441cb0ef41Sopenharmony_ci
19451cb0ef41Sopenharmony_cipromise_test(t => {
19461cb0ef41Sopenharmony_ci  let controller;
19471cb0ef41Sopenharmony_ci  let byobRequest;
19481cb0ef41Sopenharmony_ci
19491cb0ef41Sopenharmony_ci  const testError = new TypeError('foo');
19501cb0ef41Sopenharmony_ci
19511cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
19521cb0ef41Sopenharmony_ci    start(c) {
19531cb0ef41Sopenharmony_ci      controller = c;
19541cb0ef41Sopenharmony_ci    },
19551cb0ef41Sopenharmony_ci    pull() {
19561cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
19571cb0ef41Sopenharmony_ci      throw testError;
19581cb0ef41Sopenharmony_ci    },
19591cb0ef41Sopenharmony_ci    type: 'bytes'
19601cb0ef41Sopenharmony_ci  });
19611cb0ef41Sopenharmony_ci
19621cb0ef41Sopenharmony_ci  const reader = stream.getReader();
19631cb0ef41Sopenharmony_ci
19641cb0ef41Sopenharmony_ci  const promise = promise_rejects_exactly(t, testError, reader.read(), 'read() must fail');
19651cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, testError, promise.then(() => reader.closed))
19661cb0ef41Sopenharmony_ci      .then(() => assert_equals(byobRequest, null, 'byobRequest must be null'));
19671cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Throwing in pull function must error the stream');
19681cb0ef41Sopenharmony_ci
19691cb0ef41Sopenharmony_cipromise_test(t => {
19701cb0ef41Sopenharmony_ci  let byobRequest;
19711cb0ef41Sopenharmony_ci
19721cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
19731cb0ef41Sopenharmony_ci    pull(controller) {
19741cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
19751cb0ef41Sopenharmony_ci      controller.error(error1);
19761cb0ef41Sopenharmony_ci      throw new TypeError('foo');
19771cb0ef41Sopenharmony_ci    },
19781cb0ef41Sopenharmony_ci    type: 'bytes'
19791cb0ef41Sopenharmony_ci  });
19801cb0ef41Sopenharmony_ci
19811cb0ef41Sopenharmony_ci  const reader = stream.getReader();
19821cb0ef41Sopenharmony_ci
19831cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, error1, reader.read(), 'read() must fail')
19841cb0ef41Sopenharmony_ci      .then(() => promise_rejects_exactly(t, error1, reader.closed, 'closed must fail'))
19851cb0ef41Sopenharmony_ci      .then(() => assert_equals(byobRequest, null, 'byobRequest must be null'));
19861cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Throwing in pull in response to read() must be ignored if the stream is ' +
19871cb0ef41Sopenharmony_ci   'errored in it');
19881cb0ef41Sopenharmony_ci
19891cb0ef41Sopenharmony_cipromise_test(t => {
19901cb0ef41Sopenharmony_ci  let byobRequest;
19911cb0ef41Sopenharmony_ci
19921cb0ef41Sopenharmony_ci  const testError = new TypeError('foo');
19931cb0ef41Sopenharmony_ci
19941cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
19951cb0ef41Sopenharmony_ci    pull(controller) {
19961cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
19971cb0ef41Sopenharmony_ci      throw testError;
19981cb0ef41Sopenharmony_ci    },
19991cb0ef41Sopenharmony_ci    type: 'bytes'
20001cb0ef41Sopenharmony_ci  });
20011cb0ef41Sopenharmony_ci
20021cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
20031cb0ef41Sopenharmony_ci
20041cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, testError, reader.read(new Uint8Array(1)), 'read(view) must fail')
20051cb0ef41Sopenharmony_ci      .then(() => promise_rejects_exactly(t, testError, reader.closed, 'reader.closed must reject'))
20061cb0ef41Sopenharmony_ci      .then(() => assert_not_equals(byobRequest, null, 'byobRequest must not be null'));
20071cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Throwing in pull in response to read(view) function must error the stream');
20081cb0ef41Sopenharmony_ci
20091cb0ef41Sopenharmony_cipromise_test(t => {
20101cb0ef41Sopenharmony_ci  let byobRequest;
20111cb0ef41Sopenharmony_ci
20121cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
20131cb0ef41Sopenharmony_ci    pull(controller) {
20141cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
20151cb0ef41Sopenharmony_ci      controller.error(error1);
20161cb0ef41Sopenharmony_ci      throw new TypeError('foo');
20171cb0ef41Sopenharmony_ci    },
20181cb0ef41Sopenharmony_ci    type: 'bytes'
20191cb0ef41Sopenharmony_ci  });
20201cb0ef41Sopenharmony_ci
20211cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
20221cb0ef41Sopenharmony_ci
20231cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, error1, reader.read(new Uint8Array(1)), 'read(view) must fail')
20241cb0ef41Sopenharmony_ci      .then(() => promise_rejects_exactly(t, error1, reader.closed, 'closed must fail'))
20251cb0ef41Sopenharmony_ci      .then(() => assert_not_equals(byobRequest, null, 'byobRequest must not be null'));
20261cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: Throwing in pull in response to read(view) must be ignored if the stream is ' +
20271cb0ef41Sopenharmony_ci   'errored in it');
20281cb0ef41Sopenharmony_ci
20291cb0ef41Sopenharmony_cipromise_test(() => {
20301cb0ef41Sopenharmony_ci  let byobRequest;
20311cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
20321cb0ef41Sopenharmony_ci    pull(controller) {
20331cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
20341cb0ef41Sopenharmony_ci      byobRequest.respond(4);
20351cb0ef41Sopenharmony_ci    },
20361cb0ef41Sopenharmony_ci    type: 'bytes'
20371cb0ef41Sopenharmony_ci  });
20381cb0ef41Sopenharmony_ci  const reader = rs.getReader({ mode: 'byob' });
20391cb0ef41Sopenharmony_ci  const view = new Uint8Array(16);
20401cb0ef41Sopenharmony_ci  return reader.read(view).then(() => {
20411cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => byobRequest.respond(4), 'respond() should throw a TypeError');
20421cb0ef41Sopenharmony_ci  });
20431cb0ef41Sopenharmony_ci}, 'calling respond() twice on the same byobRequest should throw');
20441cb0ef41Sopenharmony_ci
20451cb0ef41Sopenharmony_cipromise_test(() => {
20461cb0ef41Sopenharmony_ci  let byobRequest;
20471cb0ef41Sopenharmony_ci  const newView = () => new Uint8Array(16);
20481cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
20491cb0ef41Sopenharmony_ci    pull(controller) {
20501cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
20511cb0ef41Sopenharmony_ci      byobRequest.respondWithNewView(newView());
20521cb0ef41Sopenharmony_ci    },
20531cb0ef41Sopenharmony_ci    type: 'bytes'
20541cb0ef41Sopenharmony_ci  });
20551cb0ef41Sopenharmony_ci  const reader = rs.getReader({ mode: 'byob' });
20561cb0ef41Sopenharmony_ci  return reader.read(newView()).then(() => {
20571cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => byobRequest.respondWithNewView(newView()),
20581cb0ef41Sopenharmony_ci                     'respondWithNewView() should throw a TypeError');
20591cb0ef41Sopenharmony_ci  });
20601cb0ef41Sopenharmony_ci}, 'calling respondWithNewView() twice on the same byobRequest should throw');
20611cb0ef41Sopenharmony_ci
20621cb0ef41Sopenharmony_cipromise_test(() => {
20631cb0ef41Sopenharmony_ci  let controller;
20641cb0ef41Sopenharmony_ci  let byobRequest;
20651cb0ef41Sopenharmony_ci  let resolvePullCalledPromise;
20661cb0ef41Sopenharmony_ci  const pullCalledPromise = new Promise(resolve => {
20671cb0ef41Sopenharmony_ci    resolvePullCalledPromise = resolve;
20681cb0ef41Sopenharmony_ci  });
20691cb0ef41Sopenharmony_ci  let resolvePull;
20701cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
20711cb0ef41Sopenharmony_ci    start(c) {
20721cb0ef41Sopenharmony_ci      controller = c;
20731cb0ef41Sopenharmony_ci    },
20741cb0ef41Sopenharmony_ci    pull(c) {
20751cb0ef41Sopenharmony_ci      byobRequest = c.byobRequest;
20761cb0ef41Sopenharmony_ci      resolvePullCalledPromise();
20771cb0ef41Sopenharmony_ci      return new Promise(resolve => {
20781cb0ef41Sopenharmony_ci        resolvePull = resolve;
20791cb0ef41Sopenharmony_ci      });
20801cb0ef41Sopenharmony_ci    },
20811cb0ef41Sopenharmony_ci    type: 'bytes'
20821cb0ef41Sopenharmony_ci  });
20831cb0ef41Sopenharmony_ci  const reader = rs.getReader({ mode: 'byob' });
20841cb0ef41Sopenharmony_ci  const readPromise = reader.read(new Uint8Array(16));
20851cb0ef41Sopenharmony_ci  return pullCalledPromise.then(() => {
20861cb0ef41Sopenharmony_ci    controller.close();
20871cb0ef41Sopenharmony_ci    byobRequest.respond(0);
20881cb0ef41Sopenharmony_ci    resolvePull();
20891cb0ef41Sopenharmony_ci    return readPromise.then(() => {
20901cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => byobRequest.respond(0), 'respond() should throw');
20911cb0ef41Sopenharmony_ci    });
20921cb0ef41Sopenharmony_ci  });
20931cb0ef41Sopenharmony_ci}, 'calling respond(0) twice on the same byobRequest should throw even when closed');
20941cb0ef41Sopenharmony_ci
20951cb0ef41Sopenharmony_cipromise_test(() => {
20961cb0ef41Sopenharmony_ci  let controller;
20971cb0ef41Sopenharmony_ci  let byobRequest;
20981cb0ef41Sopenharmony_ci  let resolvePullCalledPromise;
20991cb0ef41Sopenharmony_ci  const pullCalledPromise = new Promise(resolve => {
21001cb0ef41Sopenharmony_ci    resolvePullCalledPromise = resolve;
21011cb0ef41Sopenharmony_ci  });
21021cb0ef41Sopenharmony_ci  let resolvePull;
21031cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
21041cb0ef41Sopenharmony_ci    start(c) {
21051cb0ef41Sopenharmony_ci      controller = c;
21061cb0ef41Sopenharmony_ci    },
21071cb0ef41Sopenharmony_ci    pull(c) {
21081cb0ef41Sopenharmony_ci      byobRequest = c.byobRequest;
21091cb0ef41Sopenharmony_ci      resolvePullCalledPromise();
21101cb0ef41Sopenharmony_ci      return new Promise(resolve => {
21111cb0ef41Sopenharmony_ci        resolvePull = resolve;
21121cb0ef41Sopenharmony_ci      });
21131cb0ef41Sopenharmony_ci    },
21141cb0ef41Sopenharmony_ci    type: 'bytes'
21151cb0ef41Sopenharmony_ci  });
21161cb0ef41Sopenharmony_ci  const reader = rs.getReader({ mode: 'byob' });
21171cb0ef41Sopenharmony_ci  const readPromise = reader.read(new Uint8Array(16));
21181cb0ef41Sopenharmony_ci  return pullCalledPromise.then(() => {
21191cb0ef41Sopenharmony_ci    const cancelPromise = reader.cancel('meh');
21201cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => byobRequest.respond(0), 'respond() should throw');
21211cb0ef41Sopenharmony_ci    resolvePull();
21221cb0ef41Sopenharmony_ci    return Promise.all([readPromise, cancelPromise]);
21231cb0ef41Sopenharmony_ci  });
21241cb0ef41Sopenharmony_ci}, 'calling respond() should throw when canceled');
21251cb0ef41Sopenharmony_ci
21261cb0ef41Sopenharmony_cipromise_test(async t => {
21271cb0ef41Sopenharmony_ci  let resolvePullCalledPromise;
21281cb0ef41Sopenharmony_ci  const pullCalledPromise = new Promise(resolve => {
21291cb0ef41Sopenharmony_ci    resolvePullCalledPromise = resolve;
21301cb0ef41Sopenharmony_ci  });
21311cb0ef41Sopenharmony_ci  let resolvePull;
21321cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
21331cb0ef41Sopenharmony_ci    pull() {
21341cb0ef41Sopenharmony_ci      resolvePullCalledPromise();
21351cb0ef41Sopenharmony_ci      return new Promise(resolve => {
21361cb0ef41Sopenharmony_ci        resolvePull = resolve;
21371cb0ef41Sopenharmony_ci      });
21381cb0ef41Sopenharmony_ci    },
21391cb0ef41Sopenharmony_ci    type: 'bytes'
21401cb0ef41Sopenharmony_ci  });
21411cb0ef41Sopenharmony_ci  const reader = rs.getReader({ mode: 'byob' });
21421cb0ef41Sopenharmony_ci  const read = reader.read(new Uint8Array(16));
21431cb0ef41Sopenharmony_ci  await pullCalledPromise;
21441cb0ef41Sopenharmony_ci  resolvePull();
21451cb0ef41Sopenharmony_ci  await delay(0);
21461cb0ef41Sopenharmony_ci  reader.releaseLock();
21471cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read, 'pending read should reject');
21481cb0ef41Sopenharmony_ci}, 'pull() resolving should not resolve read()');
21491cb0ef41Sopenharmony_ci
21501cb0ef41Sopenharmony_cipromise_test(() => {
21511cb0ef41Sopenharmony_ci  // Tests https://github.com/whatwg/streams/issues/686
21521cb0ef41Sopenharmony_ci
21531cb0ef41Sopenharmony_ci  let controller;
21541cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
21551cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 128,
21561cb0ef41Sopenharmony_ci    start(c) {
21571cb0ef41Sopenharmony_ci      controller = c;
21581cb0ef41Sopenharmony_ci    },
21591cb0ef41Sopenharmony_ci    type: 'bytes'
21601cb0ef41Sopenharmony_ci  });
21611cb0ef41Sopenharmony_ci
21621cb0ef41Sopenharmony_ci  const readPromise = rs.getReader().read();
21631cb0ef41Sopenharmony_ci
21641cb0ef41Sopenharmony_ci  const br = controller.byobRequest;
21651cb0ef41Sopenharmony_ci  controller.close();
21661cb0ef41Sopenharmony_ci
21671cb0ef41Sopenharmony_ci  br.respond(0);
21681cb0ef41Sopenharmony_ci
21691cb0ef41Sopenharmony_ci  return readPromise;
21701cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: default reader + autoAllocateChunkSize + byobRequest interaction');
21711cb0ef41Sopenharmony_ci
21721cb0ef41Sopenharmony_citest(() => {
21731cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => new ReadableStream({ autoAllocateChunkSize: 0, type: 'bytes' }),
21741cb0ef41Sopenharmony_ci      'controller cannot be setup with autoAllocateChunkSize = 0');
21751cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: autoAllocateChunkSize cannot be 0');
21761cb0ef41Sopenharmony_ci
21771cb0ef41Sopenharmony_citest(() => {
21781cb0ef41Sopenharmony_ci  const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
21791cb0ef41Sopenharmony_ci  const stream = new ReadableStream({ type: 'bytes' });
21801cb0ef41Sopenharmony_ci  new ReadableStreamBYOBReader(stream);
21811cb0ef41Sopenharmony_ci}, 'ReadableStreamBYOBReader can be constructed directly');
21821cb0ef41Sopenharmony_ci
21831cb0ef41Sopenharmony_citest(() => {
21841cb0ef41Sopenharmony_ci  const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
21851cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => new ReadableStreamBYOBReader({}), 'constructor must throw');
21861cb0ef41Sopenharmony_ci}, 'ReadableStreamBYOBReader constructor requires a ReadableStream argument');
21871cb0ef41Sopenharmony_ci
21881cb0ef41Sopenharmony_citest(() => {
21891cb0ef41Sopenharmony_ci  const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
21901cb0ef41Sopenharmony_ci  const stream = new ReadableStream({ type: 'bytes' });
21911cb0ef41Sopenharmony_ci  stream.getReader();
21921cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => new ReadableStreamBYOBReader(stream), 'constructor must throw');
21931cb0ef41Sopenharmony_ci}, 'ReadableStreamBYOBReader constructor requires an unlocked ReadableStream');
21941cb0ef41Sopenharmony_ci
21951cb0ef41Sopenharmony_citest(() => {
21961cb0ef41Sopenharmony_ci  const ReadableStreamBYOBReader = new ReadableStream({ type: 'bytes' }).getReader({ mode: 'byob' }).constructor;
21971cb0ef41Sopenharmony_ci  const stream = new ReadableStream();
21981cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => new ReadableStreamBYOBReader(stream), 'constructor must throw');
21991cb0ef41Sopenharmony_ci}, 'ReadableStreamBYOBReader constructor requires a ReadableStream with type "bytes"');
22001cb0ef41Sopenharmony_ci
22011cb0ef41Sopenharmony_citest(() => {
22021cb0ef41Sopenharmony_ci  assert_throws_js(RangeError, () => new ReadableStream({ type: 'bytes' }, {
22031cb0ef41Sopenharmony_ci    size() {
22041cb0ef41Sopenharmony_ci      return 1;
22051cb0ef41Sopenharmony_ci    }
22061cb0ef41Sopenharmony_ci  }), 'constructor should throw for size function');
22071cb0ef41Sopenharmony_ci
22081cb0ef41Sopenharmony_ci  assert_throws_js(RangeError,
22091cb0ef41Sopenharmony_ci                   () => new ReadableStream({ type: 'bytes' }, new CountQueuingStrategy({ highWaterMark: 1 })),
22101cb0ef41Sopenharmony_ci                   'constructor should throw when strategy is CountQueuingStrategy');
22111cb0ef41Sopenharmony_ci
22121cb0ef41Sopenharmony_ci  assert_throws_js(RangeError,
22131cb0ef41Sopenharmony_ci                   () => new ReadableStream({ type: 'bytes' }, new ByteLengthQueuingStrategy({ highWaterMark: 512 })),
22141cb0ef41Sopenharmony_ci                   'constructor should throw when strategy is ByteLengthQueuingStrategy');
22151cb0ef41Sopenharmony_ci
22161cb0ef41Sopenharmony_ci  class HasSizeMethod {
22171cb0ef41Sopenharmony_ci    size() {}
22181cb0ef41Sopenharmony_ci }
22191cb0ef41Sopenharmony_ci
22201cb0ef41Sopenharmony_ci  assert_throws_js(RangeError, () => new ReadableStream({ type: 'bytes' }, new HasSizeMethod()),
22211cb0ef41Sopenharmony_ci                   'constructor should throw when size on the prototype chain');
22221cb0ef41Sopenharmony_ci}, 'ReadableStream constructor should not accept a strategy with a size defined if type is "bytes"');
22231cb0ef41Sopenharmony_ci
22241cb0ef41Sopenharmony_cipromise_test(async t => {
22251cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
22261cb0ef41Sopenharmony_ci    pull: t.step_func(c => {
22271cb0ef41Sopenharmony_ci      const view = new Uint8Array(c.byobRequest.view.buffer, 0, 1);
22281cb0ef41Sopenharmony_ci      view[0] = 1;
22291cb0ef41Sopenharmony_ci
22301cb0ef41Sopenharmony_ci      c.byobRequest.respondWithNewView(view);
22311cb0ef41Sopenharmony_ci    }),
22321cb0ef41Sopenharmony_ci    type: 'bytes'
22331cb0ef41Sopenharmony_ci  });
22341cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
22351cb0ef41Sopenharmony_ci
22361cb0ef41Sopenharmony_ci  const result = await reader.read(new Uint8Array([4, 5, 6]));
22371cb0ef41Sopenharmony_ci  assert_false(result.done, 'result.done');
22381cb0ef41Sopenharmony_ci
22391cb0ef41Sopenharmony_ci  const view = result.value;
22401cb0ef41Sopenharmony_ci  assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
22411cb0ef41Sopenharmony_ci  assert_equals(view.byteLength, 1, 'result.value.byteLength');
22421cb0ef41Sopenharmony_ci  assert_equals(view[0], 1, 'result.value[0]');
22431cb0ef41Sopenharmony_ci  assert_equals(view.buffer.byteLength, 3, 'result.value.buffer.byteLength');
22441cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(view.buffer)], [1, 5, 6], 'result.value.buffer');
22451cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() with a smaller view');
22461cb0ef41Sopenharmony_ci
22471cb0ef41Sopenharmony_cipromise_test(async t => {
22481cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
22491cb0ef41Sopenharmony_ci    pull: t.step_func(c => {
22501cb0ef41Sopenharmony_ci      const view = new Uint8Array(c.byobRequest.view.buffer, 0, 0);
22511cb0ef41Sopenharmony_ci
22521cb0ef41Sopenharmony_ci      c.close();
22531cb0ef41Sopenharmony_ci
22541cb0ef41Sopenharmony_ci      c.byobRequest.respondWithNewView(view);
22551cb0ef41Sopenharmony_ci    }),
22561cb0ef41Sopenharmony_ci    type: 'bytes'
22571cb0ef41Sopenharmony_ci  });
22581cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
22591cb0ef41Sopenharmony_ci
22601cb0ef41Sopenharmony_ci  const result = await reader.read(new Uint8Array([4, 5, 6]));
22611cb0ef41Sopenharmony_ci  assert_true(result.done, 'result.done');
22621cb0ef41Sopenharmony_ci
22631cb0ef41Sopenharmony_ci  const view = result.value;
22641cb0ef41Sopenharmony_ci  assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
22651cb0ef41Sopenharmony_ci  assert_equals(view.byteLength, 0, 'result.value.byteLength');
22661cb0ef41Sopenharmony_ci  assert_equals(view.buffer.byteLength, 3, 'result.value.buffer.byteLength');
22671cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(view.buffer)], [4, 5, 6], 'result.value.buffer');
22681cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() with a zero-length view (in the closed state)');
22691cb0ef41Sopenharmony_ci
22701cb0ef41Sopenharmony_cipromise_test(async t => {
22711cb0ef41Sopenharmony_ci  let controller;
22721cb0ef41Sopenharmony_ci  let resolvePullCalledPromise;
22731cb0ef41Sopenharmony_ci  const pullCalledPromise = new Promise(resolve => {
22741cb0ef41Sopenharmony_ci    resolvePullCalledPromise = resolve;
22751cb0ef41Sopenharmony_ci  });
22761cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
22771cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
22781cb0ef41Sopenharmony_ci      controller = c;
22791cb0ef41Sopenharmony_ci    }),
22801cb0ef41Sopenharmony_ci    pull: t.step_func(() => {
22811cb0ef41Sopenharmony_ci      resolvePullCalledPromise();
22821cb0ef41Sopenharmony_ci    }),
22831cb0ef41Sopenharmony_ci    type: 'bytes'
22841cb0ef41Sopenharmony_ci  });
22851cb0ef41Sopenharmony_ci
22861cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
22871cb0ef41Sopenharmony_ci  const readPromise = reader.read(new Uint8Array([4, 5, 6]));
22881cb0ef41Sopenharmony_ci  await pullCalledPromise;
22891cb0ef41Sopenharmony_ci
22901cb0ef41Sopenharmony_ci  // Transfer the original BYOB request's buffer, and respond with a new view on that buffer
22911cb0ef41Sopenharmony_ci  const transferredView = await transferArrayBufferView(controller.byobRequest.view);
22921cb0ef41Sopenharmony_ci  const newView = transferredView.subarray(0, 1);
22931cb0ef41Sopenharmony_ci  newView[0] = 42;
22941cb0ef41Sopenharmony_ci
22951cb0ef41Sopenharmony_ci  controller.byobRequest.respondWithNewView(newView);
22961cb0ef41Sopenharmony_ci
22971cb0ef41Sopenharmony_ci  const result = await readPromise;
22981cb0ef41Sopenharmony_ci  assert_false(result.done, 'result.done');
22991cb0ef41Sopenharmony_ci
23001cb0ef41Sopenharmony_ci  const view = result.value;
23011cb0ef41Sopenharmony_ci  assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
23021cb0ef41Sopenharmony_ci  assert_equals(view.byteLength, 1, 'result.value.byteLength');
23031cb0ef41Sopenharmony_ci  assert_equals(view[0], 42, 'result.value[0]');
23041cb0ef41Sopenharmony_ci  assert_equals(view.buffer.byteLength, 3, 'result.value.buffer.byteLength');
23051cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(view.buffer)], [42, 5, 6], 'result.value.buffer');
23061cb0ef41Sopenharmony_ci
23071cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() with a transferred non-zero-length view ' +
23081cb0ef41Sopenharmony_ci   '(in the readable state)');
23091cb0ef41Sopenharmony_ci
23101cb0ef41Sopenharmony_cipromise_test(async t => {
23111cb0ef41Sopenharmony_ci  let controller;
23121cb0ef41Sopenharmony_ci  let resolvePullCalledPromise;
23131cb0ef41Sopenharmony_ci  const pullCalledPromise = new Promise(resolve => {
23141cb0ef41Sopenharmony_ci    resolvePullCalledPromise = resolve;
23151cb0ef41Sopenharmony_ci  });
23161cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
23171cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
23181cb0ef41Sopenharmony_ci      controller = c;
23191cb0ef41Sopenharmony_ci    }),
23201cb0ef41Sopenharmony_ci    pull: t.step_func(() => {
23211cb0ef41Sopenharmony_ci      resolvePullCalledPromise();
23221cb0ef41Sopenharmony_ci    }),
23231cb0ef41Sopenharmony_ci    type: 'bytes'
23241cb0ef41Sopenharmony_ci  });
23251cb0ef41Sopenharmony_ci
23261cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
23271cb0ef41Sopenharmony_ci  const readPromise = reader.read(new Uint8Array([4, 5, 6]));
23281cb0ef41Sopenharmony_ci  await pullCalledPromise;
23291cb0ef41Sopenharmony_ci
23301cb0ef41Sopenharmony_ci  // Transfer the original BYOB request's buffer, and respond with an empty view on that buffer
23311cb0ef41Sopenharmony_ci  const transferredView = await transferArrayBufferView(controller.byobRequest.view);
23321cb0ef41Sopenharmony_ci  const newView = transferredView.subarray(0, 0);
23331cb0ef41Sopenharmony_ci
23341cb0ef41Sopenharmony_ci  controller.close();
23351cb0ef41Sopenharmony_ci  controller.byobRequest.respondWithNewView(newView);
23361cb0ef41Sopenharmony_ci
23371cb0ef41Sopenharmony_ci  const result = await readPromise;
23381cb0ef41Sopenharmony_ci  assert_true(result.done, 'result.done');
23391cb0ef41Sopenharmony_ci
23401cb0ef41Sopenharmony_ci  const view = result.value;
23411cb0ef41Sopenharmony_ci  assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
23421cb0ef41Sopenharmony_ci  assert_equals(view.byteLength, 0, 'result.value.byteLength');
23431cb0ef41Sopenharmony_ci  assert_equals(view.buffer.byteLength, 3, 'result.value.buffer.byteLength');
23441cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(view.buffer)], [4, 5, 6], 'result.value.buffer');
23451cb0ef41Sopenharmony_ci
23461cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() with a transferred zero-length view ' +
23471cb0ef41Sopenharmony_ci   '(in the closed state)');
23481cb0ef41Sopenharmony_ci
23491cb0ef41Sopenharmony_cipromise_test(async t => {
23501cb0ef41Sopenharmony_ci  let controller;
23511cb0ef41Sopenharmony_ci  let pullCount = 0;
23521cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
23531cb0ef41Sopenharmony_ci    type: 'bytes',
23541cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 10,
23551cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
23561cb0ef41Sopenharmony_ci      controller = c;
23571cb0ef41Sopenharmony_ci    }),
23581cb0ef41Sopenharmony_ci    pull: t.step_func(() => {
23591cb0ef41Sopenharmony_ci      ++pullCount;
23601cb0ef41Sopenharmony_ci    })
23611cb0ef41Sopenharmony_ci  });
23621cb0ef41Sopenharmony_ci
23631cb0ef41Sopenharmony_ci  await flushAsyncEvents();
23641cb0ef41Sopenharmony_ci  assert_equals(pullCount, 0, 'pull() must not have been invoked yet');
23651cb0ef41Sopenharmony_ci
23661cb0ef41Sopenharmony_ci  const reader1 = rs.getReader();
23671cb0ef41Sopenharmony_ci  const read1 = reader1.read();
23681cb0ef41Sopenharmony_ci  assert_equals(pullCount, 1, 'pull() must have been invoked once');
23691cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
23701cb0ef41Sopenharmony_ci  assert_equals(byobRequest1.view.byteLength, 10, 'first byobRequest.view.byteLength');
23711cb0ef41Sopenharmony_ci
23721cb0ef41Sopenharmony_ci  // enqueue() must discard the auto-allocated BYOB request
23731cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array([1, 2, 3]));
23741cb0ef41Sopenharmony_ci  assert_equals(byobRequest1.view, null, 'first byobRequest must be invalidated after enqueue()');
23751cb0ef41Sopenharmony_ci
23761cb0ef41Sopenharmony_ci  const result1 = await read1;
23771cb0ef41Sopenharmony_ci  assert_false(result1.done, 'first result.done');
23781cb0ef41Sopenharmony_ci  const view1 = result1.value;
23791cb0ef41Sopenharmony_ci  assert_equals(view1.byteOffset, 0, 'first result.value.byteOffset');
23801cb0ef41Sopenharmony_ci  assert_equals(view1.byteLength, 3, 'first result.value.byteLength');
23811cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(view1.buffer)], [1, 2, 3], 'first result.value.buffer');
23821cb0ef41Sopenharmony_ci
23831cb0ef41Sopenharmony_ci  reader1.releaseLock();
23841cb0ef41Sopenharmony_ci
23851cb0ef41Sopenharmony_ci  // read(view) should work after discarding the auto-allocated BYOB request
23861cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
23871cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint8Array([4, 5, 6]));
23881cb0ef41Sopenharmony_ci  assert_equals(pullCount, 2, 'pull() must have been invoked twice');
23891cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
23901cb0ef41Sopenharmony_ci  assert_equals(byobRequest2.view.byteOffset, 0, 'second byobRequest.view.byteOffset');
23911cb0ef41Sopenharmony_ci  assert_equals(byobRequest2.view.byteLength, 3, 'second byobRequest.view.byteLength');
23921cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(byobRequest2.view.buffer)], [4, 5, 6], 'second byobRequest.view.buffer');
23931cb0ef41Sopenharmony_ci
23941cb0ef41Sopenharmony_ci  byobRequest2.respond(3);
23951cb0ef41Sopenharmony_ci  assert_equals(byobRequest2.view, null, 'second byobRequest must be invalidated after respond()');
23961cb0ef41Sopenharmony_ci
23971cb0ef41Sopenharmony_ci  const result2 = await read2;
23981cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
23991cb0ef41Sopenharmony_ci  const view2 = result2.value;
24001cb0ef41Sopenharmony_ci  assert_equals(view2.byteOffset, 0, 'second result.value.byteOffset');
24011cb0ef41Sopenharmony_ci  assert_equals(view2.byteLength, 3, 'second result.value.byteLength');
24021cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(view2.buffer)], [4, 5, 6], 'second result.value.buffer');
24031cb0ef41Sopenharmony_ci
24041cb0ef41Sopenharmony_ci  reader2.releaseLock();
24051cb0ef41Sopenharmony_ci  assert_equals(pullCount, 2, 'pull() must only have been invoked twice');
24061cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue() discards auto-allocated BYOB request');
24071cb0ef41Sopenharmony_ci
24081cb0ef41Sopenharmony_cipromise_test(async t => {
24091cb0ef41Sopenharmony_ci  let controller;
24101cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
24111cb0ef41Sopenharmony_ci    type: 'bytes',
24121cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
24131cb0ef41Sopenharmony_ci      controller = c;
24141cb0ef41Sopenharmony_ci    })
24151cb0ef41Sopenharmony_ci  });
24161cb0ef41Sopenharmony_ci  await flushAsyncEvents();
24171cb0ef41Sopenharmony_ci
24181cb0ef41Sopenharmony_ci  const reader1 = rs.getReader({ mode: 'byob' });
24191cb0ef41Sopenharmony_ci  const read1 = reader1.read(new Uint8Array([1, 2, 3]));
24201cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
24211cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
24221cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array([1, 2, 3]), 'first byobRequest.view');
24231cb0ef41Sopenharmony_ci
24241cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
24251cb0ef41Sopenharmony_ci  reader1.releaseLock();
24261cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
24271cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint8Array([4, 5, 6]));
24281cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
24291cb0ef41Sopenharmony_ci  assert_equals(controller.byobRequest, byobRequest1, 'byobRequest should be unchanged');
24301cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(byobRequest1.view.buffer)], [1, 2, 3], 'byobRequest.view.buffer should be unchanged');
24311cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
24321cb0ef41Sopenharmony_ci
24331cb0ef41Sopenharmony_ci  // respond() should fulfill the *second* read() request
24341cb0ef41Sopenharmony_ci  byobRequest1.view[0] = 11;
24351cb0ef41Sopenharmony_ci  byobRequest1.respond(1);
24361cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
24371cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after respond()');
24381cb0ef41Sopenharmony_ci
24391cb0ef41Sopenharmony_ci  const result2 = await read2;
24401cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
24411cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([11, 5, 6]).subarray(0, 1), 'second result.value');
24421cb0ef41Sopenharmony_ci
24431cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: releaseLock() with pending read(view), read(view) on second reader, respond()');
24441cb0ef41Sopenharmony_ci
24451cb0ef41Sopenharmony_cipromise_test(async t => {
24461cb0ef41Sopenharmony_ci  let controller;
24471cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
24481cb0ef41Sopenharmony_ci    type: 'bytes',
24491cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
24501cb0ef41Sopenharmony_ci      controller = c;
24511cb0ef41Sopenharmony_ci    })
24521cb0ef41Sopenharmony_ci  });
24531cb0ef41Sopenharmony_ci  await flushAsyncEvents();
24541cb0ef41Sopenharmony_ci
24551cb0ef41Sopenharmony_ci  const reader1 = rs.getReader({ mode: 'byob' });
24561cb0ef41Sopenharmony_ci  const read1 = reader1.read(new Uint8Array([1, 2, 3]));
24571cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
24581cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
24591cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array([1, 2, 3]), 'first byobRequest.view');
24601cb0ef41Sopenharmony_ci
24611cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
24621cb0ef41Sopenharmony_ci  reader1.releaseLock();
24631cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
24641cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint16Array(1));
24651cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
24661cb0ef41Sopenharmony_ci  assert_equals(controller.byobRequest, byobRequest1, 'byobRequest should be unchanged');
24671cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(byobRequest1.view.buffer)], [1, 2, 3], 'byobRequest.view.buffer should be unchanged');
24681cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
24691cb0ef41Sopenharmony_ci
24701cb0ef41Sopenharmony_ci  // respond(1) should partially fill the second read(), but not yet fulfill it
24711cb0ef41Sopenharmony_ci  byobRequest1.view[0] = 0x11;
24721cb0ef41Sopenharmony_ci  byobRequest1.respond(1);
24731cb0ef41Sopenharmony_ci
24741cb0ef41Sopenharmony_ci  // second BYOB request should use remaining buffer from the second read()
24751cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
24761cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest2, null, 'second byobRequest should exist');
24771cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest2.view, new Uint8Array([0x11, 0]).subarray(1, 2), 'second byobRequest.view');
24781cb0ef41Sopenharmony_ci
24791cb0ef41Sopenharmony_ci  // second respond(1) should fill the read request and fulfill it
24801cb0ef41Sopenharmony_ci  byobRequest2.view[0] = 0x22;
24811cb0ef41Sopenharmony_ci  byobRequest2.respond(1);
24821cb0ef41Sopenharmony_ci  const result2 = await read2;
24831cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
24841cb0ef41Sopenharmony_ci  const view2 = result2.value;
24851cb0ef41Sopenharmony_ci  assert_equals(view2.byteOffset, 0, 'second result.value.byteOffset');
24861cb0ef41Sopenharmony_ci  assert_equals(view2.byteLength, 2, 'second result.value.byteLength');
24871cb0ef41Sopenharmony_ci  const dataView2 = new DataView(view2.buffer, view2.byteOffset, view2.byteLength);
24881cb0ef41Sopenharmony_ci  assert_equals(dataView2.getUint16(0), 0x1122, 'second result.value[0]');
24891cb0ef41Sopenharmony_ci
24901cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: releaseLock() with pending read(view), read(view) on second reader with ' +
24911cb0ef41Sopenharmony_ci   '1 element Uint16Array, respond(1)');
24921cb0ef41Sopenharmony_ci
24931cb0ef41Sopenharmony_cipromise_test(async t => {
24941cb0ef41Sopenharmony_ci  let controller;
24951cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
24961cb0ef41Sopenharmony_ci    type: 'bytes',
24971cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
24981cb0ef41Sopenharmony_ci      controller = c;
24991cb0ef41Sopenharmony_ci    })
25001cb0ef41Sopenharmony_ci  });
25011cb0ef41Sopenharmony_ci  await flushAsyncEvents();
25021cb0ef41Sopenharmony_ci
25031cb0ef41Sopenharmony_ci  const reader1 = rs.getReader({ mode: 'byob' });
25041cb0ef41Sopenharmony_ci  const read1 = reader1.read(new Uint8Array([1, 2, 3]));
25051cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
25061cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
25071cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array([1, 2, 3]), 'first byobRequest.view');
25081cb0ef41Sopenharmony_ci
25091cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
25101cb0ef41Sopenharmony_ci  reader1.releaseLock();
25111cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
25121cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint8Array([4, 5]));
25131cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
25141cb0ef41Sopenharmony_ci  assert_equals(controller.byobRequest, byobRequest1, 'byobRequest should be unchanged');
25151cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(byobRequest1.view.buffer)], [1, 2, 3], 'byobRequest.view.buffer should be unchanged');
25161cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
25171cb0ef41Sopenharmony_ci
25181cb0ef41Sopenharmony_ci  // respond(3) should fulfill the second read(), and put 1 remaining byte in the queue
25191cb0ef41Sopenharmony_ci  byobRequest1.view[0] = 6;
25201cb0ef41Sopenharmony_ci  byobRequest1.view[1] = 7;
25211cb0ef41Sopenharmony_ci  byobRequest1.view[2] = 8;
25221cb0ef41Sopenharmony_ci  byobRequest1.respond(3);
25231cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
25241cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after respond()');
25251cb0ef41Sopenharmony_ci
25261cb0ef41Sopenharmony_ci  const result2 = await read2;
25271cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
25281cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([6, 7]), 'second result.value');
25291cb0ef41Sopenharmony_ci
25301cb0ef41Sopenharmony_ci  // third read() should fulfill with the remaining byte
25311cb0ef41Sopenharmony_ci  const result3 = await reader2.read(new Uint8Array([0, 0, 0]));
25321cb0ef41Sopenharmony_ci  assert_false(result3.done, 'third result.done');
25331cb0ef41Sopenharmony_ci  assert_typed_array_equals(result3.value, new Uint8Array([8, 0, 0]).subarray(0, 1), 'third result.value');
25341cb0ef41Sopenharmony_ci
25351cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: releaseLock() with pending read(view), read(view) on second reader with ' +
25361cb0ef41Sopenharmony_ci   '2 element Uint8Array, respond(3)');
25371cb0ef41Sopenharmony_ci
25381cb0ef41Sopenharmony_cipromise_test(async t => {
25391cb0ef41Sopenharmony_ci  let controller;
25401cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
25411cb0ef41Sopenharmony_ci    type: 'bytes',
25421cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
25431cb0ef41Sopenharmony_ci      controller = c;
25441cb0ef41Sopenharmony_ci    })
25451cb0ef41Sopenharmony_ci  });
25461cb0ef41Sopenharmony_ci  await flushAsyncEvents();
25471cb0ef41Sopenharmony_ci
25481cb0ef41Sopenharmony_ci  const reader1 = rs.getReader({ mode: 'byob' });
25491cb0ef41Sopenharmony_ci  const read1 = reader1.read(new Uint8Array([1, 2, 3]));
25501cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
25511cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
25521cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array([1, 2, 3]), 'first byobRequest.view');
25531cb0ef41Sopenharmony_ci
25541cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
25551cb0ef41Sopenharmony_ci  reader1.releaseLock();
25561cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
25571cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint8Array([4, 5, 6]));
25581cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
25591cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
25601cb0ef41Sopenharmony_ci
25611cb0ef41Sopenharmony_ci  // respondWithNewView() should fulfill the *second* read() request
25621cb0ef41Sopenharmony_ci  byobRequest1.view[0] = 11;
25631cb0ef41Sopenharmony_ci  byobRequest1.view[1] = 12;
25641cb0ef41Sopenharmony_ci  byobRequest1.respondWithNewView(byobRequest1.view.subarray(0, 2));
25651cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
25661cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after respondWithNewView()');
25671cb0ef41Sopenharmony_ci
25681cb0ef41Sopenharmony_ci  const result2 = await read2;
25691cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
25701cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([11, 12, 6]).subarray(0, 2), 'second result.value');
25711cb0ef41Sopenharmony_ci
25721cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: releaseLock() with pending read(view), read(view) on second reader, respondWithNewView()');
25731cb0ef41Sopenharmony_ci
25741cb0ef41Sopenharmony_cipromise_test(async t => {
25751cb0ef41Sopenharmony_ci  let controller;
25761cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
25771cb0ef41Sopenharmony_ci    type: 'bytes',
25781cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
25791cb0ef41Sopenharmony_ci      controller = c;
25801cb0ef41Sopenharmony_ci    })
25811cb0ef41Sopenharmony_ci  });
25821cb0ef41Sopenharmony_ci  await flushAsyncEvents();
25831cb0ef41Sopenharmony_ci
25841cb0ef41Sopenharmony_ci  const reader1 = rs.getReader({ mode: 'byob' });
25851cb0ef41Sopenharmony_ci  const read1 = reader1.read(new Uint8Array([1, 2, 3]));
25861cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
25871cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
25881cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array([1, 2, 3]), 'first byobRequest.view');
25891cb0ef41Sopenharmony_ci
25901cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
25911cb0ef41Sopenharmony_ci  reader1.releaseLock();
25921cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
25931cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint8Array([4, 5, 6]));
25941cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
25951cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
25961cb0ef41Sopenharmony_ci
25971cb0ef41Sopenharmony_ci  // enqueue() should fulfill the *second* read() request
25981cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array([11, 12]));
25991cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
26001cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after enqueue()');
26011cb0ef41Sopenharmony_ci
26021cb0ef41Sopenharmony_ci  const result2 = await read2;
26031cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
26041cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([11, 12, 6]).subarray(0, 2), 'second result.value');
26051cb0ef41Sopenharmony_ci
26061cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: releaseLock() with pending read(view), read(view) on second reader, enqueue()');
26071cb0ef41Sopenharmony_ci
26081cb0ef41Sopenharmony_cipromise_test(async t => {
26091cb0ef41Sopenharmony_ci  let controller;
26101cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
26111cb0ef41Sopenharmony_ci    type: 'bytes',
26121cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
26131cb0ef41Sopenharmony_ci      controller = c;
26141cb0ef41Sopenharmony_ci    })
26151cb0ef41Sopenharmony_ci  });
26161cb0ef41Sopenharmony_ci  await flushAsyncEvents();
26171cb0ef41Sopenharmony_ci
26181cb0ef41Sopenharmony_ci  const reader1 = rs.getReader({ mode: 'byob' });
26191cb0ef41Sopenharmony_ci  const read1 = reader1.read(new Uint8Array([1, 2, 3]));
26201cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
26211cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
26221cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array([1, 2, 3]), 'first byobRequest.view');
26231cb0ef41Sopenharmony_ci
26241cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
26251cb0ef41Sopenharmony_ci  reader1.releaseLock();
26261cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
26271cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint8Array([4, 5, 6]));
26281cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
26291cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
26301cb0ef41Sopenharmony_ci
26311cb0ef41Sopenharmony_ci  // close() followed by respond(0) should fulfill the second read()
26321cb0ef41Sopenharmony_ci  controller.close();
26331cb0ef41Sopenharmony_ci  byobRequest1.respond(0);
26341cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
26351cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after respond()');
26361cb0ef41Sopenharmony_ci
26371cb0ef41Sopenharmony_ci  const result2 = await read2;
26381cb0ef41Sopenharmony_ci  assert_true(result2.done, 'second result.done');
26391cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([4, 5, 6]).subarray(0, 0), 'second result.value');
26401cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: releaseLock() with pending read(view), read(view) on second reader, ' +
26411cb0ef41Sopenharmony_ci   'close(), respond(0)');
26421cb0ef41Sopenharmony_ci
26431cb0ef41Sopenharmony_cipromise_test(async t => {
26441cb0ef41Sopenharmony_ci  let controller;
26451cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
26461cb0ef41Sopenharmony_ci    type: 'bytes',
26471cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 4,
26481cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
26491cb0ef41Sopenharmony_ci      controller = c;
26501cb0ef41Sopenharmony_ci    })
26511cb0ef41Sopenharmony_ci  });
26521cb0ef41Sopenharmony_ci  await flushAsyncEvents();
26531cb0ef41Sopenharmony_ci
26541cb0ef41Sopenharmony_ci  const reader1 = rs.getReader();
26551cb0ef41Sopenharmony_ci  const read1 = reader1.read();
26561cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
26571cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
26581cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array(4), 'first byobRequest.view');
26591cb0ef41Sopenharmony_ci
26601cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
26611cb0ef41Sopenharmony_ci  reader1.releaseLock();
26621cb0ef41Sopenharmony_ci  const reader2 = rs.getReader();
26631cb0ef41Sopenharmony_ci  const read2 = reader2.read();
26641cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
26651cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
26661cb0ef41Sopenharmony_ci
26671cb0ef41Sopenharmony_ci  // respond() should fulfill the *second* read() request
26681cb0ef41Sopenharmony_ci  byobRequest1.view[0] = 11;
26691cb0ef41Sopenharmony_ci  byobRequest1.respond(1);
26701cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
26711cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after respond()');
26721cb0ef41Sopenharmony_ci
26731cb0ef41Sopenharmony_ci  const result2 = await read2;
26741cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
26751cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([11, 0, 0, 0]).subarray(0, 1), 'second result.value');
26761cb0ef41Sopenharmony_ci
26771cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: autoAllocateChunkSize, releaseLock() with pending read(), read() on second reader, respond()');
26781cb0ef41Sopenharmony_ci
26791cb0ef41Sopenharmony_cipromise_test(async t => {
26801cb0ef41Sopenharmony_ci  let controller;
26811cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
26821cb0ef41Sopenharmony_ci    type: 'bytes',
26831cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 4,
26841cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
26851cb0ef41Sopenharmony_ci      controller = c;
26861cb0ef41Sopenharmony_ci    })
26871cb0ef41Sopenharmony_ci  });
26881cb0ef41Sopenharmony_ci  await flushAsyncEvents();
26891cb0ef41Sopenharmony_ci
26901cb0ef41Sopenharmony_ci  const reader1 = rs.getReader();
26911cb0ef41Sopenharmony_ci  const read1 = reader1.read();
26921cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
26931cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
26941cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array(4), 'first byobRequest.view');
26951cb0ef41Sopenharmony_ci
26961cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
26971cb0ef41Sopenharmony_ci  reader1.releaseLock();
26981cb0ef41Sopenharmony_ci  const reader2 = rs.getReader();
26991cb0ef41Sopenharmony_ci  const read2 = reader2.read();
27001cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
27011cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
27021cb0ef41Sopenharmony_ci
27031cb0ef41Sopenharmony_ci  // enqueue() should fulfill the *second* read() request
27041cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array([11]));
27051cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
27061cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after enqueue()');
27071cb0ef41Sopenharmony_ci
27081cb0ef41Sopenharmony_ci  const result2 = await read2;
27091cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
27101cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([11]), 'second result.value');
27111cb0ef41Sopenharmony_ci
27121cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: autoAllocateChunkSize, releaseLock() with pending read(), read() on second reader, enqueue()');
27131cb0ef41Sopenharmony_ci
27141cb0ef41Sopenharmony_cipromise_test(async t => {
27151cb0ef41Sopenharmony_ci  let controller;
27161cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
27171cb0ef41Sopenharmony_ci    type: 'bytes',
27181cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 4,
27191cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
27201cb0ef41Sopenharmony_ci      controller = c;
27211cb0ef41Sopenharmony_ci    })
27221cb0ef41Sopenharmony_ci  });
27231cb0ef41Sopenharmony_ci  await flushAsyncEvents();
27241cb0ef41Sopenharmony_ci
27251cb0ef41Sopenharmony_ci  const reader1 = rs.getReader();
27261cb0ef41Sopenharmony_ci  const read1 = reader1.read();
27271cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
27281cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
27291cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array(4), 'first byobRequest.view');
27301cb0ef41Sopenharmony_ci
27311cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
27321cb0ef41Sopenharmony_ci  reader1.releaseLock();
27331cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
27341cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint8Array([4, 5, 6]));
27351cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
27361cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
27371cb0ef41Sopenharmony_ci
27381cb0ef41Sopenharmony_ci  // respond() should fulfill the *second* read() request
27391cb0ef41Sopenharmony_ci  byobRequest1.view[0] = 11;
27401cb0ef41Sopenharmony_ci  byobRequest1.respond(1);
27411cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
27421cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after respond()');
27431cb0ef41Sopenharmony_ci
27441cb0ef41Sopenharmony_ci  const result2 = await read2;
27451cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
27461cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([11, 5, 6]).subarray(0, 1), 'second result.value');
27471cb0ef41Sopenharmony_ci
27481cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: autoAllocateChunkSize, releaseLock() with pending read(), read(view) on second reader, respond()');
27491cb0ef41Sopenharmony_ci
27501cb0ef41Sopenharmony_cipromise_test(async t => {
27511cb0ef41Sopenharmony_ci  let controller;
27521cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
27531cb0ef41Sopenharmony_ci    type: 'bytes',
27541cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 4,
27551cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
27561cb0ef41Sopenharmony_ci      controller = c;
27571cb0ef41Sopenharmony_ci    })
27581cb0ef41Sopenharmony_ci  });
27591cb0ef41Sopenharmony_ci  await flushAsyncEvents();
27601cb0ef41Sopenharmony_ci
27611cb0ef41Sopenharmony_ci  const reader1 = rs.getReader();
27621cb0ef41Sopenharmony_ci  const read1 = reader1.read();
27631cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
27641cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
27651cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array(4), 'first byobRequest.view');
27661cb0ef41Sopenharmony_ci
27671cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
27681cb0ef41Sopenharmony_ci  reader1.releaseLock();
27691cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
27701cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint8Array([4, 5, 6]));
27711cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
27721cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
27731cb0ef41Sopenharmony_ci
27741cb0ef41Sopenharmony_ci  // enqueue() should fulfill the *second* read() request
27751cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array([11]));
27761cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
27771cb0ef41Sopenharmony_ci  assert_equals(byobRequest2, null, 'byobRequest should be null after enqueue()');
27781cb0ef41Sopenharmony_ci
27791cb0ef41Sopenharmony_ci  const result2 = await read2;
27801cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
27811cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([11, 5, 6]).subarray(0, 1), 'second result.value');
27821cb0ef41Sopenharmony_ci
27831cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: autoAllocateChunkSize, releaseLock() with pending read(), read(view) on second reader, enqueue()');
27841cb0ef41Sopenharmony_ci
27851cb0ef41Sopenharmony_cipromise_test(async t => {
27861cb0ef41Sopenharmony_ci  let controller;
27871cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
27881cb0ef41Sopenharmony_ci    type: 'bytes',
27891cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
27901cb0ef41Sopenharmony_ci      controller = c;
27911cb0ef41Sopenharmony_ci    })
27921cb0ef41Sopenharmony_ci  });
27931cb0ef41Sopenharmony_ci  await flushAsyncEvents();
27941cb0ef41Sopenharmony_ci
27951cb0ef41Sopenharmony_ci  const reader1 = rs.getReader({ mode: 'byob' });
27961cb0ef41Sopenharmony_ci  const read1 = reader1.read(new Uint16Array(1));
27971cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
27981cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
27991cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array([0, 0]), 'first byobRequest.view');
28001cb0ef41Sopenharmony_ci
28011cb0ef41Sopenharmony_ci  // respond(1) should partially fill the first read(), but not yet fulfill it
28021cb0ef41Sopenharmony_ci  byobRequest1.view[0] = 0x11;
28031cb0ef41Sopenharmony_ci  byobRequest1.respond(1);
28041cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
28051cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest2, null, 'second byobRequest should exist');
28061cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest2.view, new Uint8Array([0x11, 0]).subarray(1, 2), 'second byobRequest.view');
28071cb0ef41Sopenharmony_ci
28081cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
28091cb0ef41Sopenharmony_ci  reader1.releaseLock();
28101cb0ef41Sopenharmony_ci  const reader2 = rs.getReader({ mode: 'byob' });
28111cb0ef41Sopenharmony_ci  const read2 = reader2.read(new Uint16Array(1));
28121cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
28131cb0ef41Sopenharmony_ci  assert_equals(controller.byobRequest, byobRequest2, 'byobRequest should be unchanged');
28141cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest2.view, new Uint8Array([0x11, 0]).subarray(1, 2), 'byobRequest.view should be unchanged');
28151cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
28161cb0ef41Sopenharmony_ci
28171cb0ef41Sopenharmony_ci  // second respond(1) should fill the read request and fulfill it
28181cb0ef41Sopenharmony_ci  byobRequest2.view[0] = 0x22;
28191cb0ef41Sopenharmony_ci  byobRequest2.respond(1);
28201cb0ef41Sopenharmony_ci  assert_equals(controller.byobRequest, null, 'byobRequest should be invalidated after second respond()');
28211cb0ef41Sopenharmony_ci
28221cb0ef41Sopenharmony_ci  const result2 = await read2;
28231cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
28241cb0ef41Sopenharmony_ci  const view2 = result2.value;
28251cb0ef41Sopenharmony_ci  assert_equals(view2.byteOffset, 0, 'second result.value.byteOffset');
28261cb0ef41Sopenharmony_ci  assert_equals(view2.byteLength, 2, 'second result.value.byteLength');
28271cb0ef41Sopenharmony_ci  const dataView2 = new DataView(view2.buffer, view2.byteOffset, view2.byteLength);
28281cb0ef41Sopenharmony_ci  assert_equals(dataView2.getUint16(0), 0x1122, 'second result.value[0]');
28291cb0ef41Sopenharmony_ci
28301cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view) with 1 element Uint16Array, respond(1), releaseLock(), read(view) on ' +
28311cb0ef41Sopenharmony_ci   'second reader with 1 element Uint16Array, respond(1)');
28321cb0ef41Sopenharmony_ci
28331cb0ef41Sopenharmony_cipromise_test(async t => {
28341cb0ef41Sopenharmony_ci  let controller;
28351cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
28361cb0ef41Sopenharmony_ci    type: 'bytes',
28371cb0ef41Sopenharmony_ci    start: t.step_func((c) => {
28381cb0ef41Sopenharmony_ci      controller = c;
28391cb0ef41Sopenharmony_ci    })
28401cb0ef41Sopenharmony_ci  });
28411cb0ef41Sopenharmony_ci  await flushAsyncEvents();
28421cb0ef41Sopenharmony_ci
28431cb0ef41Sopenharmony_ci  const reader1 = rs.getReader({ mode: 'byob' });
28441cb0ef41Sopenharmony_ci  const read1 = reader1.read(new Uint16Array(1));
28451cb0ef41Sopenharmony_ci  const byobRequest1 = controller.byobRequest;
28461cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest1, null, 'first byobRequest should exist');
28471cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest1.view, new Uint8Array([0, 0]), 'first byobRequest.view');
28481cb0ef41Sopenharmony_ci
28491cb0ef41Sopenharmony_ci  // respond(1) should partially fill the first read(), but not yet fulfill it
28501cb0ef41Sopenharmony_ci  byobRequest1.view[0] = 0x11;
28511cb0ef41Sopenharmony_ci  byobRequest1.respond(1);
28521cb0ef41Sopenharmony_ci  const byobRequest2 = controller.byobRequest;
28531cb0ef41Sopenharmony_ci  assert_not_equals(byobRequest2, null, 'second byobRequest should exist');
28541cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest2.view, new Uint8Array([0x11, 0]).subarray(1, 2), 'second byobRequest.view');
28551cb0ef41Sopenharmony_ci
28561cb0ef41Sopenharmony_ci  // releaseLock() should reject the pending read, but *not* invalidate the BYOB request
28571cb0ef41Sopenharmony_ci  reader1.releaseLock();
28581cb0ef41Sopenharmony_ci  const reader2 = rs.getReader();
28591cb0ef41Sopenharmony_ci  const read2 = reader2.read();
28601cb0ef41Sopenharmony_ci  assert_not_equals(controller.byobRequest, null, 'byobRequest should not be invalidated after releaseLock()');
28611cb0ef41Sopenharmony_ci  assert_equals(controller.byobRequest, byobRequest2, 'byobRequest should be unchanged');
28621cb0ef41Sopenharmony_ci  assert_typed_array_equals(byobRequest2.view, new Uint8Array([0x11, 0]).subarray(1, 2), 'byobRequest.view should be unchanged');
28631cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, read1, 'pending read must reject after releaseLock()');
28641cb0ef41Sopenharmony_ci
28651cb0ef41Sopenharmony_ci  // enqueue() should fulfill the read request and put remaining byte in the queue
28661cb0ef41Sopenharmony_ci  controller.enqueue(new Uint8Array([0x22]));
28671cb0ef41Sopenharmony_ci  assert_equals(controller.byobRequest, null, 'byobRequest should be invalidated after second respond()');
28681cb0ef41Sopenharmony_ci
28691cb0ef41Sopenharmony_ci  const result2 = await read2;
28701cb0ef41Sopenharmony_ci  assert_false(result2.done, 'second result.done');
28711cb0ef41Sopenharmony_ci  assert_typed_array_equals(result2.value, new Uint8Array([0x11]), 'second result.value');
28721cb0ef41Sopenharmony_ci
28731cb0ef41Sopenharmony_ci  const result3 = await reader2.read();
28741cb0ef41Sopenharmony_ci  assert_false(result3.done, 'third result.done');
28751cb0ef41Sopenharmony_ci  assert_typed_array_equals(result3.value, new Uint8Array([0x22]), 'third result.value');
28761cb0ef41Sopenharmony_ci
28771cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read(view) with 1 element Uint16Array, respond(1), releaseLock(), read() on ' +
28781cb0ef41Sopenharmony_ci   'second reader, enqueue()');
28791cb0ef41Sopenharmony_ci
28801cb0ef41Sopenharmony_cipromise_test(async t => {
28811cb0ef41Sopenharmony_ci  // Tests https://github.com/nodejs/node/issues/41886
28821cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
28831cb0ef41Sopenharmony_ci    type: 'bytes',
28841cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 10,
28851cb0ef41Sopenharmony_ci    pull: t.step_func((c) => {
28861cb0ef41Sopenharmony_ci      const newView = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
28871cb0ef41Sopenharmony_ci      newView.set([20, 21, 22]);
28881cb0ef41Sopenharmony_ci      c.byobRequest.respondWithNewView(newView);
28891cb0ef41Sopenharmony_ci    })
28901cb0ef41Sopenharmony_ci  });
28911cb0ef41Sopenharmony_ci
28921cb0ef41Sopenharmony_ci  const reader = stream.getReader();
28931cb0ef41Sopenharmony_ci  const result = await reader.read();
28941cb0ef41Sopenharmony_ci  assert_false(result.done, 'result.done');
28951cb0ef41Sopenharmony_ci
28961cb0ef41Sopenharmony_ci  const view = result.value;
28971cb0ef41Sopenharmony_ci  assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
28981cb0ef41Sopenharmony_ci  assert_equals(view.byteLength, 3, 'result.value.byteLength');
28991cb0ef41Sopenharmony_ci  assert_equals(view.buffer.byteLength, 10, 'result.value.buffer.byteLength');
29001cb0ef41Sopenharmony_ci  assert_array_equals([...new Uint8Array(view)], [20, 21, 22], 'result.value');
29011cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: autoAllocateChunkSize, read(), respondWithNewView()');
2902