tor-browser

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

resizable-dataview-get-elem.js (1023B)


      1 load(libdir + "dataview.js");
      2 
      3 const TypedArrays = [
      4  Int8Array,
      5  Uint8Array,
      6  Int16Array,
      7  Uint16Array,
      8  Int32Array,
      9  Uint32Array,
     10  Float16Array,
     11  Float32Array,
     12  Float64Array,
     13  BigInt64Array,
     14  BigUint64Array,
     15 ];
     16 
     17 function test(TA) {
     18  const length = 4;
     19  const byteLength = length * TA.BYTES_PER_ELEMENT;
     20 
     21  let rab = new ArrayBuffer(byteLength, {maxByteLength: byteLength});
     22  let actual = new TA(rab);
     23  let expected = new TA(length);
     24  let type = expected[0].constructor;
     25 
     26  for (let i = 0; i < length; ++i) {
     27    actual[i] = type(i * i);
     28    expected[i] = type(i * i);
     29  }
     30 
     31  let dv = new DataView(rab);
     32  for (let i = 0; i < 200; ++i) {
     33    let index = i % length;
     34    let byteIndex = index * TA.BYTES_PER_ELEMENT;
     35 
     36    assertEq(dv.getElem(byteIndex, nativeIsLittleEndian), expected[index]);
     37  }
     38 }
     39 
     40 for (let TA of TypedArrays) {
     41  let getter = "get" + typeName(TA);
     42 
     43  // Copy test function to ensure monomorphic ICs.
     44  let copy = Function(`return ${test}`.replaceAll("getElem", getter))();
     45 
     46  copy(TA);
     47 }