11cb0ef41Sopenharmony_ci// META: global=window,worker
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_cipromise_test(() => {
51cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
61cb0ef41Sopenharmony_ci    start(c) {
71cb0ef41Sopenharmony_ci      c.close();
81cb0ef41Sopenharmony_ci    },
91cb0ef41Sopenharmony_ci    type: 'bytes'
101cb0ef41Sopenharmony_ci  });
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
131cb0ef41Sopenharmony_ci  const view = new Uint8Array([1, 2, 3]);
141cb0ef41Sopenharmony_ci  return reader.read(view).then(({ value, done }) => {
151cb0ef41Sopenharmony_ci    // Sanity checks
161cb0ef41Sopenharmony_ci    assert_true(value instanceof Uint8Array, 'The value read must be a Uint8Array');
171cb0ef41Sopenharmony_ci    assert_not_equals(value, view, 'The value read must not be the *same* Uint8Array');
181cb0ef41Sopenharmony_ci    assert_array_equals(value, [], 'The value read must be an empty Uint8Array, since the stream is closed');
191cb0ef41Sopenharmony_ci    assert_true(done, 'done must be true, since the stream is closed');
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci    // The important assertions
221cb0ef41Sopenharmony_ci    assert_not_equals(value.buffer, view.buffer, 'a different ArrayBuffer must underlie the value');
231cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 0, 'the original buffer must be detached');
241cb0ef41Sopenharmony_ci  });
251cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read()ing from a closed stream still transfers the buffer');
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_cipromise_test(() => {
281cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
291cb0ef41Sopenharmony_ci    start(c) {
301cb0ef41Sopenharmony_ci      c.enqueue(new Uint8Array([1, 2, 3]));
311cb0ef41Sopenharmony_ci    },
321cb0ef41Sopenharmony_ci    type: 'bytes'
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
361cb0ef41Sopenharmony_ci  const view = new Uint8Array([4, 5, 6]);
371cb0ef41Sopenharmony_ci  return reader.read(view).then(({ value, done }) => {
381cb0ef41Sopenharmony_ci    // Sanity checks
391cb0ef41Sopenharmony_ci    assert_true(value instanceof Uint8Array, 'The value read must be a Uint8Array');
401cb0ef41Sopenharmony_ci    assert_not_equals(value, view, 'The value read must not be the *same* Uint8Array');
411cb0ef41Sopenharmony_ci    assert_array_equals(value, [1, 2, 3], 'The value read must be the enqueued Uint8Array, not the original values');
421cb0ef41Sopenharmony_ci    assert_false(done, 'done must be false, since the stream is not closed');
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci    // The important assertions
451cb0ef41Sopenharmony_ci    assert_not_equals(value.buffer, view.buffer, 'a different ArrayBuffer must underlie the value');
461cb0ef41Sopenharmony_ci    assert_equals(view.buffer.byteLength, 0, 'the original buffer must be detached');
471cb0ef41Sopenharmony_ci  });
481cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read()ing from a stream with queued chunks still transfers the buffer');
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_citest(() => {
511cb0ef41Sopenharmony_ci  new ReadableStream({
521cb0ef41Sopenharmony_ci    start(c) {
531cb0ef41Sopenharmony_ci      const view = new Uint8Array([1, 2, 3]);
541cb0ef41Sopenharmony_ci      c.enqueue(view);
551cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.enqueue(view));
561cb0ef41Sopenharmony_ci    },
571cb0ef41Sopenharmony_ci    type: 'bytes'
581cb0ef41Sopenharmony_ci  });
591cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueuing an already-detached buffer throws');
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_citest(() => {
621cb0ef41Sopenharmony_ci  new ReadableStream({
631cb0ef41Sopenharmony_ci    start(c) {
641cb0ef41Sopenharmony_ci      const view = new Uint8Array([]);
651cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.enqueue(view));
661cb0ef41Sopenharmony_ci    },
671cb0ef41Sopenharmony_ci    type: 'bytes'
681cb0ef41Sopenharmony_ci  });
691cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueuing a zero-length buffer throws');
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_citest(() => {
721cb0ef41Sopenharmony_ci  new ReadableStream({
731cb0ef41Sopenharmony_ci    start(c) {
741cb0ef41Sopenharmony_ci      const view = new Uint8Array(new ArrayBuffer(10), 0, 0);
751cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.enqueue(view));
761cb0ef41Sopenharmony_ci    },
771cb0ef41Sopenharmony_ci    type: 'bytes'
781cb0ef41Sopenharmony_ci  });
791cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueuing a zero-length view on a non-zero-length buffer throws');
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_cipromise_test(t => {
821cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
831cb0ef41Sopenharmony_ci    start(c) {
841cb0ef41Sopenharmony_ci      c.enqueue(new Uint8Array([1, 2, 3]));
851cb0ef41Sopenharmony_ci    },
861cb0ef41Sopenharmony_ci    type: 'bytes'
871cb0ef41Sopenharmony_ci  });
881cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ci  const view = new Uint8Array([4, 5, 6]);
911cb0ef41Sopenharmony_ci  return reader.read(view).then(() => {
921cb0ef41Sopenharmony_ci    // view is now detached
931cb0ef41Sopenharmony_ci    return promise_rejects_js(t, TypeError, reader.read(view));
941cb0ef41Sopenharmony_ci  });
951cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: reading into an already-detached buffer rejects');
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_cipromise_test(t => {
981cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
991cb0ef41Sopenharmony_ci    start(c) {
1001cb0ef41Sopenharmony_ci      c.enqueue(new Uint8Array([1, 2, 3]));
1011cb0ef41Sopenharmony_ci    },
1021cb0ef41Sopenharmony_ci    type: 'bytes'
1031cb0ef41Sopenharmony_ci  });
1041cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci  const view = new Uint8Array();
1071cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError, reader.read(view));
1081cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: reading into a zero-length buffer rejects');
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_cipromise_test(t => {
1111cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1121cb0ef41Sopenharmony_ci    start(c) {
1131cb0ef41Sopenharmony_ci      c.enqueue(new Uint8Array([1, 2, 3]));
1141cb0ef41Sopenharmony_ci    },
1151cb0ef41Sopenharmony_ci    type: 'bytes'
1161cb0ef41Sopenharmony_ci  });
1171cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ci  const view = new Uint8Array(new ArrayBuffer(10), 0, 0);
1201cb0ef41Sopenharmony_ci  return promise_rejects_js(t, TypeError, reader.read(view));
1211cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: reading into a zero-length view on a non-zero-length buffer rejects');
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ciasync_test(t => {
1241cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1251cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
1261cb0ef41Sopenharmony_ci      // Detach it by reading into it
1271cb0ef41Sopenharmony_ci      reader.read(c.byobRequest.view);
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.byobRequest.respond(1),
1301cb0ef41Sopenharmony_ci        'respond() must throw if the corresponding view has become detached');
1311cb0ef41Sopenharmony_ci    }),
1321cb0ef41Sopenharmony_ci    type: 'bytes'
1331cb0ef41Sopenharmony_ci  });
1341cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
1371cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respond() throws if the BYOB request\'s buffer has been detached (in the ' +
1381cb0ef41Sopenharmony_ci   'readable state)');
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ciasync_test(t => {
1411cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1421cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
1431cb0ef41Sopenharmony_ci      c.close();
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci      // Detach it by reading into it
1461cb0ef41Sopenharmony_ci      reader.read(c.byobRequest.view);
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.byobRequest.respond(0),
1491cb0ef41Sopenharmony_ci        'respond() must throw if the corresponding view has become detached');
1501cb0ef41Sopenharmony_ci    }),
1511cb0ef41Sopenharmony_ci    type: 'bytes'
1521cb0ef41Sopenharmony_ci  });
1531cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
1561cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respond() throws if the BYOB request\'s buffer has been detached (in the ' +
1571cb0ef41Sopenharmony_ci   'closed state)');
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_ciasync_test(t => {
1601cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1611cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
1621cb0ef41Sopenharmony_ci      // Detach it by reading into it
1631cb0ef41Sopenharmony_ci      const view = new Uint8Array([1, 2, 3]);
1641cb0ef41Sopenharmony_ci      reader.read(view);
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.byobRequest.respondWithNewView(view));
1671cb0ef41Sopenharmony_ci    }),
1681cb0ef41Sopenharmony_ci    type: 'bytes'
1691cb0ef41Sopenharmony_ci  });
1701cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
1731cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has been detached ' +
1741cb0ef41Sopenharmony_ci    '(in the readable state)');
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ciasync_test(t => {
1771cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1781cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
1791cb0ef41Sopenharmony_ci      const view = new Uint8Array();
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.byobRequest.respondWithNewView(view));
1821cb0ef41Sopenharmony_ci    }),
1831cb0ef41Sopenharmony_ci    type: 'bytes'
1841cb0ef41Sopenharmony_ci  });
1851cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
1881cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer is zero-length ' +
1891cb0ef41Sopenharmony_ci    '(in the readable state)');
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ciasync_test(t => {
1921cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
1931cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
1941cb0ef41Sopenharmony_ci      const view = new Uint8Array(c.byobRequest.view.buffer, 0, 0);
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.byobRequest.respondWithNewView(view));
1971cb0ef41Sopenharmony_ci    }),
1981cb0ef41Sopenharmony_ci    type: 'bytes'
1991cb0ef41Sopenharmony_ci  });
2001cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
2031cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view is zero-length on a ' +
2041cb0ef41Sopenharmony_ci    'non-zero-length buffer (in the readable state)');
2051cb0ef41Sopenharmony_ci
2061cb0ef41Sopenharmony_ciasync_test(t => {
2071cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2081cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
2091cb0ef41Sopenharmony_ci      const view = c.byobRequest.view.subarray(1, 2);
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ci      assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
2121cb0ef41Sopenharmony_ci    }),
2131cb0ef41Sopenharmony_ci    type: 'bytes'
2141cb0ef41Sopenharmony_ci  });
2151cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
2181cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view has a different offset ' +
2191cb0ef41Sopenharmony_ci   '(in the readable state)');
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_ciasync_test(t => {
2221cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2231cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
2241cb0ef41Sopenharmony_ci      c.close();
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ci      const view = c.byobRequest.view.subarray(1, 1);
2271cb0ef41Sopenharmony_ci
2281cb0ef41Sopenharmony_ci      assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
2291cb0ef41Sopenharmony_ci    }),
2301cb0ef41Sopenharmony_ci    type: 'bytes'
2311cb0ef41Sopenharmony_ci  });
2321cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
2351cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view has a different offset ' +
2361cb0ef41Sopenharmony_ci   '(in the closed state)');
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_ciasync_test(t => {
2391cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2401cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
2411cb0ef41Sopenharmony_ci      const view = new Uint8Array(new ArrayBuffer(10), 0, 3);
2421cb0ef41Sopenharmony_ci
2431cb0ef41Sopenharmony_ci      assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
2441cb0ef41Sopenharmony_ci    }),
2451cb0ef41Sopenharmony_ci    type: 'bytes'
2461cb0ef41Sopenharmony_ci  });
2471cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
2481cb0ef41Sopenharmony_ci
2491cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
2501cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
2511cb0ef41Sopenharmony_ci   'different length (in the readable state)');
2521cb0ef41Sopenharmony_ci
2531cb0ef41Sopenharmony_ciasync_test(t => {
2541cb0ef41Sopenharmony_ci  // Tests https://github.com/nodejs/node/issues/41886
2551cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2561cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
2571cb0ef41Sopenharmony_ci      const view = new Uint8Array(new ArrayBuffer(11), 0, 3);
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci      assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
2601cb0ef41Sopenharmony_ci    }),
2611cb0ef41Sopenharmony_ci    type: 'bytes',
2621cb0ef41Sopenharmony_ci    autoAllocateChunkSize: 10
2631cb0ef41Sopenharmony_ci  });
2641cb0ef41Sopenharmony_ci  const reader = stream.getReader();
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci  reader.read();
2671cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
2681cb0ef41Sopenharmony_ci   'different length (autoAllocateChunkSize)');
2691cb0ef41Sopenharmony_ci
2701cb0ef41Sopenharmony_ciasync_test(t => {
2711cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2721cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
2731cb0ef41Sopenharmony_ci      const view = new Uint8Array(c.byobRequest.view.buffer, 0, 4);
2741cb0ef41Sopenharmony_ci      view[0] = 20;
2751cb0ef41Sopenharmony_ci      view[1] = 21;
2761cb0ef41Sopenharmony_ci      view[2] = 22;
2771cb0ef41Sopenharmony_ci      view[3] = 23;
2781cb0ef41Sopenharmony_ci
2791cb0ef41Sopenharmony_ci      assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
2801cb0ef41Sopenharmony_ci    }),
2811cb0ef41Sopenharmony_ci    type: 'bytes'
2821cb0ef41Sopenharmony_ci  });
2831cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
2841cb0ef41Sopenharmony_ci
2851cb0ef41Sopenharmony_ci  const buffer = new ArrayBuffer(10);
2861cb0ef41Sopenharmony_ci  const view = new Uint8Array(buffer, 0, 3);
2871cb0ef41Sopenharmony_ci  view[0] = 10;
2881cb0ef41Sopenharmony_ci  view[1] = 11;
2891cb0ef41Sopenharmony_ci  view[2] = 12;
2901cb0ef41Sopenharmony_ci  reader.read(view);
2911cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view has a larger length ' +
2921cb0ef41Sopenharmony_ci   '(in the readable state)');
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ciasync_test(t => {
2951cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
2961cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
2971cb0ef41Sopenharmony_ci      c.close();
2981cb0ef41Sopenharmony_ci
2991cb0ef41Sopenharmony_ci      // Detach it by reading into it
3001cb0ef41Sopenharmony_ci      const view = new Uint8Array([1, 2, 3]);
3011cb0ef41Sopenharmony_ci      reader.read(view);
3021cb0ef41Sopenharmony_ci
3031cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.byobRequest.respondWithNewView(view));
3041cb0ef41Sopenharmony_ci    }),
3051cb0ef41Sopenharmony_ci    type: 'bytes'
3061cb0ef41Sopenharmony_ci  });
3071cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
3081cb0ef41Sopenharmony_ci
3091cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
3101cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has been detached ' +
3111cb0ef41Sopenharmony_ci   '(in the closed state)');
3121cb0ef41Sopenharmony_ci
3131cb0ef41Sopenharmony_ciasync_test(t => {
3141cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
3151cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
3161cb0ef41Sopenharmony_ci      const view = new Uint8Array();
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_ci      c.close();
3191cb0ef41Sopenharmony_ci
3201cb0ef41Sopenharmony_ci      assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
3211cb0ef41Sopenharmony_ci    }),
3221cb0ef41Sopenharmony_ci    type: 'bytes'
3231cb0ef41Sopenharmony_ci  });
3241cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
3251cb0ef41Sopenharmony_ci
3261cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
3271cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer is zero-length ' +
3281cb0ef41Sopenharmony_ci   '(in the closed state)');
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ciasync_test(t => {
3311cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
3321cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
3331cb0ef41Sopenharmony_ci      const view = new Uint8Array(c.byobRequest.view.buffer, 0, 1);
3341cb0ef41Sopenharmony_ci
3351cb0ef41Sopenharmony_ci      c.close();
3361cb0ef41Sopenharmony_ci
3371cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.byobRequest.respondWithNewView(view));
3381cb0ef41Sopenharmony_ci    }),
3391cb0ef41Sopenharmony_ci    type: 'bytes'
3401cb0ef41Sopenharmony_ci  });
3411cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
3421cb0ef41Sopenharmony_ci
3431cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
3441cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view is non-zero-length ' +
3451cb0ef41Sopenharmony_ci   '(in the closed state)');
3461cb0ef41Sopenharmony_ci
3471cb0ef41Sopenharmony_ciasync_test(t => {
3481cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
3491cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
3501cb0ef41Sopenharmony_ci      const view = new Uint8Array(new ArrayBuffer(10), 0, 0);
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_ci      c.close();
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci      assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
3551cb0ef41Sopenharmony_ci    }),
3561cb0ef41Sopenharmony_ci    type: 'bytes'
3571cb0ef41Sopenharmony_ci  });
3581cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
3591cb0ef41Sopenharmony_ci
3601cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
3611cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
3621cb0ef41Sopenharmony_ci   'different length (in the closed state)');
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_ciasync_test(t => {
3651cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
3661cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
3671cb0ef41Sopenharmony_ci      // Detach it by reading into it
3681cb0ef41Sopenharmony_ci      reader.read(c.byobRequest.view);
3691cb0ef41Sopenharmony_ci
3701cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.enqueue(new Uint8Array([1])),
3711cb0ef41Sopenharmony_ci        'enqueue() must throw if the BYOB request\'s buffer has become detached');
3721cb0ef41Sopenharmony_ci    }),
3731cb0ef41Sopenharmony_ci    type: 'bytes'
3741cb0ef41Sopenharmony_ci  });
3751cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
3761cb0ef41Sopenharmony_ci
3771cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
3781cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue() throws if the BYOB request\'s buffer has been detached (in the ' +
3791cb0ef41Sopenharmony_ci  'readable state)');
3801cb0ef41Sopenharmony_ci
3811cb0ef41Sopenharmony_ciasync_test(t => {
3821cb0ef41Sopenharmony_ci  const stream = new ReadableStream({
3831cb0ef41Sopenharmony_ci    pull: t.step_func_done(c => {
3841cb0ef41Sopenharmony_ci      c.close();
3851cb0ef41Sopenharmony_ci
3861cb0ef41Sopenharmony_ci      // Detach it by reading into it
3871cb0ef41Sopenharmony_ci      reader.read(c.byobRequest.view);
3881cb0ef41Sopenharmony_ci
3891cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.enqueue(new Uint8Array([1])),
3901cb0ef41Sopenharmony_ci        'enqueue() must throw if the BYOB request\'s buffer has become detached');
3911cb0ef41Sopenharmony_ci    }),
3921cb0ef41Sopenharmony_ci    type: 'bytes'
3931cb0ef41Sopenharmony_ci  });
3941cb0ef41Sopenharmony_ci  const reader = stream.getReader({ mode: 'byob' });
3951cb0ef41Sopenharmony_ci
3961cb0ef41Sopenharmony_ci  reader.read(new Uint8Array([4, 5, 6]));
3971cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue() throws if the BYOB request\'s buffer has been detached (in the ' +
3981cb0ef41Sopenharmony_ci  'closed state)');
399