michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /*global intl_NumberFormat: false, */ michael@0: michael@0: michael@0: var numberFormatCache = new Record(); michael@0: michael@0: michael@0: /** michael@0: * Format this Number object into a string, using the locale and formatting options michael@0: * provided. michael@0: * michael@0: * Spec: ECMAScript Language Specification, 5.1 edition, 15.7.4.3. michael@0: * Spec: ECMAScript Internationalization API Specification, 13.2.1. michael@0: */ michael@0: function Number_toLocaleString() { michael@0: // Steps 1-2. Note that valueOf enforces "this Number value" restrictions. michael@0: var x = callFunction(std_Number_valueOf, this); michael@0: michael@0: // Steps 2-3. michael@0: var locales = arguments.length > 0 ? arguments[0] : undefined; michael@0: var options = arguments.length > 1 ? arguments[1] : undefined; michael@0: michael@0: // Step 4. michael@0: var numberFormat; michael@0: if (locales === undefined && options === undefined) { michael@0: // This cache only optimizes for the old ES5 toLocaleString without michael@0: // locales and options. michael@0: if (numberFormatCache.numberFormat === undefined) michael@0: numberFormatCache.numberFormat = intl_NumberFormat(locales, options); michael@0: numberFormat = numberFormatCache.numberFormat; michael@0: } else { michael@0: numberFormat = intl_NumberFormat(locales, options); michael@0: } michael@0: michael@0: // Step 5. michael@0: return intl_FormatNumber(numberFormat, x); michael@0: }