diff --git a/test/built-ins/DataView/prototype/byteLength/resizable-array-buffer-auto.js b/test/built-ins/DataView/prototype/byteLength/resizable-array-buffer-auto.js new file mode 100644 index 0000000000..f42ccf45a6 --- /dev/null +++ b/test/built-ins/DataView/prototype/byteLength/resizable-array-buffer-auto.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-dataview.prototype.bytelength +description: | + throws a TypeError if the underlying ArrayBuffer is resized beyond the + boundary of the dynamically-sized DataView instance +features: [resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +var ab = new ArrayBuffer(4, {maxByteLength: 5}); +var dataView = new DataView(ab, 1); +var expected = 3; + +assert.sameValue(dataView.byteLength, expected); + +try { + ab.resize(5); + expected = 4; +} catch (_) {} + +assert.sameValue(dataView.byteLength, expected, "following grow"); + +try { + ab.resize(3); + expected = 2; +} catch (_) {} + +assert.sameValue(dataView.byteLength, expected, "following shrink (within bounds)"); + +try { + ab.resize(1); + expected = TypeError; +} catch (_) { + expected = Test262Error; +} + +assert.throws(expected, function() { + dataView.byteLength; + throw new Test262Error('the operation completed successfully'); +}); diff --git a/test/built-ins/DataView/prototype/byteLength/resizable-array-buffer-fixed.js b/test/built-ins/DataView/prototype/byteLength/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000..fdc4ab5b57 --- /dev/null +++ b/test/built-ins/DataView/prototype/byteLength/resizable-array-buffer-fixed.js @@ -0,0 +1,45 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-dataview.prototype.bytelength +description: | + throws a TypeError if the underlying ArrayBuffer is resized beyond the + boundary of the fixed-sized DataView instance +features: [resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +var ab = new ArrayBuffer(4, {maxByteLength: 5}); +var dataView = new DataView(ab, 1, 2); + +assert.sameValue(dataView.byteLength, 2); + +try { + ab.resize(5); +} catch (_) {} + +assert.sameValue(dataView.byteLength, 2, "following grow"); + +try { + ab.resize(3); +} catch (_) {} + +assert.sameValue(dataView.byteLength, 2, "following shrink (within bounds)"); + +var expectedError; +try { + ab.resize(2); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + dataView.byteLength; + throw new Test262Error('the operation completed successfully'); +}); diff --git a/test/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-auto.js b/test/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-auto.js new file mode 100644 index 0000000000..c9d80b6849 --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-auto.js @@ -0,0 +1,45 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-dataview.prototype.byteoffset +description: | + throws a TypeError if the underlying ArrayBuffer is resized beyond the + boundary of the dynamically-sized DataView instance +features: [resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +var ab = new ArrayBuffer(4, {maxByteLength: 5}); +var dataView = new DataView(ab, 1); + +assert.sameValue(dataView.byteOffset, 1); + +try { + ab.resize(5); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following grow"); + +try { + ab.resize(3); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following shrink (within bounds)"); + +var expectedError; +try { + ab.resize(1); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + dataView.byteOffset; + throw new Test262Error('the operation completed successfully'); +}); diff --git a/test/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-fixed.js b/test/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000..938074398d --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-fixed.js @@ -0,0 +1,45 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-dataview.prototype.byteoffset +description: | + throws a TypeError if the underlying ArrayBuffer is resized beyond the + boundary of the fixed-sized DataView instance +features: [resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +var ab = new ArrayBuffer(4, {maxByteLength: 5}); +var dataView = new DataView(ab, 1, 2); + +assert.sameValue(dataView.byteOffset, 1); + +try { + ab.resize(5); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following grow"); + +try { + ab.resize(BPE * 3); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following shrink (within bounds)"); + +var expectedError; +try { + ab.resize(2); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + dataView.byteOffset; + throw new Test262Error('the operation completed successfully'); +});