From 1b1dca163655f5ca43b270eab351ef3722110c2e Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Sat, 11 Jun 2022 02:42:43 +0900 Subject: [PATCH] `.with` should convert `value` up front https://github.com/tc39/proposal-change-array-by-copy/pull/86 --- src/Float16Array.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Float16Array.mjs b/src/Float16Array.mjs index af048d4e..9e9ece53 100644 --- a/src/Float16Array.mjs +++ b/src/Float16Array.mjs @@ -536,6 +536,8 @@ export class Float16Array { const relativeIndex = ToIntegerOrInfinity(index); const k = relativeIndex >= 0 ? relativeIndex : length + relativeIndex; + const number = +value; + if (k < 0 || k >= length) { throw new NativeRangeError(OFFSET_IS_OUT_OF_BOUNDS); } @@ -553,7 +555,7 @@ export class Float16Array { ); const array = getFloat16BitsArray(cloned); - array[k] = roundToFloat16Bits(value); + array[k] = roundToFloat16Bits(number); return cloned; }