From 88c5b410aa453268133c6a3559dddeee7f34037f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Mon, 12 May 2025 15:58:00 +0200 Subject: [PATCH] Add coverage for converting negative fractional index to zero in (Typed)Array.prototype.with JSC doesn't handle this correctly for `TypedArray.prototype.with`. --- ...tive-fractional-index-truncated-to-zero.js | 26 ++++++++++++++++ ...tive-fractional-index-truncated-to-zero.js | 30 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/built-ins/Array/prototype/with/negative-fractional-index-truncated-to-zero.js create mode 100644 test/built-ins/TypedArray/prototype/with/negative-fractional-index-truncated-to-zero.js 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); +});