summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/ArrayBuffer
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/ArrayBuffer
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/ArrayBuffer')
-rw-r--r--js/src/tests/non262/ArrayBuffer/CloneArrayBuffer.js35
-rw-r--r--js/src/tests/non262/ArrayBuffer/browser.js0
-rw-r--r--js/src/tests/non262/ArrayBuffer/bug1689503.js9
-rw-r--r--js/src/tests/non262/ArrayBuffer/bug1777413.js7
-rw-r--r--js/src/tests/non262/ArrayBuffer/constructorNotCallable.js8
-rw-r--r--js/src/tests/non262/ArrayBuffer/getter-name.js10
-rw-r--r--js/src/tests/non262/ArrayBuffer/shell.js0
-rw-r--r--js/src/tests/non262/ArrayBuffer/slice-species.js180
8 files changed, 249 insertions, 0 deletions
diff --git a/js/src/tests/non262/ArrayBuffer/CloneArrayBuffer.js b/js/src/tests/non262/ArrayBuffer/CloneArrayBuffer.js
new file mode 100644
index 0000000000..480314ad8e
--- /dev/null
+++ b/js/src/tests/non262/ArrayBuffer/CloneArrayBuffer.js
@@ -0,0 +1,35 @@
+var BUGNUMBER = 1264941;
+var summary = 'CloneArrayBuffer should be called with byteLength of source typedArray';
+
+print(BUGNUMBER + ": " + summary);
+
+function test(ctor, byteLength) {
+ var abuf = new ctor(byteLength);
+ assertEq(abuf.byteLength, byteLength);
+
+ for (var byteOffset of [0, 16]) {
+ for (var elementLength = 0;
+ elementLength < (byteLength - byteOffset) / Float64Array.BYTES_PER_ELEMENT;
+ elementLength++) {
+ var a1 = new Float64Array(abuf, byteOffset, elementLength);
+ assertEq(a1.buffer.byteLength, byteLength);
+ assertEq(a1.byteLength, elementLength * Float64Array.BYTES_PER_ELEMENT);
+ assertEq(a1.byteOffset, byteOffset);
+
+ var a2 = new Float64Array(a1);
+ assertEq(a2.buffer.byteLength, a1.byteLength);
+ assertEq(a2.byteLength, a1.byteLength);
+ assertEq(a2.byteOffset, 0);
+ }
+ }
+}
+
+test(ArrayBuffer, 16);
+test(ArrayBuffer, 128);
+
+class MyArrayBuffer extends ArrayBuffer {}
+test(MyArrayBuffer, 16);
+test(MyArrayBuffer, 128);
+
+if (typeof reportCompare === 'function')
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/ArrayBuffer/browser.js b/js/src/tests/non262/ArrayBuffer/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/non262/ArrayBuffer/browser.js
diff --git a/js/src/tests/non262/ArrayBuffer/bug1689503.js b/js/src/tests/non262/ArrayBuffer/bug1689503.js
new file mode 100644
index 0000000000..475ae533cc
--- /dev/null
+++ b/js/src/tests/non262/ArrayBuffer/bug1689503.js
@@ -0,0 +1,9 @@
+// |reftest| skip-if(!xulRuntime.shell) -- needs Debugger
+
+let g = newGlobal({ newCompartment: true });
+let dbg = new Debugger(g);
+dbg.memory.trackingAllocationSites = true;
+g.createExternalArrayBuffer(64);
+
+if (typeof reportCompare === 'function')
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/ArrayBuffer/bug1777413.js b/js/src/tests/non262/ArrayBuffer/bug1777413.js
new file mode 100644
index 0000000000..3c58aecbfc
--- /dev/null
+++ b/js/src/tests/non262/ArrayBuffer/bug1777413.js
@@ -0,0 +1,7 @@
+// |reftest| skip-if(!xulRuntime.shell) -- needs shell functions
+
+var b = createExternalArrayBuffer(0);
+assertEq(b.byteLength, 0);
+
+if (typeof reportCompare === 'function')
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/ArrayBuffer/constructorNotCallable.js b/js/src/tests/non262/ArrayBuffer/constructorNotCallable.js
new file mode 100644
index 0000000000..9df97fe867
--- /dev/null
+++ b/js/src/tests/non262/ArrayBuffer/constructorNotCallable.js
@@ -0,0 +1,8 @@
+assertThrowsInstanceOf(() => ArrayBuffer(), TypeError);
+assertThrowsInstanceOf(() => ArrayBuffer(1), TypeError);
+assertThrowsInstanceOf(() => ArrayBuffer.call(null), TypeError);
+assertThrowsInstanceOf(() => ArrayBuffer.apply(null, []), TypeError);
+assertThrowsInstanceOf(() => Reflect.apply(ArrayBuffer, null, []), TypeError);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0,0,"OK");
diff --git a/js/src/tests/non262/ArrayBuffer/getter-name.js b/js/src/tests/non262/ArrayBuffer/getter-name.js
new file mode 100644
index 0000000000..434782bfe8
--- /dev/null
+++ b/js/src/tests/non262/ArrayBuffer/getter-name.js
@@ -0,0 +1,10 @@
+var BUGNUMBER = 1180290;
+var summary = 'ArrayBuffer getters should have get prefix';
+
+print(BUGNUMBER + ": " + summary);
+
+assertEq(Object.getOwnPropertyDescriptor(ArrayBuffer, Symbol.species).get.name, "get [Symbol.species]");
+assertEq(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get.name, "get byteLength");
+
+if (typeof reportCompare === 'function')
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/ArrayBuffer/shell.js b/js/src/tests/non262/ArrayBuffer/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/non262/ArrayBuffer/shell.js
diff --git a/js/src/tests/non262/ArrayBuffer/slice-species.js b/js/src/tests/non262/ArrayBuffer/slice-species.js
new file mode 100644
index 0000000000..6f025d162c
--- /dev/null
+++ b/js/src/tests/non262/ArrayBuffer/slice-species.js
@@ -0,0 +1,180 @@
+const tests = [
+ [Int8Array, [9, 10, 11, 12, 13, 14, 15, 16]],
+ [Uint8Array, [9, 10, 11, 12, 13, 14, 15, 16]],
+ [Uint8ClampedArray, [9, 10, 11, 12, 13, 14, 15, 16]],
+ [Int16Array, [5, 6, 7, 8]],
+ [Uint16Array, [5, 6, 7, 8]],
+ [Int32Array, [3, 4]],
+ [Uint32Array, [3, 4]],
+ [Float32Array, [3, 4]],
+ [Float64Array, [2]],
+];
+
+let logs = [];
+for (let [ctor, answer] of tests) {
+ let arr = new ctor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+
+ let proxyProto = new Proxy({}, {
+ get(that, name) {
+ throw new Error("unexpected prop access");
+ }
+ });
+
+ class MyArrayBuffer extends ArrayBuffer {}
+
+ arr.buffer.constructor = new Proxy({}, {
+ get(that, name) {
+ if (name == Symbol.species) {
+ logs.push("get @@species");
+ let C = new Proxy(function(...args) {
+ logs.push("call ctor");
+ return new MyArrayBuffer(...args);
+ }, {
+ get(that, name) {
+ logs.push("get ctor." + String(name));
+ if (name == "prototype") {
+ return proxyProto;
+ }
+ throw new Error("unexpected prop access");
+ }
+ });
+ return C;
+ }
+ throw new Error("unexpected prop access");
+ }
+ });
+
+ logs.length = 0;
+ let buf = arr.buffer.slice(8, 16);
+ assertEq(buf.constructor, MyArrayBuffer);
+ assertDeepEq(logs, ["get @@species", "get ctor.prototype", "call ctor"]);
+ assertDeepEq([...new ctor(buf)], answer);
+
+
+ // modified @@species
+ let a = arr.buffer;
+ a.constructor = {
+ [Symbol.species]: MyArrayBuffer
+ };
+ let b = a.slice(8, 16);
+ assertEq(b.constructor, MyArrayBuffer);
+ assertDeepEq([...new ctor(b)], answer);
+
+ class MyArrayBufferWithSpecies extends ArrayBuffer {
+ get [Symbol.species]() {
+ return MyArrayBufferWithSpecies;
+ }
+ }
+ a = arr.buffer;
+ a.constructor = MyArrayBufferWithSpecies;
+ b = a.slice(8, 16);
+ assertEq(b.constructor, MyArrayBufferWithSpecies);
+ assertDeepEq([...new ctor(b)], answer);
+
+ // no @@species
+ a = arr.buffer;
+ a.constructor = {
+ [Symbol.species]: undefined
+ };
+ b = a.slice(8, 16);
+ assertEq(b.constructor, ArrayBuffer);
+ assertDeepEq([...new ctor(b)], answer);
+
+ a = arr.buffer;
+ a.constructor = {
+ [Symbol.species]: null
+ };
+ b = a.slice(8, 16);
+ assertEq(b.constructor, ArrayBuffer);
+ assertDeepEq([...new ctor(b)], answer);
+
+ // invalid @@species
+ for (let species of [0, 1.1, true, false, "a", /a/, Symbol.iterator, [], {}]) {
+ a = arr.buffer;
+ a.constructor = {
+ [Symbol.species]: species
+ };
+ assertThrowsInstanceOf(() => a.slice(8, 16), TypeError);
+ }
+
+ // undefined constructor
+ a = arr.buffer;
+ a.constructor = undefined;
+ b = a.slice(8, 16);
+ assertEq(b.constructor, ArrayBuffer);
+ assertDeepEq([...new ctor(b)], answer);
+
+ // invalid constructor
+ for (let ctor of [null, 0, 1.1, true, false, "a", Symbol.iterator]) {
+ a = arr.buffer;
+ a.constructor = ctor;
+ assertThrowsInstanceOf(() => a.slice(8, 16), TypeError);
+ }
+
+ // @@species from different global
+ let g = newGlobal();
+ g.eval("var MyArrayBuffer = class MyArrayBuffer extends ArrayBuffer {};");
+ a = arr.buffer;
+ a.constructor = {
+ [Symbol.species]: g.MyArrayBuffer
+ };
+ b = a.slice(8, 16);
+ assertEq(b.constructor, g.MyArrayBuffer);
+ assertDeepEq([...new ctor(b)], answer);
+
+ a = arr.buffer;
+ a.constructor = {
+ [Symbol.species]: g.ArrayBuffer
+ };
+ b = a.slice(8, 16);
+ assertEq(b.constructor, g.ArrayBuffer);
+ assertDeepEq([...new ctor(b)], answer);
+
+ // constructor from different global
+ g.eval(`
+var MyArrayBufferWithSpecies = class MyArrayBufferWithSpecies extends ArrayBuffer {
+ get [Symbol.species]() {
+ return MyArrayBufferWithSpecies;
+ }
+};
+`);
+ a = arr.buffer;
+ a.constructor = g.MyArrayBufferWithSpecies;
+ b = a.slice(8, 16);
+ assertEq(b.constructor, g.MyArrayBufferWithSpecies);
+ assertDeepEq([...new ctor(b)], answer);
+
+ g.eval(`
+var arr = new ${ctor.name}([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+var a = arr.buffer;
+`);
+ b = ArrayBuffer.prototype.slice.call(g.a, 8, 16);
+ assertEq(b.constructor, g.ArrayBuffer);
+ assertDeepEq([...new ctor(b)], answer);
+
+ // running in different global
+ b = g.a.slice(8, 16);
+ assertEq(b.constructor, g.ArrayBuffer);
+ assertDeepEq([...new ctor(b)], answer);
+
+ // subclasses
+ // not-modified @@species
+ a = new MyArrayBuffer(16);
+ b = a.slice(8, 16);
+ assertEq(b.constructor, MyArrayBuffer);
+
+ // modified @@species
+ class MyArrayBuffer2 extends ArrayBuffer {
+ }
+ class MyArrayBuffer3 extends ArrayBuffer {
+ static get [Symbol.species]() {
+ return MyArrayBuffer2;
+ }
+ }
+ a = new MyArrayBuffer3(16);
+ b = a.slice(8, 16);
+ assertEq(b.constructor, MyArrayBuffer2);
+}
+
+if (typeof reportCompare === 'function')
+ reportCompare(0,0,"OK");