-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rab/gsab] Return false in [[PreventExtensions]] for variable-length TAs
This is a spec normative change: tc39/ecma262#3453 Fixed: 374310073 Change-Id: I085260fea077bc27cf1e4f06d4389519e12c4e14 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6014979 Commit-Queue: Shu-yu Guo <[email protected]> Auto-Submit: Shu-yu Guo <[email protected]> Commit-Queue: Rezvan Mahdavi Hezaveh <[email protected]> Reviewed-by: Rezvan Mahdavi Hezaveh <[email protected]> Cr-Commit-Position: refs/heads/main@{#97166}
- Loading branch information
1 parent
8eee455
commit d1d82e0
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ging/built-ins/Object/preventExtensions/preventExtensions-variable-length-typed-arrays.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |
49 changes: 49 additions & 0 deletions
49
test/staging/built-ins/Object/seal/seal-variable-length-typed-arrays.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |
37 changes: 37 additions & 0 deletions
37
...ing/built-ins/Reflect/preventExtensions/preventExtensions-variable-length-typed-arrays.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |