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

[rab/gsab] Return false in [[PreventExtensions]] for variable-length TAs #4325

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,49 @@
// Copyright (C) 2024 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-object.preventExtensions
description: Can't preventExtensions variable length TypedArrays
features: [SharedArrayBuffer, ArrayBuffer, resizable-arraybuffer]
includes: [resizableArrayBufferUtils.js]
---*/

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

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

for (let ctor of ctors) {
const gsab = new SharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, { maxByteLength: 8 * ctor.BYTES_PER_ELEMENT });
const fixedLength = new ctor(gsab, 0, 4);
const fixedLengthWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT, 2);
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.
Object.preventExtensions(fixedLength);
Object.preventExtensions(fixedLengthWithOffset);
assert.throws(TypeError, function() {
Object.preventExtensions(lengthTracking);
});
assert.throws(TypeError, function() {
Object.preventExtensions(lengthTrackingWithOffset);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (C) 2024 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-object.seal
description: Can't seal variable length TypedArrays
features: [SharedArrayBuffer, ArrayBuffer, resizable-arraybuffer]
includes: [resizableArrayBufferUtils.js]
---*/

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

// "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 gsab = new SharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, { maxByteLength: 8 * ctor.BYTES_PER_ELEMENT });
const fixedLength = new ctor(gsab, 0, 4);
const fixedLengthWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT, 2);
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.
Object.seal(fixedLength);
Object.seal(fixedLengthWithOffset);
assert.throws(TypeError, function() {
Object.seal(lengthTracking);
});
assert.throws(TypeError, function() {
Object.seal(lengthTrackingWithOffset);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2024 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-Reflect.preventExtensions
description: Can't preventExtensions variable length TypedArrays
features: [SharedArrayBuffer, ArrayBuffer, resizable-arraybuffer]
includes: [resizableArrayBufferUtils.js]
---*/

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

// "Fixed length" TAs backed by RABs can shrink then re-grow.
assert.sameValue(Reflect.preventExtensions(fixedLength), false);
assert.sameValue(Reflect.preventExtensions(fixedLengthWithOffset), false);
assert.sameValue(Reflect.preventExtensions(lengthTracking), false);
assert.sameValue(Reflect.preventExtensions(lengthTrackingWithOffset), false);
}

for (let ctor of ctors) {
const gsab = new SharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, { maxByteLength: 8 * ctor.BYTES_PER_ELEMENT });
const fixedLength = new ctor(gsab, 0, 4);
const fixedLengthWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT, 2);
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.sameValue(Reflect.preventExtensions(fixedLength), true);
assert.sameValue(Reflect.preventExtensions(fixedLengthWithOffset), true);
assert.sameValue(Reflect.preventExtensions(lengthTracking), false);
assert.sameValue(Reflect.preventExtensions(lengthTrackingWithOffset), false);
}
Loading