diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/intl402/BigInt | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/intl402/BigInt')
17 files changed, 370 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/BigInt/browser.js b/js/src/tests/test262/intl402/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/browser.js diff --git a/js/src/tests/test262/intl402/BigInt/prototype/browser.js b/js/src/tests/test262/intl402/BigInt/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/browser.js diff --git a/js/src/tests/test262/intl402/BigInt/prototype/shell.js b/js/src/tests/test262/intl402/BigInt/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/shell.js diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/browser.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/browser.js diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/builtin.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/builtin.js new file mode 100644 index 0000000000..c3c87d4b85 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/builtin.js @@ -0,0 +1,31 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// Copyright 2019 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: > + Tests that BigInt.prototype.toLocaleString meets the requirements + for built-in objects defined by the introduction of chapter 17 of + the ECMAScript Language Specification. +author: Norbert Lindenberg +includes: [isConstructor.js] +features: [Reflect.construct, BigInt] +---*/ + +assert.sameValue(Object.prototype.toString.call(BigInt.prototype.toLocaleString), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(BigInt.prototype.toLocaleString), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(BigInt.prototype.toLocaleString), Function.prototype); + +assert.sameValue(BigInt.prototype.toLocaleString.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(BigInt.prototype.toLocaleString), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/de-DE.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/de-DE.js new file mode 100644 index 0000000000..b92250d0c2 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/de-DE.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: Checks basic behavior for BigInt.prototype.toLocaleString. +locale: [de-DE] +features: [BigInt] +---*/ + +const tests = [ + [0n, undefined, "0"], + [-0n, undefined, "0"], + [88776655n, { "maximumSignificantDigits": 4 }, "88.780.000"], + [88776655n, { "maximumSignificantDigits": 4, "style": "percent" }, "8.878.000.000\u00a0%"], + [88776655n, { "minimumFractionDigits": 3 }, "88.776.655,000"], + [90071992547409910n, undefined, "90.071.992.547.409.910"], +]; + +for (const [bigint, options, expected] of tests) { + const result = bigint.toLocaleString("de-DE", options); + assert.sameValue(result, expected); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/default-options-object-prototype.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/default-options-object-prototype.js new file mode 100644 index 0000000000..893e074082 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/default-options-object-prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved. +// Copyright (C) 2019 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializenumberformat +description: > + Monkey-patching Object.prototype does not change the default + options for NumberFormat as a null prototype is used. +info: | + InitializeNumberFormat ( numberFormat, locales, options ) + + 1. If _options_ is *undefined*, then + 1. Let _options_ be ObjectCreate(*null*). +locale: [en-US] +features: [BigInt] +---*/ + +Object.prototype.useGrouping = false; +assert.sameValue(12345n.toLocaleString("en-US"), "12,345"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/en-US.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/en-US.js new file mode 100644 index 0000000000..96a0824ba9 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/en-US.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: Checks basic behavior for BigInt.prototype.toLocaleString. +locale: [en-US] +features: [BigInt] +---*/ + +const tests = [ + [0n, undefined, "0"], + [-0n, undefined, "0"], + [88776655n, { "maximumSignificantDigits": 4 }, "88,780,000"], + [88776655n, { "maximumSignificantDigits": 4, "style": "percent" }, "8,878,000,000%"], + [88776655n, { "minimumFractionDigits": 3 }, "88,776,655.000"], + [90071992547409910n, undefined, "90,071,992,547,409,910"], +]; + +for (const [bigint, options, expected] of tests) { + const result = bigint.toLocaleString("en-US", options); + assert.sameValue(result, expected); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/length.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/length.js new file mode 100644 index 0000000000..6653858f1b --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/length.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// Copyright (C) 2019 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: > + BigInt.prototype.toLocaleString.length is 0. +info: | + BigInt.prototype.toLocaleString ( [ locales [ , options ] ] ) + + 17 ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype.toLocaleString, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/name.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/name.js new file mode 100644 index 0000000000..cab1cf03f4 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/name.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: > + BigInt.prototype.toLocaleString.name is toLocaleString. +info: | + BigInt.prototype.toLocaleString ( [ locales [ , options ] ] ) + + 17 ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. For functions that are specified as properties of objects, + the name value is the property name string used to access the function. + + Unless otherwise specified, the name property of a built-in function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt.prototype.toLocaleString, "name", { + value: "toLocaleString", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/prop-desc.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/prop-desc.js new file mode 100644 index 0000000000..2b2c64d7d7 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/prop-desc.js @@ -0,0 +1,32 @@ +// Copyright (C) 2019 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: Checks the "toLocaleString" property of the BigInt prototype object. +info: | + BigInt.prototype.toLocaleString ( [ locales [ , options ] ] ) + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. + +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +assert.sameValue( + typeof BigInt.prototype.toLocaleString, + "function", + "typeof BigInt.prototype.toLocaleString is function" +); + +verifyProperty(BigInt.prototype, "toLocaleString", { + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/returns-same-results-as-NumberFormat.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/returns-same-results-as-NumberFormat.js new file mode 100644 index 0000000000..5083fe05f5 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/returns-same-results-as-NumberFormat.js @@ -0,0 +1,49 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// Copyright 2019 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: > + Tests that BigInt.prototype.toLocaleString produces the same + results as Intl.BigIntFormat. +features: [BigInt] +---*/ + +var inputs = [ + 0n, + -0n, + 1n, + -1n, + 123n, + -123n, + 12345n, + -12345n, + 12344501000000000000000000000000000n, + -12344501000000000000000000000000000n, +]; +var localesInputs = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]]; +var optionsInputs = [ + undefined, + {style: "percent"}, + {style: "currency", currency: "EUR", currencyDisplay: "symbol"}, + {style: "currency", currency: "IQD", currencyDisplay: "symbol"}, + {style: "currency", currency: "KMF", currencyDisplay: "symbol"}, + {style: "currency", currency: "CLF", currencyDisplay: "symbol"}, + {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3} +]; + +for (const locales of localesInputs) { + for (const options of optionsInputs) { + const optionsString = options ? JSON.stringify(options) : String(options); + const referenceNumberFormat = new Intl.NumberFormat(locales, options); + for (const input of inputs) { + const referenceFormatted = referenceNumberFormat.format(input); + const formatted = input.toLocaleString(locales, options); + assert.sameValue(formatted, referenceFormatted, + `(Testing with locales ${locales}; options ${optionsString}.)`); + } + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/shell.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/shell.js @@ -0,0 +1,19 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/taint-Intl-NumberFormat.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/taint-Intl-NumberFormat.js new file mode 100644 index 0000000000..f918e5537c --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/taint-Intl-NumberFormat.js @@ -0,0 +1,17 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// Copyright 2019 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: > + Tests that Number.prototype.toLocaleString uses the standard + built-in Intl.NumberFormat constructor. +includes: [testIntl.js] +features: [BigInt] +---*/ + +taintDataProperty(Intl, "NumberFormat"); +0n.toLocaleString(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/this-value-invalid.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/this-value-invalid.js new file mode 100644 index 0000000000..cfc9053033 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/this-value-invalid.js @@ -0,0 +1,31 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// Copyright 2019 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: Tests that toLocaleString handles "thisBigIntValue" correctly. +features: [BigInt] +---*/ + +var invalidValues = [ + undefined, + null, + false, + "5", + Symbol(), + 5, + -1234567.89, + NaN, + -Infinity, + {valueOf: function () { return 5; }}, + {valueOf: function () { return 5n; }}, +]; + +for (const value of invalidValues) { + assert.throws(TypeError, function() { + BigInt.prototype.toLocaleString.call(value); + }, `BigInt.prototype.toLocaleString did not throw with this = ${String(value)}.`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js new file mode 100644 index 0000000000..f4cb784959 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js @@ -0,0 +1,50 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// Copyright 2019 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-bigint.prototype.tolocalestring +description: > + Tests that BigInt.prototype.toLocaleString throws the same + exceptions as Intl.NumberFormat. +features: [BigInt] +---*/ + +var localesInputs = [null, [NaN], ["i"], ["de_DE"]]; +var optionsInputs = [ + {localeMatcher: null}, + {style: "invalid"}, + {style: "currency"}, + {style: "currency", currency: "ßP"}, + {maximumSignificantDigits: -Infinity} +]; + +for (const locales of localesInputs) { + var referenceError, error; + try { + var format = new Intl.NumberFormat(locales); + } catch (e) { + referenceError = e; + } + assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.NumberFormat for locales " + locales + "."); + + assert.throws(referenceError.constructor, function() { + var result = 0n.toLocaleString(locales); + }, "BigInt.prototype.toLocaleString didn't throw exception for locales " + locales + "."); +} + +for (const options of optionsInputs) { + var referenceError, error; + try { + var format = new Intl.NumberFormat([], options); + } catch (e) { + referenceError = e; + } + assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.NumberFormat for options " + JSON.stringify(options) + "."); + + assert.throws(referenceError.constructor, function() { + var result = 0n.toLocaleString([], options); + }, "BigInt.prototype.toLocaleString didn't throw exception for options " + JSON.stringify(options) + "."); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/BigInt/shell.js b/js/src/tests/test262/intl402/BigInt/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/BigInt/shell.js |