Bumping manifests a=b2g-bump
[gecko.git] / js / src / builtin / Number.js
blob07b2be57abe45e979704b42002818b047249d394
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /*global intl_NumberFormat: false, */
8 var numberFormatCache = new Record();
11 /**
12  * Format this Number object into a string, using the locale and formatting options
13  * provided.
14  *
15  * Spec: ECMAScript Language Specification, 5.1 edition, 15.7.4.3.
16  * Spec: ECMAScript Internationalization API Specification, 13.2.1.
17  */
18 function Number_toLocaleString() {
19     // Steps 1-2.  Note that valueOf enforces "this Number value" restrictions.
20     var x = callFunction(std_Number_valueOf, this);
22     // Steps 2-3.
23     var locales = arguments.length > 0 ? arguments[0] : undefined;
24     var options = arguments.length > 1 ? arguments[1] : undefined;
26     // Step 4.
27     var numberFormat;
28     if (locales === undefined && options === undefined) {
29         // This cache only optimizes for the old ES5 toLocaleString without
30         // locales and options.
31         if (numberFormatCache.numberFormat === undefined)
32             numberFormatCache.numberFormat = intl_NumberFormat(locales, options);
33         numberFormat = numberFormatCache.numberFormat;
34     } else {
35         numberFormat = intl_NumberFormat(locales, options);
36     }
38     // Step 5.
39     return intl_FormatNumber(numberFormat, x);
42 // ES6 draft ES6 20.1.2.4
43 function Number_isFinite(num) {
44     if (typeof num !== "number")
45         return false;
46     return num - num === 0;
49 // ES6 draft ES6 20.1.2.2
50 function Number_isNaN(num) {
51     if (typeof num !== "number")
52         return false;
53     return num !== num;
56 // ES6 draft ES6 20.1.2.5
57 function Number_isSafeInteger(number) {
58     // Step 1.
59     if (typeof number !== 'number')
60         return false;
62     // Step 2.
63     if (!Number_isFinite(number))
64         return false;
66     // Step 3.
67     var integer = ToInteger(number);
69     // Step 4.
70     if (integer !== number)
71         return false;
73     // Step 5. If abs(integer) <= 2**53 - 1, return true.
74     if (std_Math_abs(integer) <= 9007199254740991)
75         return true;
77     // Step 6.
78     return false;
81 function Global_isNaN(number) {
82     return Number_isNaN(ToNumber(number));
85 function Global_isFinite(number){
86     return Number_isFinite(ToNumber(number));