diff --git a/test/built-ins/Iterator/prototype/drop/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/drop/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..cc8367df129 --- /dev/null +++ b/test/built-ins/Iterator/prototype/drop/argument-validation-failure-closes-underlying.js @@ -0,0 +1,48 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.drop +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.drop ( limit ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(RangeError, function() { + closable.drop(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(RangeError, function() { + closable.drop(NaN); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(RangeError, function() { + closable.drop(-1); +}); +assert.sameValue(closed, true); + +closed = false; +class ShouldNotGetValueOf {} +assert.throws(ShouldNotGetValueOf, function() { + closable.drop({ get valueOf() { throw new ShouldNotGetValueOf(); }}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/every/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/every/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..c4202c46e0b --- /dev/null +++ b/test/built-ins/Iterator/prototype/every/argument-validation-failure-closes-underlying.js @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.every +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.every ( predicate ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(TypeError, function() { + closable.every(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(TypeError, function() { + closable.every({}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/filter/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/filter/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..821a849599a --- /dev/null +++ b/test/built-ins/Iterator/prototype/filter/argument-validation-failure-closes-underlying.js @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.filter +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.filter ( predicate ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(TypeError, function() { + closable.filter(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(TypeError, function() { + closable.filter({}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/find/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/find/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..9edbee820c9 --- /dev/null +++ b/test/built-ins/Iterator/prototype/find/argument-validation-failure-closes-underlying.js @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.find +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.find ( predicate ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(TypeError, function() { + closable.find(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(TypeError, function() { + closable.find({}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/flatMap/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/flatMap/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..3f491c5deff --- /dev/null +++ b/test/built-ins/Iterator/prototype/flatMap/argument-validation-failure-closes-underlying.js @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.flatMap +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.flatMap ( mapper ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(TypeError, function() { + closable.flatMap(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(TypeError, function() { + closable.flatMap({}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/forEach/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/forEach/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..f5b20b36c0a --- /dev/null +++ b/test/built-ins/Iterator/prototype/forEach/argument-validation-failure-closes-underlying.js @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.forEach +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.forEach ( predicate ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(TypeError, function() { + closable.forEach(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(TypeError, function() { + closable.forEach({}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/map/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/map/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..226620c233a --- /dev/null +++ b/test/built-ins/Iterator/prototype/map/argument-validation-failure-closes-underlying.js @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.map +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.map ( mapper ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(TypeError, function() { + closable.map(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(TypeError, function() { + closable.map({}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/reduce/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/reduce/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..20e8fd10e57 --- /dev/null +++ b/test/built-ins/Iterator/prototype/reduce/argument-validation-failure-closes-underlying.js @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.reduce +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.reduce ( reducer, [ initialValue ] ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(TypeError, function() { + closable.reduce(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(TypeError, function() { + closable.reduce({}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/reduce/non-callable-reducer.js b/test/built-ins/Iterator/prototype/reduce/non-callable-reducer.js index b94d560197a..6a563606301 100644 --- a/test/built-ins/Iterator/prototype/reduce/non-callable-reducer.js +++ b/test/built-ins/Iterator/prototype/reduce/non-callable-reducer.js @@ -11,12 +11,12 @@ features: [iterator-helpers] flags: [] ---*/ let nonCallable = {}; -let iterator = (function* () { +function* gen() { yield 1; -})(); +} assert.throws(TypeError, function () { - iterator.reduce(nonCallable); + gen().reduce(nonCallable); }); -iterator.reduce(() => {}); +gen().reduce(() => {}); diff --git a/test/built-ins/Iterator/prototype/some/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/some/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..0b6b8aa5f53 --- /dev/null +++ b/test/built-ins/Iterator/prototype/some/argument-validation-failure-closes-underlying.js @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.some +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.some ( predicate ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(TypeError, function() { + closable.some(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(TypeError, function() { + closable.some({}); +}); +assert.sameValue(closed, true); diff --git a/test/built-ins/Iterator/prototype/take/argument-validation-failure-closes-underlying.js b/test/built-ins/Iterator/prototype/take/argument-validation-failure-closes-underlying.js new file mode 100644 index 00000000000..7c9d4a32644 --- /dev/null +++ b/test/built-ins/Iterator/prototype/take/argument-validation-failure-closes-underlying.js @@ -0,0 +1,48 @@ +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteratorprototype.take +description: > + Underlying iterator is closed when argument validation fails +info: | + %Iterator.prototype%.take ( limit ) + +features: [iterator-helpers] +flags: [] +---*/ + +let closed = false; +let closable = { + __proto__: Iterator.prototype, + get next() { + throw new Test262Error('next should not be read'); + }, + return() { + closed = true; + return {}; + }, +}; + +assert.throws(RangeError, function() { + closable.take(); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(RangeError, function() { + closable.take(NaN); +}); +assert.sameValue(closed, true); + +closed = false; +assert.throws(RangeError, function() { + closable.take(-1); +}); +assert.sameValue(closed, true); + +closed = false; +class ShouldNotGetValueOf {} +assert.throws(ShouldNotGetValueOf, function() { + closable.take({ get valueOf() { throw new ShouldNotGetValueOf(); }}); +}); +assert.sameValue(closed, true);