summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/dataview/read-aligned.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/dataview/read-aligned.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/jit-test/tests/dataview/read-aligned.js')
-rw-r--r--js/src/jit-test/tests/dataview/read-aligned.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/dataview/read-aligned.js b/js/src/jit-test/tests/dataview/read-aligned.js
new file mode 100644
index 0000000000..005cc76dbe
--- /dev/null
+++ b/js/src/jit-test/tests/dataview/read-aligned.js
@@ -0,0 +1,52 @@
+// Test aligned read access.
+
+load(libdir + "dataview.js");
+
+// Create a new test function for each scalar type.
+function createRead(data) {
+ const name = typeName(data.type);
+ const offset = 0;
+
+ return Function("data", `
+ const {values, littleEndian, bigEndian} = data;
+
+ // Load from array so that Ion doesn't treat as constants.
+ const True = [true, 1];
+ const False = [false, 0];
+
+ const ab = new ArrayBuffer(${data.values.length * data.type.BYTES_PER_ELEMENT + offset});
+ const dv = new DataView(ab);
+
+ new ${data.type.name}(ab, 0, ${data.values.length}).set(values);
+
+ new Uint8Array(ab).copyWithin(${offset}, 0);
+
+ for (let i = 0; i < 100; ++i) {
+ let j = i % values.length;
+ let index = j * ${data.type.BYTES_PER_ELEMENT} + ${offset};
+
+ let v1 = dv.get${name}(index);
+ assertEq(v1, bigEndian[j]);
+
+ let v2 = dv.get${name}(index, true);
+ assertEq(v2, littleEndian[j]);
+
+ let v3 = dv.get${name}(index, false);
+ assertEq(v3, bigEndian[j]);
+
+ let v4 = dv.get${name}(index, True[i & 1]);
+ assertEq(v4, littleEndian[j]);
+
+ let v5 = dv.get${name}(index, False[i & 1]);
+ assertEq(v5, bigEndian[j]);
+ }
+ `);
+}
+
+for (let data of createTestData()) {
+ let f = createRead(data);
+
+ for (let i = 0; i < 2; ++i) {
+ f(data);
+ }
+}