From 6cdb375d8c1038f5ffde6a97e676979fd17ce074 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Tue, 13 Sep 2022 21:30:37 -0400 Subject: [PATCH] Add test for length conversion --- .../Array/prototype/group/invalid-object.js | 2 +- .../Array/prototype/group/length-throw.js | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/built-ins/Array/prototype/group/length-throw.js diff --git a/test/built-ins/Array/prototype/group/invalid-object.js b/test/built-ins/Array/prototype/group/invalid-object.js index 31d04d8ca8..244377832a 100644 --- a/test/built-ins/Array/prototype/group/invalid-object.js +++ b/test/built-ins/Array/prototype/group/invalid-object.js @@ -15,7 +15,7 @@ info: | features: [array-grouping] ---*/ -const throws = () => { +const throws = function() { throw new Test262Error('callback function should not be called') }; diff --git a/test/built-ins/Array/prototype/group/length-throw.js b/test/built-ins/Array/prototype/group/length-throw.js new file mode 100644 index 0000000000..e3d1747e12 --- /dev/null +++ b/test/built-ins/Array/prototype/group/length-throw.js @@ -0,0 +1,36 @@ +// Copyright (c) 2021 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.group +description: Array.prototype.group errors when array-like's length can't be coerced. +info: | + 22.1.3.14 Array.prototype.group ( callbackfn [ , thisArg ] ) + + ... + + 2. Let len be ? LengthOfArrayLike(O). + + ... +features: [array-grouping] +---*/ + +assert.throws(Test262Error, function() { + const arrayLike = Object.defineProperty({}, 'length', { + get: function() { + throw new Test262Error('no length for you'); + } + }); + Array.prototype.group.call(arrayLike, function() { + return 'key'; + }); +}); + +assert.throws(TypeError, function() { + const arrayLike = { + length: 1n, + }; + Array.prototype.group.call(arrayLike, function() { + return 'key'; + }); +});