Skip to content

[immutable-arraybuffer] TypedArray internal operations#4551

Open
gibson042 wants to merge 16 commits into
tc39:mainfrom
gibson042:2025-07-immutable-arraybuffer-typedarray-internal-operations
Open

[immutable-arraybuffer] TypedArray internal operations#4551
gibson042 wants to merge 16 commits into
tc39:mainfrom
gibson042:2025-07-immutable-arraybuffer-typedarray-internal-operations

Conversation

@gibson042

@gibson042 gibson042 commented Jul 29, 2025

Copy link
Copy Markdown
Member

Ref #4509

%TypedArray% instance operations

  • [[GetOwnProperty]]

    • property descriptors for in-bounds indexes of a typed array backed by an immutable ArrayBuffer are reported as writable false, enumerable true, configurable false
  • [[DefineOwnProperty]]

    • attempts to redefine own properties for in-bounds indexes of a typed array backed by an immutable ArrayBuffer are validated against descriptors for immutable properties
      • presence of writable: true, enumerable: false, configurable: true, get, and/or set results in rejection
      • presence of value with any value that is not treated as identical to the current value by Object.is results in rejection (e.g., value: -0 and value: "0" are rejected when the current value is 0)
      • all other property descriptors (e.g., any subset of { writable: false, enumerable: true, configurable: false, value: $currentValue }) are accepted but do not result in observable changes
  • [[Set]]

    • any attempt to set the value for a property whose name is a canonical numeric index string (including non-index values such as "-0", "1.5", "590295810358705700000", "5e-324", "1.7976931348623157e+308", "Infinity", and "NaN") on a typed array backed by an immutable ArrayBuffer is rejected, even if the new value is identical to the current value
    • likewise for attempts on a receiver having such a typed array in its prototype chain when the [[Set]] makes it to the typed array

Most of the changes just relax filters applied to testWithTypedArrayConstructors and similar harness/testTypedArray.js exports such that immutable ArrayBuffers are no longer excluded.

@gibson042
gibson042 requested a review from a team as a code owner July 29, 2025 16:35
@gibson042
gibson042 force-pushed the 2025-07-immutable-arraybuffer-typedarray-internal-operations branch from 55e9cb7 to 795f516 Compare August 1, 2025 01:35
@gibson042
gibson042 force-pushed the 2025-07-immutable-arraybuffer-typedarray-internal-operations branch from 795f516 to 0fa24b7 Compare May 8, 2026 00:21
gibson042 added a commit to gibson042/test262 that referenced this pull request May 8, 2026
@gibson042
gibson042 force-pushed the 2025-07-immutable-arraybuffer-typedarray-internal-operations branch from 0fa24b7 to c8acdac Compare May 8, 2026 01:40
@gibson042
gibson042 requested a review from ptomato May 8, 2026 01:42
@ptomato

ptomato commented May 15, 2026

Copy link
Copy Markdown
Contributor

Needs a non-trivial rebase.

gibson042 added a commit to gibson042/test262 that referenced this pull request May 17, 2026
@gibson042
gibson042 force-pushed the 2025-07-immutable-arraybuffer-typedarray-internal-operations branch from c8acdac to 3be710d Compare May 17, 2026 17:21
@gibson042

Copy link
Copy Markdown
Member Author

Needs a non-trivial rebase.

Done.

@ptomato ptomato left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't gotten most of the way through this yet, but here are some comments. I also don't understand what the purpose is of the first three commits - the first one ("Make better use of testTypedArray.js") seems like it's actually removing coverage in some cases?

Comment thread harness/propertyHelper.js Outdated
Comment thread harness/propertyHelper.js Outdated
Comment thread harness/propertyHelper.js Outdated
Comment thread harness/propertyHelper.js
@gibson042
gibson042 force-pushed the 2025-07-immutable-arraybuffer-typedarray-internal-operations branch 2 times, most recently from 9440796 to dea78c5 Compare May 19, 2026 14:52
…perties cannot be set when the backing buffer is immutable
…es are non-configurable and non-writable when the backing buffer is immutable
…es being defined are validated against descriptors for immutable properties
@ptomato
ptomato force-pushed the 2025-07-immutable-arraybuffer-typedarray-internal-operations branch from dea78c5 to 8fb816f Compare July 23, 2026 22:24
@ptomato

ptomato commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The linter failure seems to be a side effect of my recent fix of harness file defines. I believe rebasing on #5094 should fix it.

@ptomato

ptomato commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

(Removing compareArray.js from the frontmatter in these tests would also fix it, but that's another pass over an already long PR so it's fine if you don't want to do that right now.)

@ptomato ptomato left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've convinced myself that the new tests cover the remaining unchecked items in #4509, so this works for me. Feel free to merge when the comments are addressed, as far as I'm concerned.

I only skimmed the files where the TypedArray arg factories were edited.

It occurred to me that it'd be nice to add harness tests for the bugs you fixed in verifyProperty, but I'd say that's optional too.

Comment on lines +21 to +32
function makeSpy(calls, label, value) {
return {
toString() {
calls.push(label + " toString");
return value;
},
valueOf() {
calls.push(label + " valueOf");
return value;
}
};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional: You could use TemporalHelpers.toPrimitiveObserver for this. Although, we really need to move that into its own helper file. (Same comment for files in the same commit)

Comment on lines +34 to +39
function unloggedHasOwn(obj, key, calls) {
var length = calls.length;
var result = obj.hasOwnProperty(key);
calls.length = length;
return result;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If I'm reading correctly, this won't log anything, regardless? In that case it seems better to just use hasOwnProperty and only add this in the future if it's necessary. (Same comment for files in the same commit)

Comment on lines +53 to +54
assert.deepEqual(Object.getOwnPropertyDescriptor(sample, "0"), descriptor,
"results of Reflect.defineProperty " + reprDesc(newDesc));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional: I'd like to avoid assert.deepEqual in new tests (#3476) but this PR has been waiting long enough so I wouldn't hold things up on that.

If you do feel like fixing it, I think at first glance verifyProperty(sample, "0", descriptor, { label: ..., restore: true }) ought to work? But I haven 't looked at that too closely. If not, then a custom comparison function seems like the way to go.

Comment thread harness/propertyHelper.js
Comment on lines +223 to +229
// As a special case, never decrease array length (which would delete
// properties not covered by the new length).
if (oldValue <= 0 || __isArray(obj) && name === "length") {
newValue = oldValue === -Infinity ? 0 : oldValue + 1;
} else {
newValue = oldValue === Infinity ? 1 : oldValue - 1;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this produces a false positive for readonly NaN properties, because newValue is also NaN, whereas the old code would've written "unlikelyValue" and correctly determined that the write failed. Verified with a spot check:

var obj = {};
Object.defineProperty(obj, "a", { value: NaN, writable: false });
assert(verifyProperty(obj, 'a', { value: NaN, writable: false }));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants