summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/NumberFormat/prototype/format/value-tonumber.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/NumberFormat/prototype/format/value-tonumber.js')
-rw-r--r--js/src/tests/test262/intl402/NumberFormat/prototype/format/value-tonumber.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/NumberFormat/prototype/format/value-tonumber.js b/js/src/tests/test262/intl402/NumberFormat/prototype/format/value-tonumber.js
new file mode 100644
index 0000000000..3785b29103
--- /dev/null
+++ b/js/src/tests/test262/intl402/NumberFormat/prototype/format/value-tonumber.js
@@ -0,0 +1,46 @@
+// Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-number-format-functions
+description: >
+ Tests that Intl.NumberFormat.prototype.format converts its argument
+ (called value) to a number using ToNumber (7.1.3).
+info: |
+ 11.1.4Number Format Functions
+
+ 4. Let x be ? ToNumber(value).
+features: [Symbol]
+---*/
+
+const toNumberResults = [
+ [undefined, NaN],
+ [null, +0],
+ [true, 1],
+ [false, 0],
+ ['42', 42],
+ ['foo', NaN],
+ ['Infinity', Infinity],
+ ['-Infinity', -Infinity]
+];
+
+const nf = new Intl.NumberFormat();
+
+toNumberResults.forEach(pair => {
+ const [value, result] = pair;
+ assert.sameValue(nf.format(value), nf.format(result));
+});
+
+let count = 0;
+const dummy = {};
+dummy[Symbol.toPrimitive] = hint => (hint === 'number' ? ++count : NaN);
+assert.sameValue(nf.format(dummy), nf.format(count));
+assert.sameValue(count, 1);
+
+assert.throws(
+ TypeError,
+ () => nf.format(Symbol()),
+ "ToNumber(arg) throws a TypeError when arg is of type 'Symbol'"
+);
+
+reportCompare(0, 0);