js/src/builtin/Number.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /*global intl_NumberFormat: false, */
michael@0 6
michael@0 7
michael@0 8 var numberFormatCache = new Record();
michael@0 9
michael@0 10
michael@0 11 /**
michael@0 12 * Format this Number object into a string, using the locale and formatting options
michael@0 13 * provided.
michael@0 14 *
michael@0 15 * Spec: ECMAScript Language Specification, 5.1 edition, 15.7.4.3.
michael@0 16 * Spec: ECMAScript Internationalization API Specification, 13.2.1.
michael@0 17 */
michael@0 18 function Number_toLocaleString() {
michael@0 19 // Steps 1-2. Note that valueOf enforces "this Number value" restrictions.
michael@0 20 var x = callFunction(std_Number_valueOf, this);
michael@0 21
michael@0 22 // Steps 2-3.
michael@0 23 var locales = arguments.length > 0 ? arguments[0] : undefined;
michael@0 24 var options = arguments.length > 1 ? arguments[1] : undefined;
michael@0 25
michael@0 26 // Step 4.
michael@0 27 var numberFormat;
michael@0 28 if (locales === undefined && options === undefined) {
michael@0 29 // This cache only optimizes for the old ES5 toLocaleString without
michael@0 30 // locales and options.
michael@0 31 if (numberFormatCache.numberFormat === undefined)
michael@0 32 numberFormatCache.numberFormat = intl_NumberFormat(locales, options);
michael@0 33 numberFormat = numberFormatCache.numberFormat;
michael@0 34 } else {
michael@0 35 numberFormat = intl_NumberFormat(locales, options);
michael@0 36 }
michael@0 37
michael@0 38 // Step 5.
michael@0 39 return intl_FormatNumber(numberFormat, x);
michael@0 40 }

mercurial