summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Math/20.2.2.ToNumber.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Math/20.2.2.ToNumber.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Math/20.2.2.ToNumber.js')
-rw-r--r--js/src/tests/non262/Math/20.2.2.ToNumber.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/js/src/tests/non262/Math/20.2.2.ToNumber.js b/js/src/tests/non262/Math/20.2.2.ToNumber.js
new file mode 100644
index 0000000000..de1f4e612c
--- /dev/null
+++ b/js/src/tests/non262/Math/20.2.2.ToNumber.js
@@ -0,0 +1,112 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+/*
+ * ECMA-262 6th Edition / Draft November 8, 2013
+ *
+ * 20.2.2 Function Properties of the Math Object
+ */
+
+/*
+ * This custom object will allow us to check if valueOf() is called
+ */
+
+TestNumber.prototype = new Number();
+
+function TestNumber(value) {
+ this.value = value;
+ this.valueOfCalled = false;
+}
+
+TestNumber.prototype = {
+ valueOf: function() {
+ this.valueOfCalled = true;
+ return this.value;
+ }
+}
+
+// Verify that each TestNumber's flag is set after calling Math func
+function test(func /*, args */) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ func.apply(null, args);
+
+ for (var i = 0; i < args.length; ++i)
+ assertEq(args[i].valueOfCalled, true);
+}
+
+// Note that we are not testing these functions' return values
+// We only test whether valueOf() is called for each argument
+
+// 1. Test Math.atan2()
+var x = new TestNumber(1);
+test(Math.atan2, x);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+test(Math.atan2, y, x);
+
+// Remove comment block once patch for bug 896264 is approved
+/*
+// 2. Test Math.hypot()
+var x = new TestNumber(1);
+test(Math.hypot, x);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+test(Math.hypot, x, y);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+var z = new TestNumber(3);
+test(Math.hypot, x, y, z);
+*/
+
+// Remove comment block once patch for bug 808148 is approved
+/*
+// 3. Test Math.imul()
+var x = new TestNumber(1);
+test(Math.imul, x);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+test(Math.imul, x, y);
+*/
+
+// 4. Test Math.max()
+var x = new TestNumber(1);
+test(Math.max, x);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+test(Math.max, x, y);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+var z = new TestNumber(3);
+test(Math.max, x, y, z);
+
+// 5. Test Math.min()
+var x = new TestNumber(1);
+test(Math.min, x);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+test(Math.min, x, y);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+var z = new TestNumber(3);
+test(Math.min, x, y, z);
+
+// 6. Test Math.pow()
+var x = new TestNumber(1);
+test(Math.pow, x);
+
+var x = new TestNumber(1);
+var y = new TestNumber(2);
+test(Math.pow, x, y);
+
+reportCompare(0, 0, "ok");
+