tor-browser

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

access-formals.js (887B)


      1 function g1(x, args) {
      2    args[0] = 88;
      3 }
      4 
      5 // We assume we can optimize arguments access in |f|.
      6 //
      7 // Then the apply-call invalidates the arguments optimization,
      8 // and creates a real arguments object.
      9 //
     10 // Test that x and y fetch the values from the args object when
     11 // that happens.
     12 function f1(x, y, o) {
     13    var res = 0;
     14    for (var i=0; i<50; i++) {
     15 res += x + y;
     16 if (i > 10)
     17     o.apply(null, arguments);
     18    }
     19    return res;
     20 }
     21 
     22 var o1 = {apply: g1};
     23 assertEq(f1(3, 5, o1), 3630);
     24 assertEq(f1(3, 5, o1), 3630);
     25 
     26 // In strict mode, the arguments object does not alias formals.
     27 function g2(x, args) {
     28    args[0] = 88;
     29 }
     30 
     31 function f2(x, y, o) {
     32    "use strict";
     33    var res = 0;
     34    for (var i=0; i<50; i++) {
     35 res += x + y;
     36 if (i > 10)
     37     o.apply(null, arguments);
     38    }
     39    return res;
     40 }
     41 
     42 var o2 = {apply: g2};
     43 assertEq(f2(3, 5, o2), 400);
     44 assertEq(f2(3, 5, o2), 400);