Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Array / prototype / with / index-negative.js
blobd9b8a8eaac5a5de12c640043ebe2e8200a8fb49d
1 // Copyright (C) 2021 Igalia, S.L. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-array.prototype.with
6 description: >
7   Array.prototype.with adds length to index if it's negative.
8 info: |
9   Array.prototype.with ( index, value )
11   ...
12   2. Let len be ? LengthOfArrayLike(O).
13   3. Let relativeIndex be ? ToIntegerOrInfinity(index).
14   4. If index >= 0, let actualIndex be relativeIndex.
15   5. Else, let actualIndex be len + relativeIndex.
16   ...
17 features: [change-array-by-copy]
18 includes: [compareArray.js]
19 ---*/
21 var arr = [0, 1, 2];
23 assert.compareArray(arr.with(-1, 4), [0, 1, 4]);
24 assert.compareArray(arr.with(-3, 4), [4, 1, 2]);
26 // -0 is not < 0
27 assert.compareArray(arr.with(-0, 4), [4, 1, 2]);
29 reportCompare(0, 0);