tor-browser

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

binaryarith-date-with-proxy.js (1412B)


      1 setJitCompilerOption('ion.forceinlineCaches', 1);
      2 
      3 function warmup(fun, input_array) {
      4  for (var index = 0; index < input_array.length; index++) {
      5      input = input_array[index];
      6      input_lhs = input[0];
      7      input_rhs = input[1];
      8      output    = input[2];
      9      for (var i = 0; i < 30; i++) {
     10          var y = fun(input_lhs, input_rhs);
     11          assertEq(y, output)
     12      }
     13  }
     14 }
     15 
     16 {
     17  // check that binding a date object with a proxy does not affect the inlined Date subtraction.
     18  const testCases = [[new Date("2024-09-20T19:54:27.432Z"), new Date("2024-09-20T19:54:27.427Z"), 5],
     19                 [new Date("2024-09-20T19:54:27.432Z"), 1726862067427, 5],
     20                 [1726862067427, new Date("2024-09-20T19:54:27.432Z"), -5]];
     21  const funDateSub = (a, b) => { return a - b; }
     22  warmup(funDateSub, testCases);
     23 
     24  let proxyCalled = false;
     25  const proxy = new Proxy(new Date("2024-09-20T19:54:27.432Z"), {
     26    get: function(target, prop, receiver) {
     27      if (prop === "valueOf") {
     28        proxyCalled = true;
     29        const fn = function() {
     30          return 1726862067433;
     31        }
     32        return fn.bind(target);
     33      }
     34      return Reflect.get(target, prop, receiver);
     35    }
     36  });
     37 
     38  assertEq(funDateSub(proxy, new Date("2024-09-20T19:54:27.427Z")), 6);
     39  assertEq(proxyCalled, true);
     40 
     41  proxyCalled = false;
     42  assertEq(funDateSub(proxy, 1726862067427), 6);
     43  assertEq(proxyCalled, true);
     44 }