tor-browser

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

fun-call-apply-weird.js (973B)


      1 // |jit-test| --fast-warmup
      2 
      3 // Function with overridden call/apply (scripted).
      4 function funOverridden1(x, y) { return x + y; }
      5 funOverridden1.call = x => x + 1;
      6 funOverridden1.apply = x => x + 2;
      7 
      8 // Function with overridden call/apply (native).
      9 function funOverridden2(x, y) { return x + y; }
     10 funOverridden2.call = Math.abs;
     11 funOverridden2.apply = Math.abs;
     12 
     13 // Function with call/apply properties with other names.
     14 function funOverridden3(x, y) { return x + y; }
     15 funOverridden3.myCall = Function.prototype.call;
     16 funOverridden3.myApply = Function.prototype.apply;
     17 
     18 function f() {
     19    var arr = [1, 2];
     20    for (var i = 0; i < 100; i++) {
     21        assertEq(funOverridden1.call(i, i), i + 1);
     22        assertEq(funOverridden1.apply(i, i), i + 2);
     23 
     24        assertEq(funOverridden2.call(i, i), i);
     25        assertEq(funOverridden2.apply(i, i), i);
     26 
     27        assertEq(funOverridden3.myCall(null, i, i), i + i);
     28        assertEq(funOverridden3.myApply(null, arr), 3);
     29    }
     30 }
     31 f();