tor-browser

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

call.js (1731B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 function IsIntlService(c) {
      4    return typeof c === "function" &&
      5           c.hasOwnProperty("prototype") &&
      6           c.prototype.hasOwnProperty("resolvedOptions");
      7 }
      8 
      9 function thisValues() {
     10    const intlConstructors = Object.getOwnPropertyNames(Intl).map(name => Intl[name]).filter(IsIntlService);
     11 
     12    return [
     13        // Primitive values.
     14        ...[undefined, null, true, "abc", Symbol(), 123],
     15 
     16        // Object values.
     17        ...[{}, [], /(?:)/, function(){}, new Proxy({}, {})],
     18 
     19        // Intl objects.
     20        ...[].concat(...intlConstructors.map(ctor => {
     21            let args = [];
     22            if (ctor === Intl.DisplayNames) {
     23                // Intl.DisplayNames can't be constructed without any arguments.
     24                args = [undefined, {type: "language"}];
     25            }
     26 
     27            return [
     28                // Instance of an Intl constructor.
     29                new ctor(...args),
     30 
     31                // Instance of a subclassed Intl constructor.
     32                new class extends ctor {}(...args),
     33 
     34                // Object inheriting from an Intl constructor prototype.
     35                Object.create(ctor.prototype),
     36 
     37                // Intl object not inheriting from its default prototype.
     38                Object.setPrototypeOf(new ctor(...args), Object.prototype),
     39            ];
     40        })),
     41    ];
     42 }
     43 
     44 // Intl.PluralRules cannot be invoked as a function.
     45 assertThrowsInstanceOf(() => Intl.PluralRules(), TypeError);
     46 
     47 // Also test with explicit this-value.
     48 for (let thisValue of thisValues()) {
     49    assertThrowsInstanceOf(() => Intl.PluralRules.call(thisValue), TypeError);
     50 }
     51 
     52 if (typeof reportCompare === "function")
     53    reportCompare(true, true);