Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions test/built-ins/ArrayBuffer/prototype/immutable/prop-desc.js
Original file line number Diff line number Diff line change
@@ -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-get-arraybuffer.prototype.immutable
description: Checks the "immutable" property of ArrayBuffer.prototype.
info: |
ArrayBuffer.prototype.immutable is an accessor property whose set accessor
function is undefined.

ECMAScript Standard Built-in Objects
...
For functions that are specified as properties of objects, the name value is
the property name string used to access the function. Functions that are
specified as get or set accessor functions of built-in properties have "get"
or "set" (respectively) passed to the prefix parameter when calling
CreateBuiltinFunction.
...
Every accessor property described in clauses 19 through 28 and in Annex B.2
has the attributes { [[Enumerable]]: false, [[Configurable]]: true } unless
otherwise specified. If only a get accessor function is described, the set
accessor function is the default value, undefined.
features: [immutable-arraybuffer]
includes: [propertyHelper.js]
---*/

var desc = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "immutable");
var isHardened = Object.isFrozen(Object);
if (isHardened && desc.get) {
Object.defineProperty(desc, "get", { configurable: false });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be in individual tests, if we support it at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on defineProperty (and removed), but varying the configurable assumption is pretty much necessary to avoid excessive work in a hardened environment.


assert.sameValue(desc.value, undefined);
assert.sameValue(desc.set, undefined);
verifyCallableProperty(desc, "get", "get immutable", 0, { configurable: !isHardened });

verifyPrimordialProperty(ArrayBuffer.prototype, "immutable", {
enumerable: false,
configurable: true
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2025 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-arraybuffer.prototype.immutable
description: Return value according to the [[ArrayBufferIsImmutable]] internal slot.
info: |
get ArrayBuffer.prototype.immutable
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
4. Return IsImmutableBuffer(O).

IsImmutableBuffer ( arrayBuffer )
1. If arrayBuffer has an [[ArrayBufferIsImmutable]] internal slot, return true.
2. Return false.
features: [ArrayBuffer, immutable-arraybuffer]
includes: [detachArrayBuffer.js]
---*/

var ab = new ArrayBuffer(1);
assert.sameValue(ab.immutable, false);

var iab = ab.transferToImmutable();
assert.sameValue(iab.immutable, true);

$DETACHBUFFER(ab);
assert.sameValue(ab.immutable, false);
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (C) 2025 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-arraybuffer.prototype.immutable
description: >
Throws a TypeError exception when `this` does not have a [[ArrayBufferData]]
internal slot
info: |
get ArrayBuffer.prototype.immutable
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
features: [DataView, Int8Array, ArrayBuffer, immutable-arraybuffer]
---*/

var getter = Object.getOwnPropertyDescriptor(
ArrayBuffer.prototype, "immutable"
).get;

assert.sameValue(typeof getter, "function", "Getter must exist.");

var badReceivers = [
["plain object", {}],
["array", []],
["function", function(){}],
["ArrayBuffer.prototype", ArrayBuffer.prototype],
["TypedArray", new Int8Array(8)],
["DataView", new DataView(new ArrayBuffer(8), 0)]
];

for (var i = 0; i < badReceivers.length; i++) {
var label = badReceivers[i][0];
var value = badReceivers[i][1];
assert.throws(TypeError, function() {
getter.call(value);
}, label);
}

assert.throws(TypeError, function() {
ArrayBuffer.prototype.immutable;
}, "invoked as prototype property access");

assert.throws(TypeError, function() {
getter();
}, "invoked as function");
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2025 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-arraybuffer.prototype.immutable
description: Throws a TypeError exception when `this` is not an object
info: |
get ArrayBuffer.prototype.immutable
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
features: [ArrayBuffer, immutable-arraybuffer]
---*/

var getter = Object.getOwnPropertyDescriptor(
ArrayBuffer.prototype, "immutable"
).get;

assert.sameValue(typeof getter, "function", "Getter must exist.");

var badReceivers = [
["undefined", undefined],
["null", null],
["number", 42],
["string", "1"],
["true", true],
["false", false],
typeof Symbol === "undefined" ? undefined : ["unique symbol", Symbol("s")],
typeof Symbol === "undefined" || !Symbol.for ? undefined : ["registered symbol", Symbol.for("s")],
typeof BigInt === "undefined" ? undefined : ["bigint", BigInt(1)]
];

for (var i = 0; i < badReceivers.length; i++) {
if (!badReceivers[i]) continue;
var label = badReceivers[i][0];
var value = badReceivers[i][1];
assert.throws(TypeError, function() {
getter.call(value);
}, label);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2025 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-arraybuffer.prototype.immutable
description: Throws a TypeError exception when `this` is a SharedArrayBuffer
info: |
get ArrayBuffer.prototype.immutable
1. Let O be the this value.
2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
features: [SharedArrayBuffer, ArrayBuffer, immutable-arraybuffer]
---*/

var getter = Object.getOwnPropertyDescriptor(
ArrayBuffer.prototype, "immutable"
).get;

assert.sameValue(typeof getter, "function", "Getter must exist.");

var sab = new SharedArrayBuffer(4);
assert.throws(TypeError, function() {
getter.call(sab);
});