From 25dbbf5d8f762ea016b20845e409bd2fd3c0be5d Mon Sep 17 00:00:00 2001 From: G-Lee1031 Date: Wed, 28 Jan 2026 15:40:16 +0900 Subject: [PATCH 1/2] Added a test for Array.prototype.flatMap where mapperFunction throws --- .../flatMap/mapperfunction-throws.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/built-ins/Array/prototype/flatMap/mapperfunction-throws.js diff --git a/test/built-ins/Array/prototype/flatMap/mapperfunction-throws.js b/test/built-ins/Array/prototype/flatMap/mapperfunction-throws.js new file mode 100644 index 00000000000..7729d99a37e --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/mapperfunction-throws.js @@ -0,0 +1,30 @@ +// Copyright (C) 2026 Garham Lee. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.flatmap +description: > + Array.prototype.flatMap throws when _mapperFunction_ throws. +info: | + Array.prototype.flatMap ( _mapperFunction_ [ , _thisArg_ ] ) + + 1. Let _O_ be ? ToObject(*this* value). + 2. Let _sourceLen_ be ? LengthOfArrayLike(_O_). + 5. Perform ? FlattenIntoArray(_A_, _O_, _sourceLen_, 0, 1, _mapperFunction_, _thisArg_). + + FlattenIntoArray (_target_,_source_,_sourceLen_,_start_,_depth_,optional _mapperFunction_,optional _thisArg_,) + + 2. Let _targetIndex_ be _start_. + 3. Let _sourceIndex_ be *+0*𝔽. + 4. Repeat, while ℝ(_sourceIndex_) < _sourceLen_, + a. Let _P_ be ! ToString(_sourceIndex_). + b. Let _exists_ be ? HasProperty(_source_, _P_). + c. If _exists_ is *true*, then + i. Let _element_ be ? Get(_source_, _P_). + ii. If _mapperFunction_ is present, then + 1. Set _element_ to ? Call(_mapperFunction_, _thisArg_, « _element_, _sourceIndex_, _source_ »). +features: [Array.prototype.flatMap] +---*/ +assert.throws(Test262Error, function () { + [0].flatMap(x => {throw new Test262Error}); +}); From 22e73e54516448c889b46772509049b83181c959 Mon Sep 17 00:00:00 2001 From: G-Lee1031 Date: Thu, 29 Jan 2026 11:11:40 +0900 Subject: [PATCH 2/2] added another test for empty array case. --- .../Array/prototype/flatMap/mapperfunction-throws.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/built-ins/Array/prototype/flatMap/mapperfunction-throws.js b/test/built-ins/Array/prototype/flatMap/mapperfunction-throws.js index 7729d99a37e..8c9ab7eebd1 100644 --- a/test/built-ins/Array/prototype/flatMap/mapperfunction-throws.js +++ b/test/built-ins/Array/prototype/flatMap/mapperfunction-throws.js @@ -4,7 +4,7 @@ /*--- esid: sec-array.prototype.flatmap description: > - Array.prototype.flatMap throws when _mapperFunction_ throws. + Array.prototype.flatMap throws when _soucreLen_ is not 0 and _mapperFunction_ throws. info: | Array.prototype.flatMap ( _mapperFunction_ [ , _thisArg_ ] ) @@ -25,6 +25,16 @@ info: | 1. Set _element_ to ? Call(_mapperFunction_, _thisArg_, « _element_, _sourceIndex_, _source_ »). features: [Array.prototype.flatMap] ---*/ +//Check #1 assert.throws(Test262Error, function () { [0].flatMap(x => {throw new Test262Error}); }); + +//Check #2 +var callcount = 0; +[].flatMap(() => { + callcount += 1; + throw new Test262Error; +}); + +assert.sameValue(callcount, 0, "If _soucreLen_ is 0, _mapperFunction_ should not be called.")