tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

non-transferable-buffers.any.js (2427B)


      1 // META: global=window,worker,shadowrealm
      2 'use strict';
      3 
      4 promise_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 
     16 promise_test(async t => {
     17  const rs = new ReadableStream({
     18    pull: t.unreached_func('pull() should not be called'),
     19    type: 'bytes'
     20  });
     21 
     22  const reader = rs.getReader({ mode: 'byob' });
     23  const memory = new WebAssembly.Memory({ initial: 1 });
     24  const view = new Uint8Array(memory.buffer, 0, 1);
     25  await promise_rejects_js(t, TypeError, reader.read(view, { min: 1 }));
     26 }, 'ReadableStream with byte source: fill() with a non-transferable buffer');
     27 
     28 test(t => {
     29  let controller;
     30  const rs = new ReadableStream({
     31    start(c) {
     32      controller = c;
     33    },
     34    pull: t.unreached_func('pull() should not be called'),
     35    type: 'bytes'
     36  });
     37 
     38  const memory = new WebAssembly.Memory({ initial: 1 });
     39  const view = new Uint8Array(memory.buffer, 0, 1);
     40  assert_throws_js(TypeError, () => controller.enqueue(view));
     41 }, 'ReadableStream with byte source: enqueue() with a non-transferable buffer');
     42 
     43 promise_test(async t => {
     44  let byobRequest;
     45  let resolvePullCalledPromise;
     46  const pullCalledPromise = new Promise(resolve => {
     47    resolvePullCalledPromise = resolve;
     48  });
     49  const rs = new ReadableStream({
     50    pull(controller) {
     51      byobRequest = controller.byobRequest;
     52      resolvePullCalledPromise();
     53    },
     54    type: 'bytes'
     55  });
     56 
     57  const memory = new WebAssembly.Memory({ initial: 1 });
     58  // Make sure the backing buffers of both views have the same length
     59  const byobView = new Uint8Array(new ArrayBuffer(memory.buffer.byteLength), 0, 1);
     60  const newView = new Uint8Array(memory.buffer, byobView.byteOffset, byobView.byteLength);
     61 
     62  const reader = rs.getReader({ mode: 'byob' });
     63  reader.read(byobView).then(
     64    t.unreached_func('read() should not resolve'),
     65    t.unreached_func('read() should not reject')
     66  );
     67  await pullCalledPromise;
     68 
     69  assert_throws_js(TypeError, () => byobRequest.respondWithNewView(newView));
     70 }, 'ReadableStream with byte source: respondWithNewView() with a non-transferable buffer');