summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/setelem.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/setelem.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 '')
-rw-r--r--js/src/jit-test/tests/ion/setelem.js109
1 files changed, 109 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/ion/setelem.js b/js/src/jit-test/tests/ion/setelem.js
new file mode 100644
index 0000000000..34b900d596
--- /dev/null
+++ b/js/src/jit-test/tests/ion/setelem.js
@@ -0,0 +1,109 @@
+function testInt32() {
+ function f(arr, i) {
+ arr[0] = 1;
+ arr[1] = arr[0] + 1;
+ arr[2] = arr[1] + arr[0];
+ var x = arr[2]; // 3
+ arr[x] = arr[x-1] + 1;
+ arr[x+1] = arr[x] + i;
+ return arr[4];
+ }
+ var a = [1, 2, 3, 4, 5, 6, 7, 8];
+ for (var i=0; i<70; i++) {
+ assertEq(f(a, i), i + 4);
+ }
+}
+testInt32();
+
+function testDouble() {
+ function f(arr, d) {
+ arr[0] = d;
+ for (var i=1; i<8; i++) {
+ arr[i] = arr[i-1] + d;
+ }
+ return arr[7];
+ }
+ var a = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
+ for (var i=0; i<50; i++) {
+ assertEq(f(a, Math.PI + i)|0, ((Math.PI + i) * 8)|0);
+ }
+}
+testDouble();
+
+function testOutOfBounds() {
+ function f(arr, i, v) {
+ arr[i] = v;
+ }
+ var a = [1, 2];
+ for (var i=0; i<90; i++) {
+ f(a, 1, i);
+ }
+ assertEq(a[1], 89);
+
+ f(a, 2, 40);
+ f(a, 100, 50);
+ f(a, -1, 3);
+
+ assertEq(a[2], 40);
+ assertEq(a[100], 50);
+ assertEq(a[-1], 3);
+}
+testOutOfBounds();
+
+function testClassGuard() {
+ function f(arr, v) {
+ arr[1] = v;
+ }
+ var a = [1, 2, 3, 4];
+ for (var i=0; i<90; i++) {
+ f(a, i);
+ }
+ assertEq(a[1], 89);
+
+ var b = {};
+ f(b, 100);
+ assertEq(b[1], 100);
+}
+testClassGuard();
+
+function testMultipleTypes() {
+ function f(arr, v) {
+ arr[1] = v;
+ }
+ var a = [1, 2, 3, 4];
+ var b = [1.1, -233.2, 3.3];
+
+ for (var i=0; i<90; i++) {
+ f(a, i);
+ }
+ assertEq(a[1], 89);
+ f(b, 20);
+ assertEq(b[1], 20);
+}
+testMultipleTypes();
+
+function testNull() {
+ function f(arr) {
+ arr[0] = null;
+ }
+
+ var arr = [undefined];
+ for (var i=0; i<100; i++) {
+ f(arr);
+ }
+ assertEq(arr[0], null);
+}
+testNull();
+
+// Bug 722245.
+function testConstantGcThing() {
+ function f(arr, x) {
+ arr[x] = "abc";
+ }
+ var arr = ["", ""];
+ for (var i=0; i<100; i++) {
+ f(arr, 1);
+ }
+ assertEq(arr[1], "abc");
+}
+testConstantGcThing();