tor-browser

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

call.js (2504B)


      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 IsObject(o) {
     10    return Object(o) === o;
     11 }
     12 
     13 function thisValues() {
     14    const intlConstructors = Object.getOwnPropertyNames(Intl).map(name => Intl[name]).filter(IsIntlService);
     15 
     16    return [
     17        // Primitive values.
     18        ...[undefined, null, true, "abc", Symbol(), 123],
     19 
     20        // Object values.
     21        ...[{}, [], /(?:)/, function(){}, new Proxy({}, {})],
     22 
     23        // Intl objects.
     24        ...[].concat(...intlConstructors.map(ctor => {
     25            let args = [];
     26            if (ctor === Intl.DisplayNames) {
     27                // Intl.DisplayNames can't be constructed without any arguments.
     28                args = [undefined, {type: "language"}];
     29            }
     30 
     31            return [
     32                // Instance of an Intl constructor.
     33                new ctor(...args),
     34 
     35                // Instance of a subclassed Intl constructor.
     36                new class extends ctor {}(...args),
     37 
     38                // Object inheriting from an Intl constructor prototype.
     39                Object.create(ctor.prototype),
     40 
     41                // Intl object not inheriting from its default prototype.
     42                Object.setPrototypeOf(new ctor(...args), Object.prototype),
     43            ];
     44        })),
     45    ];
     46 }
     47 
     48 // Invoking [[Call]] for Intl.Collator always returns a new Collator instance.
     49 for (let thisValue of thisValues()) {
     50    let obj = Intl.Collator.call(thisValue);
     51    assertEq(Object.is(obj, thisValue), false);
     52    assertEq(obj instanceof Intl.Collator, true);
     53 
     54    // Ensure Intl.[[FallbackSymbol]] wasn't installed on |thisValue|.
     55    if (IsObject(thisValue))
     56        assertEqArray(Object.getOwnPropertySymbols(thisValue), []);
     57 }
     58 
     59 // Intl.Collator doesn't use the legacy Intl constructor compromise semantics.
     60 for (let thisValue of thisValues()) {
     61    // Ensure instanceof operator isn't invoked for Intl.Collator.
     62    Object.defineProperty(Intl.Collator, Symbol.hasInstance, {
     63        get() {
     64            assertEq(false, true, "@@hasInstance operator called");
     65        }, configurable: true
     66    });
     67    let obj = Intl.Collator.call(thisValue);
     68    delete Intl.Collator[Symbol.hasInstance];
     69    assertEq(Object.is(obj, thisValue), false);
     70    assertEq(obj instanceof Intl.Collator, true);
     71 }
     72 
     73 if (typeof reportCompare === "function")
     74    reportCompare(true, true);