tor-browser

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

inlinable-native-accessor-2.js (796B)


      1 // Test calling an inlinable native function as an accessor property.
      2 
      3 // Install the inlinable Number.prototype.toString method as an accessor property.
      4 Object.defineProperty(Number.prototype, "tostr", {
      5  get: Number.prototype.toString,
      6 });
      7 
      8 function testWithPrimitive() {
      9  var key = "tostr";
     10  for (var i = 0; i < 100; ++i) {
     11    assertEq(i.tostr, i.toString());
     12    assertEq(i[key], i.toString());
     13  }
     14 }
     15 testWithPrimitive();
     16 
     17 // Install the inlinable Date.prototype.getTime method as an accessor property.
     18 Object.defineProperty(Date.prototype, "time", {
     19  get: Date.prototype.getTime,
     20 });
     21 
     22 function testWithObject() {
     23  var key = "time";
     24  for (var i = 0; i < 100; ++i) {
     25    var d = new Date(i);
     26    assertEq(d.time, d.getTime());
     27    assertEq(d[key], d.getTime());
     28  }
     29 }
     30 testWithObject();