tor-browser

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

immutable-dataview-get-elem.js (1107B)


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