Debian Codegraph @

js/src/builtin/BigInt.js

raw
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 #if JS_HAS_INTL_API
6 /**
7 * Format this BigInt object into a string, using the locale and formatting
8 * options provided.
9 *
10 * Spec PR: https://github.com/tc39/ecma402/pull/236
11 */
12 function BigInt_toLocaleString() {
13 // Step 1. Note that valueOf enforces "thisBigIntValue" restrictions.
14 var x = callFunction(std_BigInt_valueOf, this);
15
16 var locales = ArgumentsLength() ? GetArgument(0) : undefined;
17 var options = ArgumentsLength() > 1 ? GetArgument(1) : undefined;
18
19 // Step 2.
20 var numberFormat;
21 if (locales === undefined && options === undefined) {
22 // This cache only optimizes when no explicit locales and options
23 // arguments were supplied.
24 if (!intl_IsRuntimeDefaultLocale(numberFormatCache.runtimeDefaultLocale)) {
25 numberFormatCache.numberFormat = intl_NumberFormat(locales, options);
26 numberFormatCache.runtimeDefaultLocale = intl_RuntimeDefaultLocale();
27 }
28 numberFormat = numberFormatCache.numberFormat;
29 } else {
30 numberFormat = intl_NumberFormat(locales, options);
31 }
32
33 // Step 3.
34 return intl_FormatNumber(numberFormat, x, /* formatToParts = */ false);
35 }
36 #endif // JS_HAS_INTL_API