11cb0ef41Sopenharmony_ci// META: global=window,worker
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_cipromise_test(async t => {
51cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
61cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
71cb0ef41Sopenharmony_ci    type: 'bytes'
81cb0ef41Sopenharmony_ci  });
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci  const reader = rs.getReader({ mode: 'byob' });
111cb0ef41Sopenharmony_ci  const memory = new WebAssembly.Memory({ initial: 1 });
121cb0ef41Sopenharmony_ci  const view = new Uint8Array(memory.buffer, 0, 1);
131cb0ef41Sopenharmony_ci  await promise_rejects_js(t, TypeError, reader.read(view));
141cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: read() with a non-transferable buffer');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_citest(t => {
171cb0ef41Sopenharmony_ci  let controller;
181cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
191cb0ef41Sopenharmony_ci    start(c) {
201cb0ef41Sopenharmony_ci      controller = c;
211cb0ef41Sopenharmony_ci    },
221cb0ef41Sopenharmony_ci    pull: t.unreached_func('pull() should not be called'),
231cb0ef41Sopenharmony_ci    type: 'bytes'
241cb0ef41Sopenharmony_ci  });
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  const memory = new WebAssembly.Memory({ initial: 1 });
271cb0ef41Sopenharmony_ci  const view = new Uint8Array(memory.buffer, 0, 1);
281cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => controller.enqueue(view));
291cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: enqueue() with a non-transferable buffer');
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_cipromise_test(async t => {
321cb0ef41Sopenharmony_ci  let byobRequest;
331cb0ef41Sopenharmony_ci  let resolvePullCalledPromise;
341cb0ef41Sopenharmony_ci  const pullCalledPromise = new Promise(resolve => {
351cb0ef41Sopenharmony_ci    resolvePullCalledPromise = resolve;
361cb0ef41Sopenharmony_ci  });
371cb0ef41Sopenharmony_ci  const rs = new ReadableStream({
381cb0ef41Sopenharmony_ci    pull(controller) {
391cb0ef41Sopenharmony_ci      byobRequest = controller.byobRequest;
401cb0ef41Sopenharmony_ci      resolvePullCalledPromise();
411cb0ef41Sopenharmony_ci    },
421cb0ef41Sopenharmony_ci    type: 'bytes'
431cb0ef41Sopenharmony_ci  });
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  const memory = new WebAssembly.Memory({ initial: 1 });
461cb0ef41Sopenharmony_ci  // Make sure the backing buffers of both views have the same length
471cb0ef41Sopenharmony_ci  const byobView = new Uint8Array(new ArrayBuffer(memory.buffer.byteLength), 0, 1);
481cb0ef41Sopenharmony_ci  const newView = new Uint8Array(memory.buffer, byobView.byteOffset, byobView.byteLength);
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci  const reader = rs.getReader({ mode: 'byob' });
511cb0ef41Sopenharmony_ci  reader.read(byobView).then(
521cb0ef41Sopenharmony_ci    t.unreached_func('read() should not resolve'),
531cb0ef41Sopenharmony_ci    t.unreached_func('read() should not reject')
541cb0ef41Sopenharmony_ci  );
551cb0ef41Sopenharmony_ci  await pullCalledPromise;
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => byobRequest.respondWithNewView(newView));
581cb0ef41Sopenharmony_ci}, 'ReadableStream with byte source: respondWithNewView() with a non-transferable buffer');
59