Skip to content

Commit

Permalink
Cast .with index to a number
Browse files Browse the repository at this point in the history
  • Loading branch information
petamoriken committed Dec 14, 2021
1 parent 9755b34 commit 1f96a85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Float16Array.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ export class Float16Array {
return convertToNumber(float16bitsArray[k]);
}

/** @see https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.withAt */
withAt(index, value) {
/** @see https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.with */
with(index, value) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);

Expand Down
24 changes: 12 additions & 12 deletions test/Float16Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,30 +826,30 @@ describe("Float16Array", () => {
});
});

describe("#withAt()", () => {
it("property `name` is 'withAt'", () => {
assert(Float16Array.prototype.withAt.name === "withAt");
describe("#with()", () => {
it("property `name` is 'with'", () => {
assert(Float16Array.prototype.with.name === "with");
});

it("property `length` is 1", () => {
assert(Float16Array.prototype.withAt.length === 2);
assert(Float16Array.prototype.with.length === 2);
});

it("withAt", () => {
it("with", () => {
const float16_1 = new Float16Array([1, 2, 3]);
const float16_2 = float16_1.withAt(1, 4);
const float16_2 = float16_1.with(1, 4);

assert(float16_1.buffer !== float16_2.buffer);
assert.equalFloat16ArrayValues(float16_1, [1, 2, 3]);
assert.equalFloat16ArrayValues(float16_2, [1, 4, 3]);

const float16_3 = float16_1.withAt(-1, 4);
const float16_3 = float16_1.with(-1, 4);

assert(float16_1.buffer !== float16_3.buffer);
assert.equalFloat16ArrayValues(float16_1, [1, 2, 3]);
assert.equalFloat16ArrayValues(float16_3, [1, 2, 4]);

const float16_4 = float16_1.withAt(0, "aaa");
const float16_4 = float16_1.with(0, "aaa");

assert(float16_1.buffer !== float16_4.buffer);
assert.equalFloat16ArrayValues(float16_1, [1, 2, 3]);
Expand All @@ -861,20 +861,20 @@ describe("Float16Array", () => {

// out of range
assert.throws(() => {
float16.withAt(5, 0);
float16.with(5, 0);
}, RangeError);
assert.throws(() => {
float16.withAt(-5, 0);
float16.with(-5, 0);
}, RangeError);

assert.throws(() => {
float16.withAt(Symbol(), 0);
float16.with(Symbol(), 0);
}, TypeError);

// Safari 13 doesn't have BigInt
if (typeof BigInt !== "undefined") {
assert.throws(() => {
float16.withAt(BigInt(0), 0);
float16.with(BigInt(0), 0);
}, TypeError);
}
});
Expand Down

0 comments on commit 1f96a85

Please sign in to comment.