diff --git a/test/built-ins/Array/prototype/with/index-throw-completion.js b/test/built-ins/Array/prototype/with/index-throw-completion.js new file mode 100644 index 0000000000..a3965f7e21 --- /dev/null +++ b/test/built-ins/Array/prototype/with/index-throw-completion.js @@ -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); +}); diff --git a/test/built-ins/TypedArray/prototype/with/index-throw-completion.js b/test/built-ins/TypedArray/prototype/with/index-throw-completion.js new file mode 100644 index 0000000000..c5dc254a38 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/with/index-throw-completion.js @@ -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); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/with/value-throw-completion.js b/test/built-ins/TypedArray/prototype/with/value-throw-completion.js new file mode 100644 index 0000000000..760571da24 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/with/value-throw-completion.js @@ -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"); +});