From 8649d5e117ecb764fd1c07445ba3e74816b943fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Mon, 12 May 2025 15:57:59 +0200 Subject: [PATCH] Add coverage for throw completions in (Typed)Array.prototype.with SpiderMonkey doesn't handle this correctly for `Array.prototype.with`. --- .../prototype/with/index-throw-completion.js | 27 +++++++++++++ .../prototype/with/index-throw-completion.js | 38 +++++++++++++++++++ .../prototype/with/value-throw-completion.js | 37 ++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 test/built-ins/Array/prototype/with/index-throw-completion.js create mode 100644 test/built-ins/TypedArray/prototype/with/index-throw-completion.js create mode 100644 test/built-ins/TypedArray/prototype/with/value-throw-completion.js 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"); +});