tor-browser

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

decode-bad-chunks.any.js (834B)


      1 // META: global=window,worker,shadowrealm
      2 
      3 'use strict';
      4 
      5 const badChunks = [
      6  {
      7    name: 'undefined',
      8    value: undefined
      9  },
     10  {
     11    name: 'null',
     12    value: null
     13  },
     14  {
     15    name: 'numeric',
     16    value: 3.14
     17  },
     18  {
     19    name: 'object, not BufferSource',
     20    value: {}
     21  },
     22  {
     23    name: 'array',
     24    value: [65]
     25  }
     26 ];
     27 
     28 for (const chunk of badChunks) {
     29  promise_test(async t => {
     30    const tds = new TextDecoderStream();
     31    const reader = tds.readable.getReader();
     32    const writer = tds.writable.getWriter();
     33    const writePromise = writer.write(chunk.value);
     34    const readPromise = reader.read();
     35    await promise_rejects_js(t, TypeError, writePromise, 'write should reject');
     36    await promise_rejects_js(t, TypeError, readPromise, 'read should reject');
     37  }, `chunk of type ${chunk.name} should error the stream`);
     38 }