11cb0ef41Sopenharmony_ci// META: global=window,worker
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_citest(() => {
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci  const theError = new Error('a unique string');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci  assert_throws_exactly(theError, () => {
101cb0ef41Sopenharmony_ci    new ReadableStream({
111cb0ef41Sopenharmony_ci      get start() {
121cb0ef41Sopenharmony_ci        throw theError;
131cb0ef41Sopenharmony_ci      }
141cb0ef41Sopenharmony_ci    });
151cb0ef41Sopenharmony_ci  }, 'constructing the stream should re-throw the error');
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci}, 'Underlying source start: throwing getter');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_citest(() => {
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  const theError = new Error('a unique string');
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  assert_throws_exactly(theError, () => {
251cb0ef41Sopenharmony_ci    new ReadableStream({
261cb0ef41Sopenharmony_ci      start() {
271cb0ef41Sopenharmony_ci        throw theError;
281cb0ef41Sopenharmony_ci      }
291cb0ef41Sopenharmony_ci    });
301cb0ef41Sopenharmony_ci  }, 'constructing the stream should re-throw the error');
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci}, 'Underlying source start: throwing method');
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_citest(() => {
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  const theError = new Error('a unique string');
381cb0ef41Sopenharmony_ci  assert_throws_exactly(theError, () => new ReadableStream({
391cb0ef41Sopenharmony_ci    get pull() {
401cb0ef41Sopenharmony_ci      throw theError;
411cb0ef41Sopenharmony_ci    }
421cb0ef41Sopenharmony_ci  }), 'constructor should throw');
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci}, 'Underlying source: throwing pull getter (initial pull)');
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_cipromise_test(t => {
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci  const theError = new Error('a unique string');
501cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
511cb0ef41Sopenharmony_ci    pull() {
521cb0ef41Sopenharmony_ci      throw theError;
531cb0ef41Sopenharmony_ci    }
541cb0ef41Sopenharmony_ci  });
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, theError, rs.getReader().closed);
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci}, 'Underlying source: throwing pull method (initial pull)');
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_cipromise_test(t => {
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci  const theError = new Error('a unique string');
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  let counter = 0;
661cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
671cb0ef41Sopenharmony_ci    get pull() {
681cb0ef41Sopenharmony_ci      ++counter;
691cb0ef41Sopenharmony_ci      if (counter === 1) {
701cb0ef41Sopenharmony_ci        return c => c.enqueue('a');
711cb0ef41Sopenharmony_ci      }
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_ci      throw theError;
741cb0ef41Sopenharmony_ci    }
751cb0ef41Sopenharmony_ci  });
761cb0ef41Sopenharmony_ci  const reader = rs.getReader();
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci  return Promise.all([
791cb0ef41Sopenharmony_ci    reader.read().then(r => {
801cb0ef41Sopenharmony_ci      assert_object_equals(r, { value: 'a', done: false }, 'the first chunk read should be correct');
811cb0ef41Sopenharmony_ci    }),
821cb0ef41Sopenharmony_ci    reader.read().then(r => {
831cb0ef41Sopenharmony_ci      assert_object_equals(r, { value: 'a', done: false }, 'the second chunk read should be correct');
841cb0ef41Sopenharmony_ci      assert_equals(counter, 1, 'counter should be 1');
851cb0ef41Sopenharmony_ci    })
861cb0ef41Sopenharmony_ci  ]);
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ci}, 'Underlying source pull: throwing getter (second pull does not result in a second get)');
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_cipromise_test(t => {
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci  const theError = new Error('a unique string');
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci  let counter = 0;
951cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
961cb0ef41Sopenharmony_ci    pull(c) {
971cb0ef41Sopenharmony_ci      ++counter;
981cb0ef41Sopenharmony_ci      if (counter === 1) {
991cb0ef41Sopenharmony_ci        c.enqueue('a');
1001cb0ef41Sopenharmony_ci        return;
1011cb0ef41Sopenharmony_ci      }
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci      throw theError;
1041cb0ef41Sopenharmony_ci    }
1051cb0ef41Sopenharmony_ci  });
1061cb0ef41Sopenharmony_ci  const reader = rs.getReader();
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci  return Promise.all([
1091cb0ef41Sopenharmony_ci    reader.read().then(r => {
1101cb0ef41Sopenharmony_ci      assert_object_equals(r, { value: 'a', done: false }, 'the chunk read should be correct');
1111cb0ef41Sopenharmony_ci    }),
1121cb0ef41Sopenharmony_ci    promise_rejects_exactly(t, theError, reader.closed)
1131cb0ef41Sopenharmony_ci  ]);
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci}, 'Underlying source pull: throwing method (second pull)');
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_citest(() => {
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ci  const theError = new Error('a unique string');
1201cb0ef41Sopenharmony_ci  assert_throws_exactly(theError, () => new ReadableStream({
1211cb0ef41Sopenharmony_ci    get cancel() {
1221cb0ef41Sopenharmony_ci      throw theError;
1231cb0ef41Sopenharmony_ci    }
1241cb0ef41Sopenharmony_ci  }), 'constructor should throw');
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci}, 'Underlying source cancel: throwing getter');
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_cipromise_test(t => {
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ci  const theError = new Error('a unique string');
1311cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
1321cb0ef41Sopenharmony_ci    cancel() {
1331cb0ef41Sopenharmony_ci      throw theError;
1341cb0ef41Sopenharmony_ci    }
1351cb0ef41Sopenharmony_ci  });
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, theError, rs.cancel());
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci}, 'Underlying source cancel: throwing method');
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_cipromise_test(() => {
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ci  let controller;
1441cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
1451cb0ef41Sopenharmony_ci    start(c) {
1461cb0ef41Sopenharmony_ci      controller = c;
1471cb0ef41Sopenharmony_ci    }
1481cb0ef41Sopenharmony_ci  });
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_ci  rs.cancel();
1511cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => controller.enqueue('a'), 'Calling enqueue after canceling should throw');
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ci  return rs.getReader().closed;
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci}, 'Underlying source: calling enqueue on an empty canceled stream should throw');
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_cipromise_test(() => {
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_ci  let controller;
1601cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
1611cb0ef41Sopenharmony_ci    start(c) {
1621cb0ef41Sopenharmony_ci      c.enqueue('a');
1631cb0ef41Sopenharmony_ci      c.enqueue('b');
1641cb0ef41Sopenharmony_ci      controller = c;
1651cb0ef41Sopenharmony_ci    }
1661cb0ef41Sopenharmony_ci  });
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_ci  rs.cancel();
1691cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => controller.enqueue('c'), 'Calling enqueue after canceling should throw');
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci  return rs.getReader().closed;
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_ci}, 'Underlying source: calling enqueue on a non-empty canceled stream should throw');
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_cipromise_test(() => {
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_ci  return new ReadableStream({
1781cb0ef41Sopenharmony_ci    start(c) {
1791cb0ef41Sopenharmony_ci      c.close();
1801cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.enqueue('a'), 'call to enqueue should throw a TypeError');
1811cb0ef41Sopenharmony_ci    }
1821cb0ef41Sopenharmony_ci  }).getReader().closed;
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci}, 'Underlying source: calling enqueue on a closed stream should throw');
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_cipromise_test(t => {
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ci  const theError = new Error('boo');
1891cb0ef41Sopenharmony_ci  const closed = new ReadableStream({
1901cb0ef41Sopenharmony_ci    start(c) {
1911cb0ef41Sopenharmony_ci      c.error(theError);
1921cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.enqueue('a'), 'call to enqueue should throw the error');
1931cb0ef41Sopenharmony_ci    }
1941cb0ef41Sopenharmony_ci  }).getReader().closed;
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ci  return promise_rejects_exactly(t, theError, closed);
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ci}, 'Underlying source: calling enqueue on an errored stream should throw');
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_cipromise_test(() => {
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ci  return new ReadableStream({
2031cb0ef41Sopenharmony_ci    start(c) {
2041cb0ef41Sopenharmony_ci      c.close();
2051cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.close(), 'second call to close should throw a TypeError');
2061cb0ef41Sopenharmony_ci    }
2071cb0ef41Sopenharmony_ci  }).getReader().closed;
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ci}, 'Underlying source: calling close twice on an empty stream should throw the second time');
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_cipromise_test(() => {
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ci  let startCalled = false;
2141cb0ef41Sopenharmony_ci  let readCalled = false;
2151cb0ef41Sopenharmony_ci  const reader = new ReadableStream({
2161cb0ef41Sopenharmony_ci    start(c) {
2171cb0ef41Sopenharmony_ci      c.enqueue('a');
2181cb0ef41Sopenharmony_ci      c.close();
2191cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.close(), 'second call to close should throw a TypeError');
2201cb0ef41Sopenharmony_ci      startCalled = true;
2211cb0ef41Sopenharmony_ci    }
2221cb0ef41Sopenharmony_ci  }).getReader();
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ci  return Promise.all([
2251cb0ef41Sopenharmony_ci    reader.read().then(r => {
2261cb0ef41Sopenharmony_ci      assert_object_equals(r, { value: 'a', done: false }, 'read() should read the enqueued chunk');
2271cb0ef41Sopenharmony_ci      readCalled = true;
2281cb0ef41Sopenharmony_ci    }),
2291cb0ef41Sopenharmony_ci    reader.closed.then(() => {
2301cb0ef41Sopenharmony_ci      assert_true(startCalled);
2311cb0ef41Sopenharmony_ci      assert_true(readCalled);
2321cb0ef41Sopenharmony_ci    })
2331cb0ef41Sopenharmony_ci  ]);
2341cb0ef41Sopenharmony_ci
2351cb0ef41Sopenharmony_ci}, 'Underlying source: calling close twice on a non-empty stream should throw the second time');
2361cb0ef41Sopenharmony_ci
2371cb0ef41Sopenharmony_cipromise_test(() => {
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_ci  let controller;
2401cb0ef41Sopenharmony_ci  let startCalled = false;
2411cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
2421cb0ef41Sopenharmony_ci    start(c) {
2431cb0ef41Sopenharmony_ci      controller = c;
2441cb0ef41Sopenharmony_ci      startCalled = true;
2451cb0ef41Sopenharmony_ci    }
2461cb0ef41Sopenharmony_ci  });
2471cb0ef41Sopenharmony_ci
2481cb0ef41Sopenharmony_ci  rs.cancel();
2491cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => controller.close(), 'Calling close after canceling should throw');
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ci  return rs.getReader().closed.then(() => {
2521cb0ef41Sopenharmony_ci    assert_true(startCalled);
2531cb0ef41Sopenharmony_ci  });
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_ci}, 'Underlying source: calling close on an empty canceled stream should throw');
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_cipromise_test(() => {
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci  let controller;
2601cb0ef41Sopenharmony_ci  let startCalled = false;
2611cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
2621cb0ef41Sopenharmony_ci    start(c) {
2631cb0ef41Sopenharmony_ci      controller = c;
2641cb0ef41Sopenharmony_ci      c.enqueue('a');
2651cb0ef41Sopenharmony_ci      startCalled = true;
2661cb0ef41Sopenharmony_ci    }
2671cb0ef41Sopenharmony_ci  });
2681cb0ef41Sopenharmony_ci
2691cb0ef41Sopenharmony_ci  rs.cancel();
2701cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => controller.close(), 'Calling close after canceling should throw');
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ci  return rs.getReader().closed.then(() => {
2731cb0ef41Sopenharmony_ci    assert_true(startCalled);
2741cb0ef41Sopenharmony_ci  });
2751cb0ef41Sopenharmony_ci
2761cb0ef41Sopenharmony_ci}, 'Underlying source: calling close on a non-empty canceled stream should throw');
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_cipromise_test(() => {
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci  const theError = new Error('boo');
2811cb0ef41Sopenharmony_ci  let startCalled = false;
2821cb0ef41Sopenharmony_ci
2831cb0ef41Sopenharmony_ci  const closed = new ReadableStream({
2841cb0ef41Sopenharmony_ci    start(c) {
2851cb0ef41Sopenharmony_ci      c.error(theError);
2861cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => c.close(), 'call to close should throw a TypeError');
2871cb0ef41Sopenharmony_ci      startCalled = true;
2881cb0ef41Sopenharmony_ci    }
2891cb0ef41Sopenharmony_ci  }).getReader().closed;
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_ci  return closed.catch(e => {
2921cb0ef41Sopenharmony_ci    assert_true(startCalled);
2931cb0ef41Sopenharmony_ci    assert_equals(e, theError, 'closed should reject with the error');
2941cb0ef41Sopenharmony_ci  });
2951cb0ef41Sopenharmony_ci
2961cb0ef41Sopenharmony_ci}, 'Underlying source: calling close after error should throw');
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_cipromise_test(() => {
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ci  const theError = new Error('boo');
3011cb0ef41Sopenharmony_ci  let startCalled = false;
3021cb0ef41Sopenharmony_ci
3031cb0ef41Sopenharmony_ci  const closed = new ReadableStream({
3041cb0ef41Sopenharmony_ci    start(c) {
3051cb0ef41Sopenharmony_ci      c.error(theError);
3061cb0ef41Sopenharmony_ci      c.error();
3071cb0ef41Sopenharmony_ci      startCalled = true;
3081cb0ef41Sopenharmony_ci    }
3091cb0ef41Sopenharmony_ci  }).getReader().closed;
3101cb0ef41Sopenharmony_ci
3111cb0ef41Sopenharmony_ci  return closed.catch(e => {
3121cb0ef41Sopenharmony_ci    assert_true(startCalled);
3131cb0ef41Sopenharmony_ci    assert_equals(e, theError, 'closed should reject with the error');
3141cb0ef41Sopenharmony_ci  });
3151cb0ef41Sopenharmony_ci
3161cb0ef41Sopenharmony_ci}, 'Underlying source: calling error twice should not throw');
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_cipromise_test(() => {
3191cb0ef41Sopenharmony_ci
3201cb0ef41Sopenharmony_ci  let startCalled = false;
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_ci  const closed = new ReadableStream({
3231cb0ef41Sopenharmony_ci    start(c) {
3241cb0ef41Sopenharmony_ci      c.close();
3251cb0ef41Sopenharmony_ci      c.error();
3261cb0ef41Sopenharmony_ci      startCalled = true;
3271cb0ef41Sopenharmony_ci    }
3281cb0ef41Sopenharmony_ci  }).getReader().closed;
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ci  return closed.then(() => assert_true(startCalled));
3311cb0ef41Sopenharmony_ci
3321cb0ef41Sopenharmony_ci}, 'Underlying source: calling error after close should not throw');
3331cb0ef41Sopenharmony_ci
3341cb0ef41Sopenharmony_cipromise_test(() => {
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_ci  let startCalled = false;
3371cb0ef41Sopenharmony_ci  const firstError = new Error('1');
3381cb0ef41Sopenharmony_ci  const secondError = new Error('2');
3391cb0ef41Sopenharmony_ci
3401cb0ef41Sopenharmony_ci  const closed = new ReadableStream({
3411cb0ef41Sopenharmony_ci    start(c) {
3421cb0ef41Sopenharmony_ci      c.error(firstError);
3431cb0ef41Sopenharmony_ci      startCalled = true;
3441cb0ef41Sopenharmony_ci      return Promise.reject(secondError);
3451cb0ef41Sopenharmony_ci    }
3461cb0ef41Sopenharmony_ci  }).getReader().closed;
3471cb0ef41Sopenharmony_ci
3481cb0ef41Sopenharmony_ci  return closed.catch(e => {
3491cb0ef41Sopenharmony_ci    assert_true(startCalled);
3501cb0ef41Sopenharmony_ci    assert_equals(e, firstError, 'closed should reject with the first error');
3511cb0ef41Sopenharmony_ci  });
3521cb0ef41Sopenharmony_ci
3531cb0ef41Sopenharmony_ci}, 'Underlying source: calling error and returning a rejected promise from start should cause the stream to error ' +
3541cb0ef41Sopenharmony_ci   'with the first error');
3551cb0ef41Sopenharmony_ci
3561cb0ef41Sopenharmony_cipromise_test(() => {
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_ci  let startCalled = false;
3591cb0ef41Sopenharmony_ci  const firstError = new Error('1');
3601cb0ef41Sopenharmony_ci  const secondError = new Error('2');
3611cb0ef41Sopenharmony_ci
3621cb0ef41Sopenharmony_ci  const closed = new ReadableStream({
3631cb0ef41Sopenharmony_ci    pull(c) {
3641cb0ef41Sopenharmony_ci      c.error(firstError);
3651cb0ef41Sopenharmony_ci      startCalled = true;
3661cb0ef41Sopenharmony_ci      return Promise.reject(secondError);
3671cb0ef41Sopenharmony_ci    }
3681cb0ef41Sopenharmony_ci  }).getReader().closed;
3691cb0ef41Sopenharmony_ci
3701cb0ef41Sopenharmony_ci  return closed.catch(e => {
3711cb0ef41Sopenharmony_ci    assert_true(startCalled);
3721cb0ef41Sopenharmony_ci    assert_equals(e, firstError, 'closed should reject with the first error');
3731cb0ef41Sopenharmony_ci  });
3741cb0ef41Sopenharmony_ci
3751cb0ef41Sopenharmony_ci}, 'Underlying source: calling error and returning a rejected promise from pull should cause the stream to error ' +
3761cb0ef41Sopenharmony_ci   'with the first error');
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ciconst error1 = { name: 'error1' };
3791cb0ef41Sopenharmony_ci
3801cb0ef41Sopenharmony_cipromise_test(t => {
3811cb0ef41Sopenharmony_ci
3821cb0ef41Sopenharmony_ci  let pullShouldThrow = false;
3831cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
3841cb0ef41Sopenharmony_ci    pull(controller) {
3851cb0ef41Sopenharmony_ci      if (pullShouldThrow) {
3861cb0ef41Sopenharmony_ci        throw error1;
3871cb0ef41Sopenharmony_ci      }
3881cb0ef41Sopenharmony_ci      controller.enqueue(0);
3891cb0ef41Sopenharmony_ci    }
3901cb0ef41Sopenharmony_ci  }, new CountQueuingStrategy({highWaterMark: 1}));
3911cb0ef41Sopenharmony_ci  const reader = rs.getReader();
3921cb0ef41Sopenharmony_ci  return Promise.resolve().then(() => {
3931cb0ef41Sopenharmony_ci    pullShouldThrow = true;
3941cb0ef41Sopenharmony_ci    return Promise.all([
3951cb0ef41Sopenharmony_ci      reader.read(),
3961cb0ef41Sopenharmony_ci      promise_rejects_exactly(t, error1, reader.closed, '.closed promise should reject')
3971cb0ef41Sopenharmony_ci    ]);
3981cb0ef41Sopenharmony_ci  });
3991cb0ef41Sopenharmony_ci
4001cb0ef41Sopenharmony_ci}, 'read should not error if it dequeues and pull() throws');
401