Add coverage for converting negative fractional index to zero in (Typed)Array.prototype.with

JSC doesn't handle this correctly for `TypedArray.prototype.with`.
This commit is contained in:
André Bargull 2025-05-12 15:58:00 +02:00 committed by Philip Chimento
parent 7c9314b06b
commit 88c5b410aa
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,26 @@
// Copyright (C) 2025 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.with
description: >
Negative fractional index which is truncated to zero.
info: |
Array.prototype.with ( index, value )
...
3. Let relativeIndex be ? ToIntegerOrInfinity(index).
...
ToIntegerOrInfinity ( argument )
1. Let number be ? ToNumber(argument).
2. If number is one of NaN, +0𝔽, or -0𝔽, return 0.
3. If number is +𝔽, return +.
4. If number is -𝔽, return -.
5. Return truncate((number)).
features: [change-array-by-copy]
---*/
var result = [0].with(-0.5, 123);
assert.sameValue(result[0], 123);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2025 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.with
description: >
Negative fractional index which is truncated to zero.
info: |
%TypedArray%.prototype.with ( index, value )
...
4. Let relativeIndex be ? ToIntegerOrInfinity(index).
...
ToIntegerOrInfinity ( argument )
1. Let number be ? ToNumber(argument).
2. If number is one of NaN, +0𝔽, or -0𝔽, return 0.
3. If number is +𝔽, return +.
4. If number is -𝔽, return -.
5. Return truncate((number)).
features: [TypedArray, change-array-by-copy]
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var ta = new TA(1);
var result = ta.with(-0.5, 123);
assert.sameValue(result[0], 123);
});