Add coverage for throw completions in (Typed)Array.prototype.with

SpiderMonkey doesn't handle this correctly for `Array.prototype.with`.
This commit is contained in:
André Bargull 2025-05-12 15:57:59 +02:00 committed by Philip Chimento
parent 006b3046fa
commit 8649d5e117
3 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// Copyright (C) 2025 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.with
description: >
Index coercion returns a throw completion.
info: |
Array.prototype.with ( index, value )
...
4. Let relativeIndex be ? ToIntegerOrInfinity(index).
...
features: [change-array-by-copy]
---*/
function MyError() {}
var index = {
valueOf() {
throw new MyError();
}
};
assert.throws(MyError, function() {
[].with(index, null);
});

View File

@ -0,0 +1,38 @@
// 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 coercion returns a throw completion.
info: |
%TypedArray%.prototype.with ( index, value )
...
4. Let relativeIndex be ? ToIntegerOrInfinity(index).
...
features: [TypedArray, change-array-by-copy]
includes: [testTypedArray.js]
---*/
function MyError() {}
testWithTypedArrayConstructors(function(TA) {
var ta = new TA(1);
var index = {
valueOf() {
throw new MyError();
}
};
var value = {
valueOf() {
throw new Test262Error("Unexpected value coercion");
}
};
assert.throws(MyError, function() {
ta.with(index, value);
});
});

View File

@ -0,0 +1,37 @@
// 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: >
Value coercion returns a throw completion.
info: |
%TypedArray%.prototype.with ( index, value )
...
7. If O.[[ContentType]] is bigint, let numericValue be ? ToBigInt(value).
8. Else, let numericValue be ? ToNumber(value).
...
features: [TypedArray, change-array-by-copy]
includes: [testTypedArray.js]
---*/
function MyError() {}
testWithTypedArrayConstructors(function(TA) {
var ta = new TA(1);
var value = {
valueOf() {
throw new MyError();
}
};
assert.throws(MyError, function() {
ta.with(100, value);
}, "Positive too large index");
assert.throws(MyError, function() {
ta.with(-100, value);
}, "Negative too large index");
});