summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/bug1101821.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/jit-test/tests/ion/bug1101821.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/ion/bug1101821.js')
-rw-r--r--js/src/jit-test/tests/ion/bug1101821.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/ion/bug1101821.js b/js/src/jit-test/tests/ion/bug1101821.js
new file mode 100644
index 0000000000..e65e47b8cd
--- /dev/null
+++ b/js/src/jit-test/tests/ion/bug1101821.js
@@ -0,0 +1,89 @@
+
+// Makes it easier for fuzzers to get max or min statements with multiple arguments.
+function test(a, b, c, d, e, f) {
+ var r = 0
+ r += Math.max(a);
+ r += Math.max(a,b);
+ r += Math.max(a,b,c);
+ r += Math.max(a,b,c,d);
+ r += Math.max(a,b,c,d,e);
+ r += Math.max(a,b,c,d,e,f);
+ r += Math.min(a);
+ r += Math.min(a,b);
+ r += Math.min(a,b,c);
+ r += Math.min(a,b,c,d);
+ r += Math.min(a,b,c,d,e);
+ r += Math.min(a,b,c,d,e,f);
+ return r;
+}
+for (var i=0; i<10; i++) {
+ assertEq(test(12,5,32,6,18,2), 186);
+ assertEq(test(1,5,3,6,18,-10), 48);
+ assertEq(test(-19,5,20,6,18,1), -48);
+}
+
+// Test max/min result up to 5 arguments.
+for (var i=1; i<5; i++) {
+ var args = [];
+ for (var j=0; j<i; j++)
+ args[args.length] = "arg" + j;
+ var max = new Function(args, "return Math.max("+args.join(",")+");");
+ var min = new Function(args, "return Math.min("+args.join(",")+");");
+
+ var input = [];
+ for (var j=0; j<i; j++) {
+ input[input.length] = j;
+ }
+
+ permutate(input, function (a) {
+ var min_value = min.apply(undefined, a);
+ var max_value = max.apply(undefined, a);
+ assertEq(min_value, minimum(a));
+ assertEq(max_value, maximum(a));
+ });
+}
+
+function minimum(arr) {
+ var min = arr[0]
+ for (var i=1; i<arr.length; i++) {
+ if (min > arr[i])
+ min = arr[i]
+ }
+ return min
+}
+function maximum(arr) {
+ var max = arr[0]
+ for (var i=1; i<arr.length; i++) {
+ if (max < arr[i])
+ max = arr[i]
+ }
+ return max
+}
+
+function permutate(array, callback) {
+ function p(array, index, callback) {
+ function swap(a, i1, i2) {
+ var t = a[i1];
+ a[i1] = a[i2];
+ a[i2] = t;
+ }
+
+ if (index == array.length - 1) {
+ callback(array);
+ return 1;
+ } else {
+ var count = p(array, index + 1, callback);
+ for (var i = index + 1; i < array.length; i++) {
+ swap(array, i, index);
+ count += p(array, index + 1, callback);
+ swap(array, i, index);
+ }
+ return count;
+ }
+ }
+
+ if (!array || array.length == 0) {
+ return 0;
+ }
+ return p(array, 0, callback);
+}