mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Resizable ArrayBuffer: TypedArray accessors (#3028)
* Add "feature" for "Resizable ArrayBuffer" proposal * Resizable ArrayBuffer: TypedArray accessors
This commit is contained in:
parent
13d7b79e90
commit
f734c2d547
46
test/built-ins/TypedArray/prototype/byteLength/resizable-array-buffer-auto.js
vendored
Normal file
46
test/built-ins/TypedArray/prototype/byteLength/resizable-array-buffer-auto.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 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-%typedarray%.prototype.byteoffset
|
||||||
|
description: |
|
||||||
|
reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
|
||||||
|
the dynamically-sized TypedArray instance
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray, 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");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var BPE = TA.BYTES_PER_ELEMENT;
|
||||||
|
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||||
|
var array = new TA(ab, BPE);
|
||||||
|
var expected = BPE * 3;
|
||||||
|
|
||||||
|
assert.sameValue(array.byteLength, expected);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 5);
|
||||||
|
expected = BPE * 4;
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteLength, expected, "following grow");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 3);
|
||||||
|
expected = BPE * 2;
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteLength, expected, "following shrink (within bounds)");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE);
|
||||||
|
expected = 0;
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteLength, expected, "following shrink (out of bounds)");
|
||||||
|
});
|
46
test/built-ins/TypedArray/prototype/byteLength/resizable-array-buffer-fixed.js
vendored
Normal file
46
test/built-ins/TypedArray/prototype/byteLength/resizable-array-buffer-fixed.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 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-%typedarray%.prototype.bytelength
|
||||||
|
description: |
|
||||||
|
reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
|
||||||
|
the fixed-sized TypedArray instance
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray, 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");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var BPE = TA.BYTES_PER_ELEMENT;
|
||||||
|
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||||
|
var array = new TA(ab, BPE, 2);
|
||||||
|
|
||||||
|
assert.sameValue(array.byteLength, BPE * 2);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 5);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteLength, BPE * 2, "following grow");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 3);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteLength, BPE * 2, "following shrink (within bounds)");
|
||||||
|
|
||||||
|
var expected;
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 2);
|
||||||
|
expected = 0;
|
||||||
|
} catch (_) {
|
||||||
|
expected = BPE * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteLength, expected, "following shrink (out of bounds)");
|
||||||
|
});
|
46
test/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js
vendored
Normal file
46
test/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 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-%typedarray%.prototype.byteoffset
|
||||||
|
description: |
|
||||||
|
reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
|
||||||
|
the dynamically-sized TypedArray instance
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray, 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");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var BPE = TA.BYTES_PER_ELEMENT;
|
||||||
|
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||||
|
var array = new TA(ab, BPE);
|
||||||
|
|
||||||
|
assert.sameValue(array.byteOffset, BPE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 5);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteOffset, BPE, "following grow");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 3);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)");
|
||||||
|
|
||||||
|
var expected;
|
||||||
|
try {
|
||||||
|
ab.resize(BPE);
|
||||||
|
expected = 0;
|
||||||
|
} catch (_) {
|
||||||
|
expected = BPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)");
|
||||||
|
});
|
46
test/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js
vendored
Normal file
46
test/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 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-%typedarray%.prototype.byteoffset
|
||||||
|
description: |
|
||||||
|
reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
|
||||||
|
the fixed-sized TypedArray instance
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray, 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");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var BPE = TA.BYTES_PER_ELEMENT;
|
||||||
|
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||||
|
var array = new TA(ab, BPE, 2);
|
||||||
|
|
||||||
|
assert.sameValue(array.byteOffset, BPE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 5);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteOffset, BPE, "following grow");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 3);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)");
|
||||||
|
|
||||||
|
var expected;
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 2);
|
||||||
|
expected = 0;
|
||||||
|
} catch (_) {
|
||||||
|
expected = BPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)");
|
||||||
|
});
|
46
test/built-ins/TypedArray/prototype/length/resizable-array-buffer-auto.js
vendored
Normal file
46
test/built-ins/TypedArray/prototype/length/resizable-array-buffer-auto.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 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-%typedarray%.prototype.length
|
||||||
|
description: |
|
||||||
|
reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
|
||||||
|
the dynamically-sized TypedArray instance
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray, 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");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var BPE = TA.BYTES_PER_ELEMENT;
|
||||||
|
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||||
|
var array = new TA(ab, BPE);
|
||||||
|
var expected = 3;
|
||||||
|
|
||||||
|
assert.sameValue(array.length, expected, "initial value");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 5);
|
||||||
|
expected = 4;
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.length, expected, "following grow");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 3);
|
||||||
|
expected = 2;
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.length, expected, "following shrink (within bounds)");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE);
|
||||||
|
expected = 0;
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.length, expected, "following shrink (out of bounds)");
|
||||||
|
});
|
46
test/built-ins/TypedArray/prototype/length/resizable-array-buffer-fixed.js
vendored
Normal file
46
test/built-ins/TypedArray/prototype/length/resizable-array-buffer-fixed.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 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-%typedarray%.prototype.length
|
||||||
|
description: |
|
||||||
|
reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
|
||||||
|
the fixed-sized TypedArray instance
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray, 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");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var BPE = TA.BYTES_PER_ELEMENT;
|
||||||
|
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||||
|
var array = new TA(ab, BPE, 2);
|
||||||
|
|
||||||
|
assert.sameValue(array.length, 2, "initial value");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 5);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.length, 2, "following grow");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 3);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
assert.sameValue(array.length, 2, "following shrink (within bounds)");
|
||||||
|
|
||||||
|
var expected;
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 2);
|
||||||
|
expected = 0;
|
||||||
|
} catch (_) {
|
||||||
|
expected = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(array.length, expected, "following shrink (out of bounds)");
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user