summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions')
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/basic.js45
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/browser.js0
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/builtin.js30
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/compactDisplay.js26
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/length.js34
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/name.js29
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/no-instanceof.js26
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/order.js43
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/prop-desc.js33
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/return-keys-order-default.js49
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/roundingMode.js42
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/shell.js24
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js23
13 files changed, 404 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/basic.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/basic.js
new file mode 100644
index 0000000000..ffde22cf3a
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/basic.js
@@ -0,0 +1,45 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// Copyright 2022 Apple Inc. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+es5id: 11.3.3
+description: >
+ Tests that the object returned by
+ Intl.NumberFormat.prototype.resolvedOptions has the right
+ properties.
+author: Norbert Lindenberg
+includes: [testIntl.js, propertyHelper.js]
+features: [Intl.NumberFormat-v3]
+---*/
+
+var actual = new Intl.NumberFormat().resolvedOptions();
+
+var actual2 = new Intl.NumberFormat().resolvedOptions();
+assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice.");
+
+// this assumes the default values where the specification provides them
+assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale),
+ "Invalid locale: " + actual.locale);
+assert(isValidNumberingSystem(actual.numberingSystem),
+ "Invalid numbering system: " + actual.numberingSystem);
+assert.sameValue(actual.style, "decimal");
+assert.sameValue(actual.minimumIntegerDigits, 1);
+assert.sameValue(actual.minimumFractionDigits, 0);
+assert.sameValue(actual.maximumFractionDigits, 3);
+assert.sameValue(actual.useGrouping, "auto");
+
+var dataPropertyDesc = { writable: true, enumerable: true, configurable: true };
+verifyProperty(actual, "locale", dataPropertyDesc);
+verifyProperty(actual, "numberingSystem", dataPropertyDesc);
+verifyProperty(actual, "style", dataPropertyDesc);
+verifyProperty(actual, "currency", undefined);
+verifyProperty(actual, "currencyDisplay", undefined);
+verifyProperty(actual, "minimumIntegerDigits", dataPropertyDesc);
+verifyProperty(actual, "minimumFractionDigits", dataPropertyDesc);
+verifyProperty(actual, "maximumFractionDigits", dataPropertyDesc);
+verifyProperty(actual, "minimumSignificantDigits", undefined);
+verifyProperty(actual, "maximumSignificantDigits", undefined);
+verifyProperty(actual, "useGrouping", dataPropertyDesc);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/browser.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/browser.js
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/builtin.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/builtin.js
new file mode 100644
index 0000000000..c513cc7fa5
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/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: 11.3.3_L15
+description: >
+ Tests that Intl.NumberFormat.prototype.resolvedOptions 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(Intl.NumberFormat.prototype.resolvedOptions), "[object Function]",
+ "The [[Class]] internal property of a built-in function must be " +
+ "\"Function\".");
+
+assert(Object.isExtensible(Intl.NumberFormat.prototype.resolvedOptions),
+ "Built-in objects must be extensible.");
+
+assert.sameValue(Object.getPrototypeOf(Intl.NumberFormat.prototype.resolvedOptions), Function.prototype);
+
+assert.sameValue(Intl.NumberFormat.prototype.resolvedOptions.hasOwnProperty("prototype"), false,
+ "Built-in functions that aren't constructors must not have a prototype property.");
+
+assert.sameValue(isConstructor(Intl.NumberFormat.prototype.resolvedOptions), false,
+ "Built-in functions don't implement [[Construct]] unless explicitly specified.");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/compactDisplay.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/compactDisplay.js
new file mode 100644
index 0000000000..9d42cee786
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/compactDisplay.js
@@ -0,0 +1,26 @@
+// Copyright 2019 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.numberformat.prototype.resolvedoptions
+description: Verifies the existence of the compactDisplay property for the object returned by resolvedOptions().
+features: [Intl.NumberFormat-unified]
+---*/
+
+for (const notation of [undefined, "standard", "scientific", "engineering"]) {
+ const options = new Intl.NumberFormat([], {
+ notation,
+ compactDisplay: "long",
+ }).resolvedOptions();
+ assert.sameValue("compactDisplay" in options, false, `There should be no compactDisplay property with notation=${notation}`);
+ assert.sameValue(options.compactDisplay, undefined, `The compactDisplay property should be undefined with notation=${notation}`);
+}
+
+const options = new Intl.NumberFormat([], {
+ notation: "compact",
+ compactDisplay: "long",
+}).resolvedOptions();
+assert.sameValue("compactDisplay" in options, true, "There should be a compactDisplay property with notation=compact");
+assert.sameValue(options.compactDisplay, "long", "The compactDisplay property should be defined with notation=compact");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/length.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/length.js
new file mode 100644
index 0000000000..44fb64a705
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/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: sec-intl.numberformat.prototype.resolvedoptions
+description: >
+ Intl.NumberFormat.prototype.resolvedOptions.length is 0.
+info: |
+ Intl.NumberFormat.prototype.resolvedOptions ()
+
+ 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(Intl.NumberFormat.prototype.resolvedOptions, "length", {
+ value: 0,
+ writable: false,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/name.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/name.js
new file mode 100644
index 0000000000..584e60f57d
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/name.js
@@ -0,0 +1,29 @@
+// Copyright (C) 2016 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.NumberFormat.prototype.resolvedOptions
+description: >
+ Intl.NumberFormat.prototype.resolvedOptions.name is "resolvedOptions".
+info: |
+ 11.4.4 Intl.NumberFormat.prototype.resolvedOptions ()
+
+ 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.
+
+ 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]
+---*/
+
+verifyProperty(Intl.NumberFormat.prototype.resolvedOptions, "name", {
+ value: "resolvedOptions",
+ writable: false,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/no-instanceof.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/no-instanceof.js
new file mode 100644
index 0000000000..e1be473f7d
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/no-instanceof.js
@@ -0,0 +1,26 @@
+// Copyright (C) 2021 Igalia S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.numberformat.prototype.resolvedoptions
+description: >
+ Tests that Intl.NumberFormat.prototype.resolvedOptions calls
+ OrdinaryHasInstance instead of the instanceof operator which includes a
+ Symbol.hasInstance lookup and call among other things.
+info: >
+ UnwrapNumberFormat ( nf )
+
+ 2. If nf does not have an [[InitializedNumberFormat]] internal slot and
+ ? OrdinaryHasInstance(%NumberFormat%, nf) is true, then
+ a. Return ? Get(nf, %Intl%.[[FallbackSymbol]]).
+---*/
+
+const nf = Object.create(Intl.NumberFormat.prototype);
+
+Object.defineProperty(Intl.NumberFormat, Symbol.hasInstance, {
+ get() { throw new Test262Error(); }
+});
+
+assert.throws(TypeError, () => nf.resolvedOptions());
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/order.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/order.js
new file mode 100644
index 0000000000..16f35fb743
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/order.js
@@ -0,0 +1,43 @@
+// Copyright 2018 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.numberformat.prototype.resolvedoptions
+description: Verifies the property order for the object returned by resolvedOptions().
+features: [Intl.NumberFormat-unified]
+---*/
+
+const options = new Intl.NumberFormat([], {
+ "style": "currency",
+ "currency": "EUR",
+ "currencyDisplay": "symbol",
+ "minimumSignificantDigits": 1,
+ "maximumSignificantDigits": 2,
+}).resolvedOptions();
+
+const expected = [
+ "locale",
+ "numberingSystem",
+ "style",
+ "currency",
+ "currencyDisplay",
+ "currencySign",
+ "minimumIntegerDigits",
+ "minimumSignificantDigits",
+ "maximumSignificantDigits",
+ "useGrouping",
+ "notation",
+ "signDisplay",
+];
+
+const actual = Object.getOwnPropertyNames(options);
+
+// Ensure all expected items are in actual and also allow other properties
+// implemented in new proposals.
+assert(actual.indexOf("locale") > -1, "\"locale\" is present");
+for (var i = 1; i < expected.length; i++) {
+ // Ensure the order as expected but allow additional new property in between
+ assert(actual.indexOf(expected[i-1]) < actual.indexOf(expected[i]), `"${expected[i-1]}" precedes "${expected[i]}"`);
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/prop-desc.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/prop-desc.js
new file mode 100644
index 0000000000..d871d8b225
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/prop-desc.js
@@ -0,0 +1,33 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.numberformat.prototype.resolvedoptions
+description: >
+ "resolvedOptions" property of Intl.NumberFormat.prototype.
+info: |
+ Intl.NumberFormat.prototype.resolvedOptions ()
+
+ 7 Requirements for Standard Built-in ECMAScript Objects
+
+ Unless specified otherwise in this document, the objects, functions, and constructors
+ described in this standard are subject to the generic requirements and restrictions
+ specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language
+ Specification, 9th edition, clause 17, or successor.
+
+ 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]
+---*/
+
+verifyProperty(Intl.NumberFormat.prototype, "resolvedOptions", {
+ writable: true,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/return-keys-order-default.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/return-keys-order-default.js
new file mode 100644
index 0000000000..15ad912032
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/return-keys-order-default.js
@@ -0,0 +1,49 @@
+// Copyright 2023 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-intl.numberformat.prototype.resolvedoptions
+description: order of property keys for the object returned by resolvedOptions()
+features: [Intl.NumberFormat-v3]
+includes: [compareArray.js]
+---*/
+
+const allKeys = [
+ 'locale',
+ 'numberingSystem',
+ 'style',
+ 'currency',
+ 'currencyDisplay',
+ 'currencySign',
+ 'unit',
+ 'unitDisplay',
+ 'minimumIntegerDigits',
+ 'minimumFractionDigits',
+ 'maximumFractionDigits',
+ 'minimumSignificantDigits',
+ 'maximumSignificantDigits',
+ 'useGrouping',
+ 'notation',
+ 'compactDisplay',
+ 'signDisplay',
+ 'roundingIncrement',
+ 'roundingMode',
+ 'roundingPriority',
+ 'trailingZeroDisplay'
+];
+
+const optionsBase = { notation: 'compact' };
+const optionsExtensions = [
+ { style: 'currency', currency: 'XTS' },
+ { style: 'unit', unit: 'percent' },
+];
+optionsExtensions.forEach((optionsExtension) => {
+ const options = Object.assign({}, optionsBase, optionsExtension);
+ const nf = new Intl.NumberFormat(undefined, options);
+ const resolved = nf.resolvedOptions();
+ const resolvedKeys = Reflect.ownKeys(resolved);
+ const expectedKeys = allKeys.filter(key => key in resolved);
+ assert.compareArray(resolvedKeys, expectedKeys,
+ 'resolvedOptions() property key order with options ' + JSON.stringify(options));
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/roundingMode.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/roundingMode.js
new file mode 100644
index 0000000000..10ab976f1c
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/roundingMode.js
@@ -0,0 +1,42 @@
+// Copyright 2021 the V8 project authors. All rights reserved.
+// Copyright 2021 Apple Inc. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-intl.numberformat.prototype.resolvedoptions
+description: roundingMode property for the object returned by resolvedOptions()
+features: [Intl.NumberFormat-v3]
+---*/
+
+var options;
+
+options = new Intl.NumberFormat([], {}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'halfExpand', 'default');
+
+options = new Intl.NumberFormat([], {roundingMode: 'ceil'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'ceil');
+
+options = new Intl.NumberFormat([], {roundingMode: 'floor'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'floor');
+
+options = new Intl.NumberFormat([], {roundingMode: 'expand'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'expand');
+
+options = new Intl.NumberFormat([], {roundingMode: 'trunc'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'trunc');
+
+options = new Intl.NumberFormat([], {roundingMode: 'halfCeil'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'halfCeil');
+
+options = new Intl.NumberFormat([], {roundingMode: 'halfFloor'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'halfFloor');
+
+options = new Intl.NumberFormat([], {roundingMode: 'halfExpand'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'halfExpand');
+
+options = new Intl.NumberFormat([], {roundingMode: 'halfTrunc'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'halfTrunc');
+
+options = new Intl.NumberFormat([], {roundingMode: 'halfEven'}).resolvedOptions();
+assert.sameValue(options.roundingMode, 'halfEven');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/shell.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/shell.js
new file mode 100644
index 0000000000..eda1477282
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/shell.js
@@ -0,0 +1,24 @@
+// 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]
+features: [Reflect.construct]
+---*/
+
+function isConstructor(f) {
+ if (typeof f !== "function") {
+ throw new Test262Error("isConstructor invoked with a non-function value");
+ }
+
+ try {
+ Reflect.construct(function(){}, [], f);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js
new file mode 100644
index 0000000000..d9773f00a3
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/resolvedOptions/this-value-not-numberformat.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.NumberFormat.prototype.resolvedOptions
+description: >
+ Tests that Intl.NumberFormat.prototype.resolvedOptions throws a
+ TypeError if called on a non-object value or an object that hasn't
+ been initialized as a NumberFormat.
+---*/
+
+const invalidTargets = [undefined, null, true, 0, 'NumberFormat', [], {}, Symbol()];
+const fn = Intl.NumberFormat.prototype.resolvedOptions;
+
+invalidTargets.forEach(target => {
+ assert.throws(
+ TypeError,
+ () => fn.call(target),
+ `Calling resolvedOptions on ${String(target)} should throw a TypeError.`
+ );
+});
+
+reportCompare(0, 0);