From 96a145cf10148afa36b23f8bdf1dfa0b156c0939 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 14 Nov 2024 15:00:05 -0800 Subject: [PATCH] [Fix] `Iterator.concat`: fix `.return` behavior Tests from https://github.com/tc39/test262/pull/4326 --- test/Iterator.concat.js | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/test/Iterator.concat.js b/test/Iterator.concat.js index 984a560..02bbc39 100644 --- a/test/Iterator.concat.js +++ b/test/Iterator.concat.js @@ -406,6 +406,44 @@ module.exports = { s2t.end(); }); + st.test('test262: test/built-ins/Iterator/concat/return-is-forwarded', function (s2t) { + var returnCount = 0; + + var testIterator1 = { + next: function () { + return { + done: false, + value: 1 + }; + }, + 'return': function () { + returnCount += 1; + return {}; + } + }; + + var iterable = {}; + iterable[Symbol.iterator] = function () { + return testIterator1; + }; + + var iterator = concat(iterable); + s2t.equal(returnCount, 0); + + var iterResult = iterator.next(); + s2t.equal(returnCount, 0); + s2t.equal(iterResult.done, false); + s2t.equal(iterResult.value, 1); + + iterator['return'](); + s2t.equal(returnCount, 1); + + iterator['return'](); + s2t.equal(returnCount, 1); + + s2t.end(); + }); + st.test('test262: test/built-ins/Iterator/concat/return-is-not-forwarded-after-exhaustion', function (s2t) { var testIterator1 = { next: function () { @@ -534,6 +572,40 @@ module.exports = { s2t.end(); }); + st.test('test262: test/built-ins/Iterator/concat/throws-typeerror-when-generator-is-running-return', function (s2t) { + var enterCount = 0; + + var iterator; + + var testIterator1 = { + next: function () { + return { done: false }; + }, + 'return': function () { + enterCount += 1; + iterator['return'](); + return { done: false }; + } + }; + + var iterable = {}; + iterable[Symbol.iterator] = function () { + return testIterator1; + }; + + iterator = concat(iterable); + + iterator.next(); + + s2t.equal(enterCount, 0); + + s2t['throws'](function () { iterator['return'](); }, TypeError); + + s2t.equal(enterCount, 1); + + s2t.end(); + }); + st.end(); }); },