mirror of
https://github.com/tc39/test262.git
synced 2025-09-25 19:18:48 +02:00
[immutable-arraybuffer] Changes to existing ArrayBuffer.prototype properties (#4540)
This commit is contained in:
parent
a07e038f37
commit
3fd4ec27f1
32
test/built-ins/ArrayBuffer/prototype/resize/this-is-immutable-arraybuffer-object.js
vendored
Normal file
32
test/built-ins/ArrayBuffer/prototype/resize/this-is-immutable-arraybuffer-object.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2025 Richard Gibson. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-arraybuffer.prototype.resize
|
||||
description: >
|
||||
Throws a TypeError if `this` has an [[ArrayBufferIsImmutable]] internal slot.
|
||||
info: |
|
||||
ArrayBuffer.prototype.resize ( newLength )
|
||||
1. Let O be the this value.
|
||||
2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
|
||||
...
|
||||
6. Assert: IsImmutableBuffer(O) is false.
|
||||
features: [resizable-arraybuffer, immutable-arraybuffer]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var calls = [];
|
||||
|
||||
var ab = (new ArrayBuffer(4)).transferToImmutable();
|
||||
assert.throws(TypeError, function() {
|
||||
ab.resize(0);
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
ab.resize({
|
||||
valueOf() {
|
||||
calls.push('newLength.valueOf');
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
assert.compareArray(calls, [], 'Must verify internal slots before reading newLength.');
|
55
test/built-ins/ArrayBuffer/prototype/slice/species-returns-immutable-arraybuffer.js
vendored
Normal file
55
test/built-ins/ArrayBuffer/prototype/slice/species-returns-immutable-arraybuffer.js
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2025 Richard Gibson. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-arraybuffer.prototype.slice
|
||||
description: >
|
||||
Throws a TypeError if species constructor returns an immutable ArrayBuffer.
|
||||
info: |
|
||||
ArrayBuffer.prototype.slice ( start, end )
|
||||
1. Let O be the this value.
|
||||
...
|
||||
14. Let bounds be ? ResolveBounds(len, start, end).
|
||||
...
|
||||
18. Let ctor be ? SpeciesConstructor(O, %ArrayBuffer%).
|
||||
19. Let new be ? Construct(ctor, « 𝔽(newLen) »).
|
||||
...
|
||||
23. If IsImmutableBuffer(new) is true, throw a TypeError exception.
|
||||
features: [Symbol.species, immutable-arraybuffer]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var calls = [];
|
||||
|
||||
var speciesConstructor = {};
|
||||
speciesConstructor[Symbol.species] = function(length) {
|
||||
calls.push("Symbol.species(" + length + ")");
|
||||
return arrayBuffer.sliceToImmutable();
|
||||
};
|
||||
|
||||
var arrayBuffer = new ArrayBuffer(8);
|
||||
arrayBuffer.constructor = speciesConstructor;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
arrayBuffer.slice();
|
||||
});
|
||||
assert.compareArray(calls, ["Symbol.species(8)"]);
|
||||
|
||||
calls = [];
|
||||
assert.throws(TypeError, function() {
|
||||
var start = {
|
||||
valueOf() {
|
||||
calls.push("start.valueOf");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
var end = {
|
||||
valueOf() {
|
||||
calls.push("end.valueOf");
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
arrayBuffer.slice(start, end);
|
||||
});
|
||||
assert.compareArray(calls, ["start.valueOf", "end.valueOf", "Symbol.species(1)"],
|
||||
"Must read arguments before SpeciesConstructor.");
|
40
test/built-ins/ArrayBuffer/prototype/transfer/this-is-immutable-arraybuffer.js
vendored
Normal file
40
test/built-ins/ArrayBuffer/prototype/transfer/this-is-immutable-arraybuffer.js
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2025 Richard Gibson. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-arraybuffer.prototype.transfer
|
||||
description: Throws a TypeError if `this` is immutable.
|
||||
info: |
|
||||
ArrayBuffer.prototype.transfer ( [ newLength ] )
|
||||
1. Let O be the this value.
|
||||
2. Return ? ArrayBufferCopyAndDetach(O, newLength, ~preserve-resizability~).
|
||||
|
||||
ArrayBufferCopyAndDetach ( arrayBuffer, newLength, preserveResizability )
|
||||
1. Perform ? RequireInternalSlot(arrayBuffer, [[ArrayBufferData]]).
|
||||
2. If IsSharedArrayBuffer(arrayBuffer) is true, throw a TypeError exception.
|
||||
3. If newLength is undefined, then
|
||||
a. Let newByteLength be arrayBuffer.[[ArrayBufferByteLength]].
|
||||
4. Else,
|
||||
a. Let newByteLength be ? ToIndex(newLength).
|
||||
5. If IsDetachedBuffer(arrayBuffer) is true, throw a TypeError exception.
|
||||
6. If IsImmutableBuffer(arrayBuffer) is true, throw a TypeError exception.
|
||||
features: [arraybuffer-transfer, immutable-arraybuffer]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var calls = [];
|
||||
|
||||
var ab = (new ArrayBuffer(4)).transferToImmutable();
|
||||
assert.throws(TypeError, function() {
|
||||
ab.transfer();
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
ab.transfer({
|
||||
valueOf() {
|
||||
calls.push("newLength.valueOf");
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
assert.compareArray(calls, ["newLength.valueOf"],
|
||||
"Must read newLength before verifying mutability.");
|
40
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-immutable-arraybuffer.js
vendored
Normal file
40
test/built-ins/ArrayBuffer/prototype/transferToFixedLength/this-is-immutable-arraybuffer.js
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2025 Richard Gibson. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-arraybuffer.prototype.transferToFixedLength
|
||||
description: Throws a TypeError if `this` is immutable.
|
||||
info: |
|
||||
ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] )
|
||||
1. Let O be the this value.
|
||||
2. Return ? ArrayBufferCopyAndDetach(O, newLength, ~fixed-length~).
|
||||
|
||||
ArrayBufferCopyAndDetach ( arrayBuffer, newLength, preserveResizability )
|
||||
1. Perform ? RequireInternalSlot(arrayBuffer, [[ArrayBufferData]]).
|
||||
2. If IsSharedArrayBuffer(arrayBuffer) is true, throw a TypeError exception.
|
||||
3. If newLength is undefined, then
|
||||
a. Let newByteLength be arrayBuffer.[[ArrayBufferByteLength]].
|
||||
4. Else,
|
||||
a. Let newByteLength be ? ToIndex(newLength).
|
||||
5. If IsDetachedBuffer(arrayBuffer) is true, throw a TypeError exception.
|
||||
6. If IsImmutableBuffer(arrayBuffer) is true, throw a TypeError exception.
|
||||
features: [arraybuffer-transfer, immutable-arraybuffer]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var calls = [];
|
||||
|
||||
var ab = (new ArrayBuffer(4)).transferToImmutable();
|
||||
assert.throws(TypeError, function() {
|
||||
ab.transferToFixedLength();
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
ab.transferToFixedLength({
|
||||
valueOf() {
|
||||
calls.push("newLength.valueOf");
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
assert.compareArray(calls, ["newLength.valueOf"],
|
||||
"Must read newLength before verifying mutability.");
|
Loading…
x
Reference in New Issue
Block a user