Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect TypeError when sealing non-empty TypedArrays #4352

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@ for (let ctor of ctors) {
const lengthTracking = new ctor(rab);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);

assert.notSameValue(fixedLength.length, 0);
assert.notSameValue(fixedLengthWithOffset.length, 0);
assert.notSameValue(lengthTracking.length, 0);
assert.notSameValue(lengthTrackingWithOffset.length, 0);

// "Fixed length" TAs backed by RABs can shrink then re-grow.
assert.throws(TypeError, function() {
Object.seal(fixedLength);
});
assert.throws(TypeError, function() {
Object.seal(fixedLengthWithOffset);
});
assert.throws(TypeError, function() {
Object.seal(lengthTracking);
});
assert.throws(TypeError, function() {
Object.seal(lengthTrackingWithOffset);
});
}

for (let ctor of ctors) {
const rab = new ArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, { maxByteLength: 8 * ctor.BYTES_PER_ELEMENT });
const rabZeroLength = new ArrayBuffer(0, { maxByteLength: 8 * ctor.BYTES_PER_ELEMENT });
const fixedLength = new ctor(rab, 0, 0);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 0);
const lengthTracking = new ctor(rabZeroLength);
const lengthTrackingWithOffset = new ctor(rab, 4 * ctor.BYTES_PER_ELEMENT);

assert.sameValue(fixedLength.length, 0);
assert.sameValue(fixedLengthWithOffset.length, 0);
assert.sameValue(lengthTracking.length, 0);
assert.sameValue(lengthTrackingWithOffset.length, 0);

// "Fixed length" TAs backed by RABs can shrink then re-grow.
assert.throws(TypeError, function() {
Object.seal(fixedLength);
Expand All @@ -37,7 +70,43 @@ for (let ctor of ctors) {
const lengthTracking = new ctor(gsab);
const lengthTrackingWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT);

// Fixed length TAs backed by GSABs can't shrink, and so are allowed.
assert.notSameValue(fixedLength.length, 0);
assert.notSameValue(fixedLengthWithOffset.length, 0);
assert.notSameValue(lengthTracking.length, 0);
assert.notSameValue(lengthTrackingWithOffset.length, 0);

// Fixed length TAs backed by GSABs can't shrink, and so are allowed. TypedArray
// properties can't be redefined to non-configurable, so this still throws.
assert.throws(TypeError, function() {
Object.seal(fixedLength);
});
assert.throws(TypeError, function() {
Object.seal(fixedLengthWithOffset);
});
assert.throws(TypeError, function() {
Object.seal(lengthTracking);
});
assert.throws(TypeError, function() {
Object.seal(lengthTrackingWithOffset);
});
}

for (let ctor of ctors) {
const gsab = new SharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, { maxByteLength: 8 * ctor.BYTES_PER_ELEMENT });
const gsabZeroLength = new SharedArrayBuffer(0, { maxByteLength: 8 * ctor.BYTES_PER_ELEMENT });
const fixedLength = new ctor(gsab, 0, 0);
const fixedLengthWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT, 0);
const lengthTracking = new ctor(gsabZeroLength);
const lengthTrackingWithOffset = new ctor(gsab, 4 * ctor.BYTES_PER_ELEMENT);

assert.sameValue(fixedLength.length, 0);
assert.sameValue(fixedLengthWithOffset.length, 0);
assert.sameValue(lengthTracking.length, 0);
assert.sameValue(lengthTrackingWithOffset.length, 0);

// Fixed zero-length TAs backed by GSABs can't shrink, and so are allowed. If
// the TypedArray is zero length, there's no attempt to redefine TypedArray
// properties.
Object.seal(fixedLength);
Object.seal(fixedLengthWithOffset);
assert.throws(TypeError, function() {
Expand Down
Loading