tor-browser

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

formatting-NaN.js (948B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 // Any copyright is dedicated to the Public Domain.
      3 // http://creativecommons.org/licenses/publicdomain/
      4 
      5 //-----------------------------------------------------------------------------
      6 var BUGNUMBER = 1484943;
      7 var summary = "Don't crash doing format/formatToParts on -NaN";
      8 
      9 print(BUGNUMBER + ": " + summary);
     10 
     11 //-----------------------------------------------------------------------------
     12 
     13 assertEq("formatToParts" in Intl.NumberFormat(), true);
     14 
     15 var nf = new Intl.NumberFormat("en-US");
     16 var parts;
     17 
     18 var values = [NaN, -NaN];
     19 
     20 for (var v of values)
     21 {
     22  assertEq(nf.format(v), "NaN");
     23 
     24  parts = nf.formatToParts(v);
     25  assertEq(parts.length, 1);
     26  assertEq(parts[0].type, "nan");
     27  assertEq(parts[0].value, "NaN");
     28 }
     29 
     30 //-----------------------------------------------------------------------------
     31 
     32 if (typeof reportCompare === "function")
     33  reportCompare(0, 0, 'ok');
     34 
     35 print("Tests complete");