tor-browser

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

resizable-dataview-set-elem.js (990B)


      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  let dv = new DataView(rab);
     27  for (let i = 0; i < 200; ++i) {
     28    let index = i % length;
     29    let byteIndex = index * TA.BYTES_PER_ELEMENT;
     30 
     31    let v = type(i);
     32    dv.setElem(byteIndex, v, nativeIsLittleEndian);
     33    expected[index] = v;
     34 
     35    assertEq(actual[index], expected[index]);
     36  }
     37 }
     38 
     39 for (let TA of TypedArrays) {
     40  let setter = "set" + typeName(TA);
     41 
     42  // Copy test function to ensure monomorphic ICs.
     43  let copy = Function(`return ${test}`.replaceAll("setElem", setter))();
     44 
     45  copy(TA);
     46 }