summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_5/Number
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_5/Number
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_5/Number')
-rw-r--r--js/src/tests/ecma_5/Number/15.7.4.2.js31
-rw-r--r--js/src/tests/ecma_5/Number/browser.js0
-rw-r--r--js/src/tests/ecma_5/Number/conversion-invalid-precision.js46
-rw-r--r--js/src/tests/ecma_5/Number/defaultvalue.js170
-rw-r--r--js/src/tests/ecma_5/Number/shell.js0
-rw-r--r--js/src/tests/ecma_5/Number/toString-radix-handling.js37
-rw-r--r--js/src/tests/ecma_5/Number/tonumber-string-hex.js38
7 files changed, 322 insertions, 0 deletions
diff --git a/js/src/tests/ecma_5/Number/15.7.4.2.js b/js/src/tests/ecma_5/Number/15.7.4.2.js
new file mode 100644
index 000000000..36443394c
--- /dev/null
+++ b/js/src/tests/ecma_5/Number/15.7.4.2.js
@@ -0,0 +1,31 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+assertEq(raisesException(TypeError)('Number.prototype.toString.call(true)'), true);
+assertEq(raisesException(TypeError)('Number.prototype.toString.call("")'), true);
+assertEq(raisesException(TypeError)('Number.prototype.toString.call({})'), true);
+assertEq(raisesException(TypeError)('Number.prototype.toString.call(null)'), true);
+assertEq(raisesException(TypeError)('Number.prototype.toString.call([])'), true);
+assertEq(raisesException(TypeError)('Number.prototype.toString.call(undefined)'), true);
+assertEq(raisesException(TypeError)('Number.prototype.toString.call(new Boolean(true))'), true);
+
+assertEq(completesNormally('Number.prototype.toString.call(42)'), true);
+assertEq(completesNormally('Number.prototype.toString.call(new Number(42))'), true);
+
+function testAround(middle)
+{
+ var range = 260;
+ var low = middle - range/2;
+ for (var i = 0; i < range; ++i)
+ assertEq(low + i, parseInt(String(low + i)));
+}
+
+testAround(-Math.pow(2,32));
+testAround(-Math.pow(2,16));
+testAround(0);
+testAround(+Math.pow(2,16));
+testAround(+Math.pow(2,32));
+
+reportCompare(true, true);
diff --git a/js/src/tests/ecma_5/Number/browser.js b/js/src/tests/ecma_5/Number/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/ecma_5/Number/browser.js
diff --git a/js/src/tests/ecma_5/Number/conversion-invalid-precision.js b/js/src/tests/ecma_5/Number/conversion-invalid-precision.js
new file mode 100644
index 000000000..76c3a94d0
--- /dev/null
+++ b/js/src/tests/ecma_5/Number/conversion-invalid-precision.js
@@ -0,0 +1,46 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommonn.org/licenses/publicdomain/
+ */
+
+var BUGNUMBER = 795745;
+var summary =
+ "Number.prototype.to* should throw a RangeError when passed a bad precision";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+function test(method, prec)
+{
+ try
+ {
+ Number.prototype[method].call(0, prec);
+ throw "should have thrown";
+ }
+ catch (e)
+ {
+ assertEq(e instanceof RangeError, true,
+ "expected RangeError for " + method + " with precision " + prec +
+ ", got " + e);
+ }
+}
+
+test("toExponential", -32);
+test("toFixed", -32);
+test("toPrecision", -32);
+
+test("toExponential", 9999999);
+test("toFixed", 9999999);
+test("toPrecision", 9999999);
+
+test("toPrecision", 0);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("Tests complete");
diff --git a/js/src/tests/ecma_5/Number/defaultvalue.js b/js/src/tests/ecma_5/Number/defaultvalue.js
new file mode 100644
index 000000000..15bf02162
--- /dev/null
+++ b/js/src/tests/ecma_5/Number/defaultvalue.js
@@ -0,0 +1,170 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommonn.org/licenses/publicdomain/
+ */
+
+var BUGNUMBER = 645464;
+var summary =
+ "[[DefaultValue]] behavior wrong for Number with overridden valueOf/toString";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+
+// equality
+
+var n = new Number();
+assertEq(n == 0, true);
+
+var n2 = new Number();
+n2.valueOf = function() { return 17; };
+assertEq(n2 == 17, true);
+
+var n3 = new Number();
+n3.toString = function() { return 42; };
+assertEq(n3 == 0, true);
+
+function testEquality()
+{
+ var n = new Number();
+ assertEq(n == 0, true);
+
+ var n2 = new Number();
+ n2.valueOf = function() { return 17; };
+ assertEq(n2 == 17, true);
+
+ var n3 = new Number();
+ n3.toString = function() { return 42; };
+ assertEq(n3 == 0, true);
+}
+testEquality();
+
+
+// addition of Number to number
+
+var n = new Number();
+assertEq(n + 5, 5);
+
+var n2 = new Number();
+n2.toString = function() { return 9; };
+assertEq(n2 + 3, 3);
+
+var n3 = new Number();
+n3.valueOf = function() { return 17; };
+assertEq(n3 + 5, 22);
+
+function testNumberAddition()
+{
+ var n = new Number();
+ assertEq(n + 5, 5);
+
+ var n2 = new Number();
+ n2.toString = function() { return 9; };
+ assertEq(n2 + 3, 3);
+
+ var n3 = new Number();
+ n3.valueOf = function() { return 17; };
+ assertEq(n3 + 5, 22);
+}
+testNumberAddition();
+
+
+// addition of Number to Number
+
+var n = new Number();
+assertEq(n + n, 0);
+
+var n2 = new Number();
+n2.toString = function() { return 5; };
+assertEq(n2 + n2, 0);
+
+var n3 = new Number();
+n3.valueOf = function() { return 8.5; };
+assertEq(n3 + n3, 17);
+
+function testNonNumberAddition()
+{
+ var n = new Number();
+ assertEq(n + n, 0);
+
+ var n2 = new Number();
+ n2.toString = function() { return 5; };
+ assertEq(n2 + n2, 0);
+
+ var n3 = new Number();
+ n3.valueOf = function() { return 8.5; };
+ assertEq(n3 + n3, 17);
+}
+testNonNumberAddition();
+
+
+// Number as bracketed property name
+
+var obj = { 0: 17, 8: 42, 9: 8675309 };
+
+var n = new Number();
+assertEq(obj[n], 17);
+
+var n2 = new Number();
+n2.valueOf = function() { return 8; }
+assertEq(obj[n2], 17);
+
+var n3 = new Number();
+n3.toString = function() { return 9; };
+assertEq(obj[n3], 8675309);
+
+function testPropertyNameToNumber()
+{
+ var obj = { 0: 17, 8: 42, 9: 8675309 };
+
+ var n = new Number();
+ assertEq(obj[n], 17);
+
+ var n2 = new Number();
+ n2.valueOf = function() { return 8; }
+ assertEq(obj[n2], 17);
+
+ var n3 = new Number();
+ n3.toString = function() { return 9; };
+ assertEq(obj[n3], 8675309);
+}
+testPropertyNameToNumber();
+
+
+// Number as property name with |in| operator
+
+var n = new Number();
+assertEq(n in { 0: 5 }, true);
+
+var n2 = new Number();
+n2.toString = function() { return "baz"; };
+assertEq(n2 in { baz: 42 }, true);
+
+var n3 = new Number();
+n3.valueOf = function() { return "quux"; };
+assertEq(n3 in { 0: 17 }, true);
+
+function testInOperatorName()
+{
+ var n = new Number();
+ assertEq(n in { 0: 5 }, true);
+
+ var n2 = new Number();
+ n2.toString = function() { return "baz"; };
+ assertEq(n2 in { baz: 42 }, true);
+
+ var n3 = new Number();
+ n3.valueOf = function() { return "quux"; };
+ assertEq(n3 in { 0: 17 }, true);
+}
+testInOperatorName();
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("All tests passed!");
diff --git a/js/src/tests/ecma_5/Number/shell.js b/js/src/tests/ecma_5/Number/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/ecma_5/Number/shell.js
diff --git a/js/src/tests/ecma_5/Number/toString-radix-handling.js b/js/src/tests/ecma_5/Number/toString-radix-handling.js
new file mode 100644
index 000000000..dd91675a2
--- /dev/null
+++ b/js/src/tests/ecma_5/Number/toString-radix-handling.js
@@ -0,0 +1,37 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommonn.org/licenses/publicdomain/
+ */
+
+var BUGNUMBER = 647385;
+var summary =
+ "Number.prototype.toString should use ToInteger on the radix and should " +
+ "throw a RangeError if the radix is bad";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+function test(r)
+{
+ try
+ {
+ 5..toString(r);
+ throw "should have thrown";
+ }
+ catch (e)
+ {
+ assertEq(e instanceof RangeError, true, "expected a RangeError, got " + e);
+ }
+}
+test(Math.pow(2, 32) + 10);
+test(55);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("All tests passed!");
diff --git a/js/src/tests/ecma_5/Number/tonumber-string-hex.js b/js/src/tests/ecma_5/Number/tonumber-string-hex.js
new file mode 100644
index 000000000..ed1e9b9dd
--- /dev/null
+++ b/js/src/tests/ecma_5/Number/tonumber-string-hex.js
@@ -0,0 +1,38 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommonn.org/licenses/publicdomain/
+ */
+
+var BUGNUMBER = 872853;
+var summary = 'Various tests of ToNumber(string), particularly +"0x" being NaN';
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+assertEq(+"0x", NaN);
+assertEq(+"\t0x", NaN);
+assertEq(+"0x\n", NaN);
+assertEq(+"\n0x\t", NaN);
+assertEq(+"0x0", 0);
+assertEq(+"0xa", 10);
+assertEq(+"0xff", 255);
+assertEq(+"-0x", NaN);
+assertEq(+"-0xa", NaN);
+assertEq(+"-0xff", NaN);
+assertEq(+"0xInfinity", NaN);
+assertEq(+"+Infinity", Infinity);
+assertEq(+"-Infinity", -Infinity);
+assertEq(+"\t+Infinity", Infinity);
+assertEq(+"-Infinity\n", -Infinity);
+assertEq(+"+ Infinity", NaN);
+assertEq(+"- Infinity", NaN);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("Tests complete");