diff --git a/test/built-ins/Array/prototype/with/negative-fractional-index-truncated-to-zero.js b/test/built-ins/Array/prototype/with/negative-fractional-index-truncated-to-zero.js new file mode 100644 index 0000000000..ab50faeb4f --- /dev/null +++ b/test/built-ins/Array/prototype/with/negative-fractional-index-truncated-to-zero.js @@ -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); diff --git a/test/built-ins/TypedArray/prototype/with/negative-fractional-index-truncated-to-zero.js b/test/built-ins/TypedArray/prototype/with/negative-fractional-index-truncated-to-zero.js new file mode 100644 index 0000000000..15428c5fa8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/with/negative-fractional-index-truncated-to-zero.js @@ -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); +});