summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Number
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/intl402/Number
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.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/Number')
-rw-r--r--js/src/tests/test262/intl402/Number/browser.js0
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/browser.js0
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/shell.js0
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/browser.js0
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/builtin.js30
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/default-options-object-prototype.js21
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/length.js34
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/returns-same-results-as-NumberFormat.js40
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/shell.js19
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/taint-Intl-NumberFormat.js16
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/this-number-value.js28
-rw-r--r--js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js49
-rw-r--r--js/src/tests/test262/intl402/Number/shell.js0
13 files changed, 237 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Number/browser.js b/js/src/tests/test262/intl402/Number/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/browser.js
diff --git a/js/src/tests/test262/intl402/Number/prototype/browser.js b/js/src/tests/test262/intl402/Number/prototype/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/browser.js
diff --git a/js/src/tests/test262/intl402/Number/prototype/shell.js b/js/src/tests/test262/intl402/Number/prototype/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/shell.js
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/browser.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/browser.js
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/builtin.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/builtin.js
new file mode 100644
index 0000000000..cc3639f018
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/builtin.js
@@ -0,0 +1,30 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+es5id: 13.2.1_L15
+description: >
+ Tests that Number.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]
+---*/
+
+assert.sameValue(Object.prototype.toString.call(Number.prototype.toLocaleString), "[object Function]",
+ "The [[Class]] internal property of a built-in function must be " +
+ "\"Function\".");
+
+assert(Object.isExtensible(Number.prototype.toLocaleString),
+ "Built-in objects must be extensible.");
+
+assert.sameValue(Object.getPrototypeOf(Number.prototype.toLocaleString), Function.prototype);
+
+assert.sameValue(Number.prototype.toLocaleString.hasOwnProperty("prototype"), false,
+ "Built-in functions that aren't constructors must not have a prototype property.");
+
+assert.sameValue(isConstructor(Number.prototype.toLocaleString), false,
+ "Built-in functions don't implement [[Construct]] unless explicitly specified.");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/default-options-object-prototype.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/default-options-object-prototype.js
new file mode 100644
index 0000000000..d6d1f0693c
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/default-options-object-prototype.js
@@ -0,0 +1,21 @@
+// Copyright (C) 2017 Daniel Ehrenberg. 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*).
+---*/
+
+if (new Intl.NumberFormat("en").resolvedOptions().locale === "en") {
+ Object.prototype.maximumFractionDigits = 1;
+ assert.sameValue(1.23.toLocaleString("en"), "1.23");
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/length.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/length.js
new file mode 100644
index 0000000000..53286f8b64
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/length.js
@@ -0,0 +1,34 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sup-number.prototype.tolocalestring
+description: >
+ Number.prototype.toLocaleString.length is 0.
+info: |
+ Number.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]
+---*/
+
+verifyProperty(Number.prototype.toLocaleString, 'length', {
+ value: 0,
+ writable: false,
+ enumerable: false,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/returns-same-results-as-NumberFormat.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/returns-same-results-as-NumberFormat.js
new file mode 100644
index 0000000000..10c54d530b
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/returns-same-results-as-NumberFormat.js
@@ -0,0 +1,40 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es5id: 13.2.1_5
+description: >
+ Tests that Number.prototype.toLocaleString produces the same
+ results as Intl.NumberFormat.
+author: Norbert Lindenberg
+includes: [compareArray.js]
+---*/
+
+var numbers = [0, -0, 1, -1, 5.5, 123, -123, -123.45, 123.44501, 0.001234,
+ -0.00000000123, 0.00000000000000000000000000000123, 1.2, 0.0000000012344501,
+ 123445.01, 12344501000000000000000000000000000, -12344501000000000000000000000000000,
+ Infinity, -Infinity, NaN];
+var locales = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]];
+var options = [
+ 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}
+];
+
+locales.forEach(function (locales) {
+ options.forEach(function (options) {
+ var referenceNumberFormat = new Intl.NumberFormat(locales, options);
+ var referenceFormatted = numbers.map(referenceNumberFormat.format);
+
+ var formatted = numbers.map(function (a) { return a.toLocaleString(locales, options); });
+ assert.compareArray(formatted, referenceFormatted,
+ "(Testing with locales " + locales + "; options " +
+ (options ? JSON.stringify(options) : options) + ".)");
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/shell.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/shell.js
new file mode 100644
index 0000000000..54371b7789
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/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/Number/prototype/toLocaleString/taint-Intl-NumberFormat.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/taint-Intl-NumberFormat.js
new file mode 100644
index 0000000000..ba9a755568
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/taint-Intl-NumberFormat.js
@@ -0,0 +1,16 @@
+// Copyright 2013 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+es5id: 13.2.1_4_2
+description: >
+ Tests that Number.prototype.toLocaleString uses the standard
+ built-in Intl.NumberFormat constructor.
+author: Norbert Lindenberg
+includes: [testIntl.js]
+---*/
+
+taintDataProperty(Intl, "NumberFormat");
+(0.0).toLocaleString();
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/this-number-value.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/this-number-value.js
new file mode 100644
index 0000000000..86e68ef2ce
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/this-number-value.js
@@ -0,0 +1,28 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es5id: 13.2.1_1
+description: Tests that toLocaleString handles "this Number value" correctly.
+author: Norbert Lindenberg
+---*/
+
+var invalidValues = [undefined, null, "5", false, {valueOf: function () { return 5; }}];
+var validValues = [5, NaN, -1234567.89, -Infinity];
+
+invalidValues.forEach(function (value) {
+ assert.throws(TypeError, function() {
+ var result = Number.prototype.toLocaleString.call(value);
+ }, "Number.prototype.toLocaleString did not reject this = " + value + ".");
+});
+
+// for valid values, just check that a Number value and the corresponding
+// Number object get the same result.
+validValues.forEach(function (value) {
+ var Constructor = Number; // to keep jshint happy
+ var valueResult = Number.prototype.toLocaleString.call(value);
+ var objectResult = Number.prototype.toLocaleString.call(new Constructor(value));
+ assert.sameValue(valueResult, objectResult, "Number.prototype.toLocaleString produces different results for Number value " + value + " and corresponding Number object.");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js
new file mode 100644
index 0000000000..8dbb5b72a3
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js
@@ -0,0 +1,49 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es5id: 13.2.1_4_1
+description: >
+ Tests that Number.prototype.toLocaleString throws the same
+ exceptions as Intl.NumberFormat.
+author: Norbert Lindenberg
+---*/
+
+var locales = [null, [NaN], ["i"], ["de_DE"]];
+var options = [
+ {localeMatcher: null},
+ {style: "invalid"},
+ {style: "currency"},
+ {style: "currency", currency: "ßP"},
+ {maximumSignificantDigits: -Infinity}
+];
+
+locales.forEach(function (locales) {
+ 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 = (0).toLocaleString(locales);
+ }, "Number.prototype.toLocaleString didn't throw exception for locales " + locales + ".");
+});
+
+options.forEach(function (options) {
+ 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 = (0).toLocaleString([], options);
+ }, "Number.prototype.toLocaleString didn't throw exception for options " + JSON.stringify(options) + ".");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Number/shell.js b/js/src/tests/test262/intl402/Number/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/Number/shell.js