summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/dataview/read-aligned.js
diff options
context:
space:
mode:
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);
+ }
+}