Support normative change to Resizable ArrayBuffer

A recent normative change to the Resizable ArrayBuffer modified the
criteria for a TypedArray becoming "out of bounds." Following the
change, TypedArrays which track the length of their underlying
ArrayBuffer instance are no longer considered "out of bounds" when the
ArrayBuffer is resized such that its size matches the TypedArray's
offset exactly.

https://github.com/tc39/proposal-resizablearraybuffer/pull/70

The majority of this patch's changes extend coverage to include cases
for both "on boundary" and "out of bounds" without reflecting any new
semantics. Two changes describe observable differences in the new
version of the algorithm:

- out-of-bounds-when-species-retrieved-different-type.js
- out-of-bounds-when-species-retrieved-same-type.js
This commit is contained in:
Mike Pennisi 2021-08-24 21:01:27 -04:00 committed by Rick Waldron
parent 49347e0cf9
commit 07caa4a2df
7 changed files with 59 additions and 6 deletions

View File

@ -42,5 +42,12 @@ testWithTypedArrayConstructors(function(TA) {
expected = 0;
} catch (_) {}
assert.sameValue(array.byteLength, expected, "following shrink (on boundary)");
try {
ab.resize(0);
expected = 0;
} catch (_) {}
assert.sameValue(array.byteLength, expected, "following shrink (out of bounds)");
});

View File

@ -34,13 +34,18 @@ testWithTypedArrayConstructors(function(TA) {
assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)");
var expected;
var expected = BPE;
try {
ab.resize(BPE);
expected = 0;
} catch (_) {
expected = BPE;
}
} catch (_) {}
assert.sameValue(array.byteOffset, expected, "following shrink (on boundary)");
try {
ab.resize(0);
expected = 0;
} catch (_) {}
assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)");
});

View File

@ -42,5 +42,12 @@ testWithTypedArrayConstructors(function(TA) {
expected = 0;
} catch (_) {}
assert.sameValue(array.length, expected, "following shrink (on boundary)");
try {
ab.resize(0);
expected = 0;
} catch (_) {}
assert.sameValue(array.length, expected, "following shrink (out of bounds)");
});

View File

@ -57,13 +57,22 @@ testWithTypedArrayConstructors(function(TA) {
assert(compareArray(new TargetCtor(source), expected), 'following shrink (within bounds)');
onGetSpecies = function() {
try {
ab.resize(BPE);
expected = [];
} catch (_) {}
};
assert(compareArray(new TargetCtor(source), expected), 'following shrink (on boundary)');
// `assert.throws` cannot be used in this case because the expected error
// is derived only after the constructor is invoked.
var expectedError;
var actualError;
onGetSpecies = function() {
try {
ab.resize(BPE);
ab.resize(0);
expectedError = TypeError;
} catch (_) {
expectedError = Test262Error;

View File

@ -57,13 +57,22 @@ testWithTypedArrayConstructors(function(TA) {
assert(compareArray(new TA(source), expected), 'following shrink (within bounds)');
onGetSpecies = function() {
try {
ab.resize(BPE);
expected = [];
} catch (_) {}
};
assert(compareArray(new TA(source), expected), 'following shrink (on boundary)');
// `assert.throws` cannot be used in this case because the expected error
// is derived only after the constructor is invoked.
var expectedError;
var actualError;
onGetSpecies = function() {
try {
ab.resize(BPE);
ab.resize(0);
expectedError = TypeError;
} catch (_) {
expectedError = Test262Error;

View File

@ -50,5 +50,12 @@ testWithTypedArrayConstructors(function(TA) {
expected = "false,false,false,false,false";
} catch (_) {}
assert.sameValue(inspect(array), expected, "following shrink (on boundary)");
try {
ab.resize(0);
expected = "false,false,false,false,false";
} catch (_) {}
assert.sameValue(inspect(array), expected, "following shrink (out of bounds)");
});

View File

@ -52,6 +52,15 @@ testWithTypedArrayConstructors(function(TA) {
expected = "";
} catch (_) {}
assert.sameValue(
Reflect.ownKeys(array).join(","), expected, "following shrink (on boundary)"
);
try {
ab.resize(0);
expected = "";
} catch (_) {}
assert.sameValue(
Reflect.ownKeys(array).join(","), expected, "following shrink (out of bounds)"
);