tor-browser

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

object-keys-06.js (1275B)


      1 load(libdir + 'array-compare.js'); // arraysEqual
      2 
      3 // Ion eager fails the test below because we have not yet created any
      4 // Cache IR IC in baseline before running the content of the top-level
      5 // function.
      6 if (getJitCompilerOptions()["ion.warmup.trigger"] <= 100)
      7    setJitCompilerOption("ion.warmup.trigger", 100);
      8 
      9 // This test case checks that we are capable of recovering the Object.keys array
     10 // even if we optimized it away. It also checks that we indeed optimize it away
     11 // as we would expect.
     12 
     13 // Prevent GC from cancelling/discarding Ion compilations.
     14 gczeal(0);
     15 
     16 function objKeysIterate(obj, expected, i) {
     17    var keys = Object.keys(obj);
     18    for (let i = 0; i < keys.length; i++) {
     19        assertEq(keys[i], expected[i]);
     20    }
     21    assertRecoveredOnBailout(keys, true);
     22 }
     23 
     24 function objKeysIterateMutated(obj, expected, i) {
     25    var keys = Object.keys(obj);
     26    obj.foo = 42;
     27    for (let i = 0; i < keys.length; i++) {
     28        assertEq(keys[i], expected[i]);
     29    }
     30    assertRecoveredOnBailout(keys, true);
     31 }
     32 
     33 // Prevent compilation of the top-level.
     34 eval(`${arraysEqual}`);
     35 let obj = {a: 0, b: 1, c: 2, d: 3};
     36 
     37 for (let i = 0; i < 100; i++) {
     38    objKeysIterate({...obj}, ["a", "b", "c", "d"], i);
     39    objKeysIterateMutated({...obj}, ["a", "b", "c", "d"], i);
     40 }