Skip to content

Commit 07caa4a

Browse files
jugglinmikerwaldron
authored andcommitted
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. tc39/proposal-resizablearraybuffer#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
1 parent 49347e0 commit 07caa4a

File tree

7 files changed

+59
-6
lines changed

7 files changed

+59
-6
lines changed

test/built-ins/TypedArray/prototype/byteLength/resizable-array-buffer-auto.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ testWithTypedArrayConstructors(function(TA) {
4242
expected = 0;
4343
} catch (_) {}
4444

45+
assert.sameValue(array.byteLength, expected, "following shrink (on boundary)");
46+
47+
try {
48+
ab.resize(0);
49+
expected = 0;
50+
} catch (_) {}
51+
4552
assert.sameValue(array.byteLength, expected, "following shrink (out of bounds)");
4653
});

test/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ testWithTypedArrayConstructors(function(TA) {
3434

3535
assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)");
3636

37-
var expected;
37+
var expected = BPE;
3838
try {
3939
ab.resize(BPE);
4040
expected = 0;
41-
} catch (_) {
42-
expected = BPE;
43-
}
41+
} catch (_) {}
42+
43+
assert.sameValue(array.byteOffset, expected, "following shrink (on boundary)");
44+
45+
try {
46+
ab.resize(0);
47+
expected = 0;
48+
} catch (_) {}
4449

4550
assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)");
4651
});

test/built-ins/TypedArray/prototype/length/resizable-array-buffer-auto.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ testWithTypedArrayConstructors(function(TA) {
4242
expected = 0;
4343
} catch (_) {}
4444

45+
assert.sameValue(array.length, expected, "following shrink (on boundary)");
46+
47+
try {
48+
ab.resize(0);
49+
expected = 0;
50+
} catch (_) {}
51+
4552
assert.sameValue(array.length, expected, "following shrink (out of bounds)");
4653
});

test/built-ins/TypedArrayConstructors/ctors/typedarray-arg/out-of-bounds-when-species-retrieved-different-type.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ testWithTypedArrayConstructors(function(TA) {
5757

5858
assert(compareArray(new TargetCtor(source), expected), 'following shrink (within bounds)');
5959

60+
onGetSpecies = function() {
61+
try {
62+
ab.resize(BPE);
63+
expected = [];
64+
} catch (_) {}
65+
};
66+
67+
assert(compareArray(new TargetCtor(source), expected), 'following shrink (on boundary)');
68+
6069
// `assert.throws` cannot be used in this case because the expected error
6170
// is derived only after the constructor is invoked.
6271
var expectedError;
6372
var actualError;
6473
onGetSpecies = function() {
6574
try {
66-
ab.resize(BPE);
75+
ab.resize(0);
6776
expectedError = TypeError;
6877
} catch (_) {
6978
expectedError = Test262Error;

test/built-ins/TypedArrayConstructors/ctors/typedarray-arg/out-of-bounds-when-species-retrieved-same-type.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ testWithTypedArrayConstructors(function(TA) {
5757

5858
assert(compareArray(new TA(source), expected), 'following shrink (within bounds)');
5959

60+
onGetSpecies = function() {
61+
try {
62+
ab.resize(BPE);
63+
expected = [];
64+
} catch (_) {}
65+
};
66+
67+
assert(compareArray(new TA(source), expected), 'following shrink (on boundary)');
68+
6069
// `assert.throws` cannot be used in this case because the expected error
6170
// is derived only after the constructor is invoked.
6271
var expectedError;
6372
var actualError;
6473
onGetSpecies = function() {
6574
try {
66-
ab.resize(BPE);
75+
ab.resize(0);
6776
expectedError = TypeError;
6877
} catch (_) {
6978
expectedError = Test262Error;

test/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-auto.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,12 @@ testWithTypedArrayConstructors(function(TA) {
5050
expected = "false,false,false,false,false";
5151
} catch (_) {}
5252

53+
assert.sameValue(inspect(array), expected, "following shrink (on boundary)");
54+
55+
try {
56+
ab.resize(0);
57+
expected = "false,false,false,false,false";
58+
} catch (_) {}
59+
5360
assert.sameValue(inspect(array), expected, "following shrink (out of bounds)");
5461
});

test/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-auto.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ testWithTypedArrayConstructors(function(TA) {
5252
expected = "";
5353
} catch (_) {}
5454

55+
assert.sameValue(
56+
Reflect.ownKeys(array).join(","), expected, "following shrink (on boundary)"
57+
);
58+
59+
try {
60+
ab.resize(0);
61+
expected = "";
62+
} catch (_) {}
63+
5564
assert.sameValue(
5665
Reflect.ownKeys(array).join(","), expected, "following shrink (out of bounds)"
5766
);

0 commit comments

Comments
 (0)