• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=window,worker
2'use strict';
3
4promise_test(async t => {
5  const rs = new ReadableStream({
6    pull: t.unreached_func('pull() should not be called'),
7    type: 'bytes'
8  });
9
10  const reader = rs.getReader({ mode: 'byob' });
11  const memory = new WebAssembly.Memory({ initial: 1 });
12  const view = new Uint8Array(memory.buffer, 0, 1);
13  await promise_rejects_js(t, TypeError, reader.read(view));
14}, 'ReadableStream with byte source: read() with a non-transferable buffer');
15
16test(t => {
17  let controller;
18  const rs = new ReadableStream({
19    start(c) {
20      controller = c;
21    },
22    pull: t.unreached_func('pull() should not be called'),
23    type: 'bytes'
24  });
25
26  const memory = new WebAssembly.Memory({ initial: 1 });
27  const view = new Uint8Array(memory.buffer, 0, 1);
28  assert_throws_js(TypeError, () => controller.enqueue(view));
29}, 'ReadableStream with byte source: enqueue() with a non-transferable buffer');
30
31promise_test(async t => {
32  let byobRequest;
33  let resolvePullCalledPromise;
34  const pullCalledPromise = new Promise(resolve => {
35    resolvePullCalledPromise = resolve;
36  });
37  const rs = new ReadableStream({
38    pull(controller) {
39      byobRequest = controller.byobRequest;
40      resolvePullCalledPromise();
41    },
42    type: 'bytes'
43  });
44
45  const memory = new WebAssembly.Memory({ initial: 1 });
46  // Make sure the backing buffers of both views have the same length
47  const byobView = new Uint8Array(new ArrayBuffer(memory.buffer.byteLength), 0, 1);
48  const newView = new Uint8Array(memory.buffer, byobView.byteOffset, byobView.byteLength);
49
50  const reader = rs.getReader({ mode: 'byob' });
51  reader.read(byobView).then(
52    t.unreached_func('read() should not resolve'),
53    t.unreached_func('read() should not reject')
54  );
55  await pullCalledPromise;
56
57  assert_throws_js(TypeError, () => byobRequest.respondWithNewView(newView));
58}, 'ReadableStream with byte source: respondWithNewView() with a non-transferable buffer');
59