tor-browser

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

this-value-ignored.js (1231B)


      1 // Copyright 2012 Mozilla Corporation. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-intl-numberformat-constructor
      6 description: >
      7    Tests that the this-value is ignored in NumberFormat, if the this-value
      8    isn't a NumberFormat instance.
      9 author: Norbert Lindenberg
     10 includes: [testIntl.js]
     11 ---*/
     12 
     13 testWithIntlConstructors(function (Constructor) {
     14    if (Constructor === Intl.NumberFormat)
     15        return;
     16 
     17    var obj, newObj;
     18 
     19    // variant 1: use constructor in a "new" expression
     20    obj = new Constructor();
     21    newObj = Intl.NumberFormat.call(obj);
     22    assert.notSameValue(obj, newObj, "NumberFormat object created with \"new\" was not ignored as this-value.");
     23 
     24    // variant 2: use constructor as a function
     25    if (Constructor !== Intl.Collator &&
     26        Constructor !== Intl.NumberFormat &&
     27        Constructor !== Intl.DateTimeFormat)
     28    {
     29        // Newer Intl constructors are not callable as a function.
     30        return;
     31    }
     32    obj = Constructor();
     33    newObj = Intl.NumberFormat.call(obj);
     34    assert.notSameValue(obj, newObj, "NumberFormat object created with constructor as function was not ignored as this-value.");
     35 });
     36 
     37 reportCompare(0, 0);