-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage for value coercions in TypedArray.p.with
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
test/built-ins/TypedArray/prototype/with/order-of-evaluation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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: > | ||
Index parameter is coerced before value parameter. | ||
info: | | ||
%TypedArray%.prototype.with ( index, value ) | ||
... | ||
4. Let relativeIndex be ? ToIntegerOrInfinity(index). | ||
... | ||
8. Else, let numericValue be ? ToNumber(value). | ||
... | ||
features: [TypedArray, change-array-by-copy] | ||
includes: [testTypedArray.js, compareArray.js] | ||
---*/ | ||
|
||
testWithTypedArrayConstructors(TA => { | ||
var ta = new TA(1); | ||
|
||
var logs = []; | ||
|
||
var index = { | ||
valueOf() { | ||
logs.push("index"); | ||
return 0; | ||
} | ||
}; | ||
|
||
var value = { | ||
valueOf() { | ||
logs.push("value"); | ||
return 0; | ||
} | ||
}; | ||
|
||
ta.with(index, value); | ||
|
||
assert.compareArray(logs, ["index", "value"]); | ||
}); |
35 changes: 35 additions & 0 deletions
35
test/built-ins/TypedArray/prototype/with/valid-typedarray-index-checked-after-coercions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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: > | ||
IsValidIntegerIndex is checked after all coercions happened. | ||
info: | | ||
%TypedArray%.prototype.with ( index, value ) | ||
... | ||
8. Else, let numericValue be ? ToNumber(value). | ||
9. If IsValidIntegerIndex(O, 𝔽(actualIndex)) is false, throw a RangeError exception. | ||
... | ||
features: [TypedArray, change-array-by-copy, resizable-arraybuffer] | ||
includes: [testTypedArray.js] | ||
---*/ | ||
|
||
testWithTypedArrayConstructors(TA => { | ||
var rab = new ArrayBuffer(0, {maxByteLength: TA.BYTES_PER_ELEMENT}); | ||
var ta = new TA(rab); | ||
assert.sameValue(ta.length, 0); | ||
|
||
var value = { | ||
valueOf() { | ||
rab.resize(TA.BYTES_PER_ELEMENT); | ||
return 0; | ||
} | ||
}; | ||
|
||
var result = ta.with(0, value); | ||
|
||
assert.sameValue(result.length, 0); | ||
assert.sameValue(rab.byteLength, TA.BYTES_PER_ELEMENT); | ||
}); |