diff options
Diffstat (limited to 'js/src/tests/non262/TypedArray/fill-detached.js')
-rw-r--r-- | js/src/tests/non262/TypedArray/fill-detached.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/fill-detached.js b/js/src/tests/non262/TypedArray/fill-detached.js new file mode 100644 index 0000000000..770067a81f --- /dev/null +++ b/js/src/tests/non262/TypedArray/fill-detached.js @@ -0,0 +1,36 @@ +// Ensure %TypedArray%.prototype.fill checks for detached buffers. + +function DetachArrayBufferValue(buffer, value) { + return { + valueOf() { + detachArrayBuffer(buffer); + return value; + } + }; +} + +function DetachTypedArrayValue(ta, value) { + return { + valueOf() { + detachArrayBuffer(ta.buffer); + return value; + } + }; +} + +// Test when ArrayBuffer is already reified. +for (let length of [0, 1, 10, 4096]) { + let ta = new Int32Array(length); + let value = DetachArrayBufferValue(ta.buffer, 123); + assertThrowsInstanceOf(() => ta.fill(value), TypeError); +} + +// Test when ArrayBuffer is reified during the fill() call. +for (let length of [0, 1, 10, 4096]) { + let ta = new Int32Array(length); + let value = DetachTypedArrayValue(ta, 123); + assertThrowsInstanceOf(() => ta.fill(value), TypeError); +} + +if (typeof reportCompare === "function") + reportCompare(0, 0); |