js/src/builtin/Number.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:151bb90324c2
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/. */
4
5 /*global intl_NumberFormat: false, */
6
7
8 var numberFormatCache = new Record();
9
10
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);
21
22 // Steps 2-3.
23 var locales = arguments.length > 0 ? arguments[0] : undefined;
24 var options = arguments.length > 1 ? arguments[1] : undefined;
25
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 }
37
38 // Step 5.
39 return intl_FormatNumber(numberFormat, x);
40 }

mercurial