tor-browser

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

bug920484.js (1286B)


      1 load(libdir + "asserts.js");
      2 
      3 // Add an invalid "localeMatcher" option to Object.prototype, the exact value does not matter,
      4 // any value except "best fit" or "lookup" is okay.
      5 Object.prototype.localeMatcher = "invalid matcher option";
      6 
      7 // The Intl API may not be available in the testing environment.
      8 if (this.hasOwnProperty("Intl")) {
      9    // Intl constructors still work perfectly fine. The default options object doesn't inherit
     10    // from Object.prototype and the invalid "localeMatcher" value from Object.prototype isn't
     11    // consulted.
     12    new Intl.Collator().compare("a", "b");
     13    new Intl.NumberFormat().format(10);
     14    new Intl.DateTimeFormat().format(new Date);
     15 
     16    // If an explicit "localeMatcher" option is given, the default from Object.prototype is ignored.
     17    new Intl.Collator(void 0, {localeMatcher: "lookup"}).compare("a", "b");
     18    new Intl.NumberFormat(void 0, {localeMatcher: "lookup"}).format(10);
     19    new Intl.DateTimeFormat(void 0, {localeMatcher: "lookup"}).format(new Date);
     20 
     21    delete Object.prototype.localeMatcher;
     22 
     23    // After removing the default option from Object.prototype, everything still works as expected.
     24    new Intl.Collator().compare("a", "b");
     25    new Intl.NumberFormat().format(10);
     26    new Intl.DateTimeFormat().format(new Date);
     27 }