From b99eafebdde38a7a3e37ccdabac4ae3516ea6b03 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Sun, 18 Oct 2026 21:41:21 -0700 Subject: [PATCH] iterator helpers: work around IteratorClose swallowing errors --- .../Iterator/concat/next-method-returns-throwing-done.js | 5 +++++ .../concat/next-method-returns-throwing-value.js | 5 +++++ .../Iterator/prototype/chunks/get-next-method-throws.js | 5 +++++ .../prototype/chunks/next-method-returns-non-object.js | 5 +++++ .../chunks/next-method-returns-throwing-done.js | 5 +++++ .../chunks/next-method-returns-throwing-value.js | 5 +++++ .../Iterator/prototype/chunks/next-method-throws.js | 5 +++++ .../prototype/drop/next-method-returns-throwing-done.js | 5 +++++ .../prototype/drop/next-method-returns-throwing-value.js | 5 +++++ .../prototype/every/next-method-returns-throwing-done.js | 5 +++++ .../every/next-method-returns-throwing-value.js | 5 +++++ .../filter/next-method-returns-throwing-done.js | 5 +++++ .../filter/next-method-returns-throwing-value.js | 5 +++++ .../prototype/find/next-method-returns-throwing-done.js | 5 +++++ .../prototype/find/next-method-returns-throwing-value.js | 5 +++++ .../flatMap/next-method-returns-throwing-done.js | 5 +++++ .../flatMap/next-method-returns-throwing-value.js | 5 +++++ .../forEach/next-method-returns-throwing-done.js | 5 +++++ .../forEach/next-method-returns-throwing-value.js | 5 +++++ .../prototype/includes/get-next-method-throws.js | 5 +++++ .../prototype/includes/next-method-returns-non-object.js | 5 +++++ .../includes/next-method-returns-throwing-done.js | 5 +++++ .../includes/next-method-returns-throwing-value.js | 5 +++++ .../Iterator/prototype/includes/next-method-throws.js | 5 +++++ .../prototype/map/next-method-returns-throwing-done.js | 5 +++++ .../prototype/map/next-method-returns-throwing-value.js | 5 +++++ .../reduce/next-method-returns-throwing-done.js | 5 +++++ .../reduce/next-method-returns-throwing-value.js | 5 +++++ .../prototype/some/next-method-returns-throwing-done.js | 5 +++++ .../prototype/some/next-method-returns-throwing-value.js | 5 +++++ .../prototype/take/next-method-returns-throwing-done.js | 9 +++++++++ .../prototype/take/next-method-returns-throwing-value.js | 9 +++++++++ .../toArray/next-method-returns-throwing-done.js | 5 +++++ .../toArray/next-method-returns-throwing-value.js | 5 +++++ .../Iterator/prototype/windows/get-next-method-throws.js | 5 +++++ .../prototype/windows/next-method-returns-non-object.js | 5 +++++ .../windows/next-method-returns-throwing-done.js | 5 +++++ .../windows/next-method-returns-throwing-value.js | 5 +++++ .../Iterator/prototype/windows/next-method-throws.js | 5 +++++ 39 files changed, 203 insertions(+) diff --git a/test/built-ins/Iterator/concat/next-method-returns-throwing-done.js b/test/built-ins/Iterator/concat/next-method-returns-throwing-done.js index 2e7d6151c0a..39853730a54 100644 --- a/test/built-ins/Iterator/concat/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/concat/next-method-returns-throwing-done.js @@ -18,6 +18,8 @@ info: | features: [iterator-sequencing] ---*/ +var returnMethodCalled = false; + let throwingIterator = { next() { return { @@ -28,6 +30,7 @@ let throwingIterator = { }; }, return() { + returnMethodCalled = true; throw new Error(); } }; @@ -43,3 +46,5 @@ let iterator = Iterator.concat(iterable); assert.throws(Test262Error, function() { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/concat/next-method-returns-throwing-value.js b/test/built-ins/Iterator/concat/next-method-returns-throwing-value.js index 3949f4ac574..55914ed6bac 100644 --- a/test/built-ins/Iterator/concat/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/concat/next-method-returns-throwing-value.js @@ -18,6 +18,8 @@ info: | features: [iterator-sequencing] ---*/ +var returnMethodCalled = false; + let throwingIterator = { next() { return { @@ -28,6 +30,7 @@ let throwingIterator = { }; }, return() { + returnMethodCalled = true; throw new Error(); } }; @@ -43,3 +46,5 @@ let iterator = Iterator.concat(iterable); assert.throws(Test262Error, function() { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/chunks/get-next-method-throws.js b/test/built-ins/Iterator/prototype/chunks/get-next-method-throws.js index 373b91d98f5..438a94643e2 100644 --- a/test/built-ins/Iterator/prototype/chunks/get-next-method-throws.js +++ b/test/built-ins/Iterator/prototype/chunks/get-next-method-throws.js @@ -11,11 +11,14 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { get next() { throw new Test262Error(); } get return() { + returnMethodCalled = true; throw new TypeError; } } @@ -25,3 +28,5 @@ let iter = new ThrowingIterator(); assert.throws(Test262Error, function () { iter.chunks(1); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when getting its next method throws"); diff --git a/test/built-ins/Iterator/prototype/chunks/next-method-returns-non-object.js b/test/built-ins/Iterator/prototype/chunks/next-method-returns-non-object.js index 0074519606a..428dc2fd46e 100644 --- a/test/built-ins/Iterator/prototype/chunks/next-method-returns-non-object.js +++ b/test/built-ins/Iterator/prototype/chunks/next-method-returns-non-object.js @@ -9,11 +9,14 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class NonObjectIterator extends Iterator { next() { return null; } get return() { + returnMethodCalled = true; throw new Test262Error(); } } @@ -23,3 +26,5 @@ let iterator = new NonObjectIterator().chunks(1); assert.throws(TypeError, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns a non-object"); diff --git a/test/built-ins/Iterator/prototype/chunks/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/chunks/next-method-returns-throwing-done.js index b93c9c795dc..aeb9d4b0a35 100644 --- a/test/built-ins/Iterator/prototype/chunks/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/chunks/next-method-returns-throwing-done.js @@ -9,6 +9,8 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -19,6 +21,7 @@ class ThrowingIterator extends Iterator { }; } get return() { + returnMethodCalled = true; throw new Test262Error(); } } @@ -28,3 +31,5 @@ let iterator = new ThrowingIterator().chunks(1); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/chunks/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/chunks/next-method-returns-throwing-value.js index a71253885f2..fce14651be6 100644 --- a/test/built-ins/Iterator/prototype/chunks/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/chunks/next-method-returns-throwing-value.js @@ -9,6 +9,8 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -19,6 +21,7 @@ class ThrowingIterator extends Iterator { }; } get return() { + returnMethodCalled = true; throw new TypeError(); } } @@ -28,3 +31,5 @@ let iterator = new ThrowingIterator().chunks(1); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/chunks/next-method-throws.js b/test/built-ins/Iterator/prototype/chunks/next-method-throws.js index b47bd729955..463abe5c270 100644 --- a/test/built-ins/Iterator/prototype/chunks/next-method-throws.js +++ b/test/built-ins/Iterator/prototype/chunks/next-method-throws.js @@ -9,11 +9,14 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { throw new Test262Error(); } get return() { + returnMethodCalled = true; throw new TypeError(); } } @@ -23,3 +26,5 @@ let iterator = new ThrowingIterator().chunks(1); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method throws"); diff --git a/test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-done.js index 88ef17ea195..b81b9488826 100644 --- a/test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-done.js @@ -14,6 +14,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -24,6 +26,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -39,3 +42,5 @@ iterator = new ThrowingIterator().drop(1); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-value.js index da90956616b..dc8688bcc54 100644 --- a/test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/drop/next-method-returns-throwing-value.js @@ -12,6 +12,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -22,6 +24,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -37,3 +40,5 @@ iterator = new ThrowingIterator().drop(1); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-done.js index 56dc8d62d4b..1335bdd152c 100644 --- a/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-done.js @@ -12,6 +12,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -22,6 +24,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -31,3 +34,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.every(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value.js index b2b5f53558f..b3c4b8dfa40 100644 --- a/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value.js @@ -12,6 +12,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -22,6 +24,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -31,3 +34,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.every(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/filter/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/filter/next-method-returns-throwing-done.js index e0ea4d820f8..e60accb5097 100644 --- a/test/built-ins/Iterator/prototype/filter/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/filter/next-method-returns-throwing-done.js @@ -12,6 +12,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -22,6 +24,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -31,3 +34,5 @@ let iterator = new ThrowingIterator().filter(() => true); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/filter/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/filter/next-method-returns-throwing-value.js index 11e67ee5e22..9a63611714a 100644 --- a/test/built-ins/Iterator/prototype/filter/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/filter/next-method-returns-throwing-value.js @@ -12,6 +12,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -22,6 +24,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -31,3 +34,5 @@ let iterator = new ThrowingIterator().filter(() => true); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/find/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/find/next-method-returns-throwing-done.js index 9a3e0a7d859..aceceeed85c 100644 --- a/test/built-ins/Iterator/prototype/find/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/find/next-method-returns-throwing-done.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.find(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/find/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/find/next-method-returns-throwing-value.js index 9453b8c08f4..d6216d3867a 100644 --- a/test/built-ins/Iterator/prototype/find/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/find/next-method-returns-throwing-value.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.find(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/flatMap/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/flatMap/next-method-returns-throwing-done.js index 7dac1daa2ef..a88e30c80f8 100644 --- a/test/built-ins/Iterator/prototype/flatMap/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/flatMap/next-method-returns-throwing-done.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator().flatMap(x => [x]); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/flatMap/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/flatMap/next-method-returns-throwing-value.js index c11cfacd6ab..2b2f626f279 100644 --- a/test/built-ins/Iterator/prototype/flatMap/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/flatMap/next-method-returns-throwing-value.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator().flatMap(x => [x]); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-done.js index 906c9d52875..c4992e6341a 100644 --- a/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-done.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.forEach(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-value.js index 26c3cb04ea9..1153dc49cfd 100644 --- a/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-value.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.forEach(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/includes/get-next-method-throws.js b/test/built-ins/Iterator/prototype/includes/get-next-method-throws.js index e640d4f1086..d7f101eaf85 100644 --- a/test/built-ins/Iterator/prototype/includes/get-next-method-throws.js +++ b/test/built-ins/Iterator/prototype/includes/get-next-method-throws.js @@ -7,12 +7,15 @@ description: > features: [iterator-includes] ---*/ +var returnMethodCalled = false; + let iterator = { __proto__: Iterator.prototype, get next() { throw new Test262Error(); }, get return() { + returnMethodCalled = true; throw new TypeError(); } }; @@ -20,3 +23,5 @@ let iterator = { assert.throws(Test262Error, function() { iterator.includes(0); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when getting its next method throws"); diff --git a/test/built-ins/Iterator/prototype/includes/next-method-returns-non-object.js b/test/built-ins/Iterator/prototype/includes/next-method-returns-non-object.js index c574679aa1f..345a380e72a 100644 --- a/test/built-ins/Iterator/prototype/includes/next-method-returns-non-object.js +++ b/test/built-ins/Iterator/prototype/includes/next-method-returns-non-object.js @@ -7,12 +7,15 @@ description: > features: [iterator-includes] ---*/ +var returnMethodCalled = false; + let iterator = { __proto__: Iterator.prototype, next() { return null; }, get return() { + returnMethodCalled = true; throw new Test262Error(); } }; @@ -20,3 +23,5 @@ let iterator = { assert.throws(TypeError, function() { iterator.includes(0); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns a non-object"); diff --git a/test/built-ins/Iterator/prototype/includes/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/includes/next-method-returns-throwing-done.js index c67ec2909b1..15952b3703f 100644 --- a/test/built-ins/Iterator/prototype/includes/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/includes/next-method-returns-throwing-done.js @@ -7,6 +7,8 @@ description: > features: [iterator-includes] ---*/ +var returnMethodCalled = false; + let iterator = { __proto__: Iterator.prototype, next() { @@ -18,6 +20,7 @@ let iterator = { }; }, get return() { + returnMethodCalled = true; throw new TypeError(); } }; @@ -25,3 +28,5 @@ let iterator = { assert.throws(Test262Error, function() { iterator.includes(0); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/includes/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/includes/next-method-returns-throwing-value.js index 86fd7c305a3..0a49ae4760b 100644 --- a/test/built-ins/Iterator/prototype/includes/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/includes/next-method-returns-throwing-value.js @@ -7,6 +7,8 @@ description: > features: [iterator-includes] ---*/ +var returnMethodCalled = false; + let iterator = { __proto__: Iterator.prototype, next() { @@ -18,6 +20,7 @@ let iterator = { }; }, get return() { + returnMethodCalled = true; throw new TypeError(); } }; @@ -25,3 +28,5 @@ let iterator = { assert.throws(Test262Error, function() { iterator.includes(0); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/includes/next-method-throws.js b/test/built-ins/Iterator/prototype/includes/next-method-throws.js index efdcb6efc0f..37fb215e20b 100644 --- a/test/built-ins/Iterator/prototype/includes/next-method-throws.js +++ b/test/built-ins/Iterator/prototype/includes/next-method-throws.js @@ -7,12 +7,15 @@ description: > features: [iterator-includes] ---*/ +var returnMethodCalled = false; + let iterator = { __proto__: Iterator.prototype, next() { throw new Test262Error(); }, get return() { + returnMethodCalled = true; throw new TypeError(); } }; @@ -20,3 +23,5 @@ let iterator = { assert.throws(Test262Error, function() { iterator.includes(0); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method throws"); diff --git a/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-done.js index c9da2ef6cb0..c79d49d91dc 100644 --- a/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-done.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator().map(() => 0); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-value.js index a34de32a031..c1b33d9f60b 100644 --- a/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-value.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator().map(() => 0); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/reduce/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/reduce/next-method-returns-throwing-done.js index c855c5bc00b..f6aeb1bc323 100644 --- a/test/built-ins/Iterator/prototype/reduce/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/reduce/next-method-returns-throwing-done.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.reduce(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/reduce/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/reduce/next-method-returns-throwing-value.js index 900958e0a55..b12af0680ec 100644 --- a/test/built-ins/Iterator/prototype/reduce/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/reduce/next-method-returns-throwing-value.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.reduce(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/some/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/some/next-method-returns-throwing-done.js index a87f60929d2..7f380cdcc01 100644 --- a/test/built-ins/Iterator/prototype/some/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/some/next-method-returns-throwing-done.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.some(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/some/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/some/next-method-returns-throwing-value.js index 6293c1d5be1..e90a4bbaf83 100644 --- a/test/built-ins/Iterator/prototype/some/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/some/next-method-returns-throwing-value.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.some(() => {}); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/take/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/take/next-method-returns-throwing-done.js index aedc2236674..14f0c072215 100644 --- a/test/built-ins/Iterator/prototype/take/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/take/next-method-returns-throwing-done.js @@ -12,6 +12,9 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; + class ReturnCalledError extends Error {} class DoneGetterError extends Error {} @@ -25,6 +28,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new ReturnCalledError(); } } @@ -35,8 +39,13 @@ assert.throws(ReturnCalledError, function () { iterator.next(); }); +assert.sameValue(returnMethodCalled, true, "take(0) closes the underlying iterator"); + +returnMethodCalled = false; iterator = new ThrowingIterator().take(1); assert.throws(DoneGetterError, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/take/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/take/next-method-returns-throwing-value.js index 60d9509a3dd..88a19163bc0 100644 --- a/test/built-ins/Iterator/prototype/take/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/take/next-method-returns-throwing-value.js @@ -12,6 +12,9 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; + class ReturnCalledError extends Error {} class ValueGetterError extends Error {} @@ -25,6 +28,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new ReturnCalledError(); } } @@ -35,8 +39,13 @@ assert.throws(ReturnCalledError, function () { iterator.next(); }); +assert.sameValue(returnMethodCalled, true, "take(0) closes the underlying iterator"); + +returnMethodCalled = false; iterator = new ThrowingIterator().take(1); assert.throws(ValueGetterError, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/toArray/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/toArray/next-method-returns-throwing-done.js index e725cf4049d..cb80dc9903c 100644 --- a/test/built-ins/Iterator/prototype/toArray/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/toArray/next-method-returns-throwing-done.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.toArray(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/toArray/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/toArray/next-method-returns-throwing-value.js index 084158ddbda..5d9ed0b4a91 100644 --- a/test/built-ins/Iterator/prototype/toArray/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/toArray/next-method-returns-throwing-value.js @@ -10,6 +10,8 @@ info: | features: [iterator-helpers] flags: [] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -20,6 +22,7 @@ class ThrowingIterator extends Iterator { }; } return() { + returnMethodCalled = true; throw new Error(); } } @@ -29,3 +32,5 @@ let iterator = new ThrowingIterator(); assert.throws(Test262Error, function () { iterator.toArray(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/windows/get-next-method-throws.js b/test/built-ins/Iterator/prototype/windows/get-next-method-throws.js index 80579e064e8..766935f79e4 100644 --- a/test/built-ins/Iterator/prototype/windows/get-next-method-throws.js +++ b/test/built-ins/Iterator/prototype/windows/get-next-method-throws.js @@ -11,11 +11,14 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { get next() { throw new Test262Error(); } get return() { + returnMethodCalled = true; throw new TypeError(); } } @@ -25,3 +28,5 @@ let iter = new ThrowingIterator(); assert.throws(Test262Error, function () { iter.windows(1); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when getting its next method throws"); diff --git a/test/built-ins/Iterator/prototype/windows/next-method-returns-non-object.js b/test/built-ins/Iterator/prototype/windows/next-method-returns-non-object.js index df1f9b8ab89..7d57364a2f6 100644 --- a/test/built-ins/Iterator/prototype/windows/next-method-returns-non-object.js +++ b/test/built-ins/Iterator/prototype/windows/next-method-returns-non-object.js @@ -9,11 +9,14 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class NonObjectIterator extends Iterator { next() { return null; } get return() { + returnMethodCalled = true; throw new Test262Error(); } } @@ -23,3 +26,5 @@ let iterator = new NonObjectIterator().windows(1); assert.throws(TypeError, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns a non-object"); diff --git a/test/built-ins/Iterator/prototype/windows/next-method-returns-throwing-done.js b/test/built-ins/Iterator/prototype/windows/next-method-returns-throwing-done.js index 33c285aef65..26f74c89646 100644 --- a/test/built-ins/Iterator/prototype/windows/next-method-returns-throwing-done.js +++ b/test/built-ins/Iterator/prototype/windows/next-method-returns-throwing-done.js @@ -9,6 +9,8 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -19,6 +21,7 @@ class ThrowingIterator extends Iterator { }; } get return() { + returnMethodCalled = true; throw new Test262Error(); } } @@ -28,3 +31,5 @@ let iterator = new ThrowingIterator().windows(1); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/windows/next-method-returns-throwing-value.js b/test/built-ins/Iterator/prototype/windows/next-method-returns-throwing-value.js index 62ed5d1ed25..5449e8e5c11 100644 --- a/test/built-ins/Iterator/prototype/windows/next-method-returns-throwing-value.js +++ b/test/built-ins/Iterator/prototype/windows/next-method-returns-throwing-value.js @@ -9,6 +9,8 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { return { @@ -19,6 +21,7 @@ class ThrowingIterator extends Iterator { }; } get return() { + returnMethodCalled = true; throw new TypeError(); } } @@ -28,3 +31,5 @@ let iterator = new ThrowingIterator().windows(1); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method returns an object with throwy getters"); diff --git a/test/built-ins/Iterator/prototype/windows/next-method-throws.js b/test/built-ins/Iterator/prototype/windows/next-method-throws.js index 4e338e39a47..5de7fd16e16 100644 --- a/test/built-ins/Iterator/prototype/windows/next-method-throws.js +++ b/test/built-ins/Iterator/prototype/windows/next-method-throws.js @@ -9,11 +9,14 @@ info: | features: [iterator-chunking, class] ---*/ + +var returnMethodCalled = false; class ThrowingIterator extends Iterator { next() { throw new Test262Error(); } get return() { + returnMethodCalled = true; throw new TypeError(); } } @@ -23,3 +26,5 @@ let iterator = new ThrowingIterator().windows(1); assert.throws(Test262Error, function () { iterator.next(); }); + +assert.sameValue(returnMethodCalled, false, "an iterator's return method is not called when its next method throws");