Skip to content

Commit 50bb04e

Browse files
committed
Add return-abrupt-from-this-length tests for Change Array by Copy methods
Mirrors the existing pattern in findLast and findLastIndex.
1 parent a47576c commit 50bb04e

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2026 dmvjs. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-array.prototype.toreversed
6+
description: >
7+
Return abrupt from ToLength(Get(O, "length")).
8+
info: |
9+
Array.prototype.toReversed ( )
10+
11+
1. Let O be ? ToObject(this value).
12+
2. Let len be ? LengthOfArrayLike(O).
13+
features: [change-array-by-copy]
14+
---*/
15+
16+
var o1 = {};
17+
18+
Object.defineProperty(o1, 'length', {
19+
get: function() {
20+
throw new Test262Error();
21+
},
22+
configurable: true
23+
});
24+
25+
assert.throws(Test262Error, function() {
26+
Array.prototype.toReversed.call(o1);
27+
});
28+
29+
var o2 = {
30+
length: {
31+
valueOf: function() {
32+
throw new Test262Error();
33+
}
34+
}
35+
};
36+
37+
assert.throws(Test262Error, function() {
38+
Array.prototype.toReversed.call(o2);
39+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2026 dmvjs. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-array.prototype.tosorted
6+
description: >
7+
Return abrupt from ToLength(Get(O, "length")).
8+
info: |
9+
Array.prototype.toSorted ( compareFn )
10+
11+
1. Let O be ? ToObject(this value).
12+
2. Let len be ? LengthOfArrayLike(O).
13+
features: [change-array-by-copy]
14+
---*/
15+
16+
var o1 = {};
17+
18+
Object.defineProperty(o1, 'length', {
19+
get: function() {
20+
throw new Test262Error();
21+
},
22+
configurable: true
23+
});
24+
25+
assert.throws(Test262Error, function() {
26+
Array.prototype.toSorted.call(o1);
27+
});
28+
29+
var o2 = {
30+
length: {
31+
valueOf: function() {
32+
throw new Test262Error();
33+
}
34+
}
35+
};
36+
37+
assert.throws(Test262Error, function() {
38+
Array.prototype.toSorted.call(o2);
39+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2026 dmvjs. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-array.prototype.tospliced
6+
description: >
7+
Return abrupt from ToLength(Get(O, "length")).
8+
info: |
9+
Array.prototype.toSpliced ( start, deleteCount, ...items )
10+
11+
1. Let O be ? ToObject(this value).
12+
2. Let len be ? LengthOfArrayLike(O).
13+
features: [change-array-by-copy]
14+
---*/
15+
16+
var o1 = {};
17+
18+
Object.defineProperty(o1, 'length', {
19+
get: function() {
20+
throw new Test262Error();
21+
},
22+
configurable: true
23+
});
24+
25+
assert.throws(Test262Error, function() {
26+
Array.prototype.toSpliced.call(o1);
27+
});
28+
29+
var o2 = {
30+
length: {
31+
valueOf: function() {
32+
throw new Test262Error();
33+
}
34+
}
35+
};
36+
37+
assert.throws(Test262Error, function() {
38+
Array.prototype.toSpliced.call(o2);
39+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2026 dmvjs. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-array.prototype.with
6+
description: >
7+
Return abrupt from ToLength(Get(O, "length")).
8+
info: |
9+
Array.prototype.with ( index, value )
10+
11+
1. Let O be ? ToObject(this value).
12+
2. Let len be ? LengthOfArrayLike(O).
13+
features: [change-array-by-copy]
14+
---*/
15+
16+
var o1 = {};
17+
18+
Object.defineProperty(o1, 'length', {
19+
get: function() {
20+
throw new Test262Error();
21+
},
22+
configurable: true
23+
});
24+
25+
assert.throws(Test262Error, function() {
26+
Array.prototype.with.call(o1, 0, 1);
27+
});
28+
29+
var o2 = {
30+
length: {
31+
valueOf: function() {
32+
throw new Test262Error();
33+
}
34+
}
35+
};
36+
37+
assert.throws(Test262Error, function() {
38+
Array.prototype.with.call(o2, 0, 1);
39+
});

0 commit comments

Comments
 (0)