Skip to content

Commit

Permalink
[Fix] Iterator.concat: fix .return behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 14, 2024
1 parent 1a70fd3 commit 96a145c
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/Iterator.concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();
});
},
Expand Down

0 comments on commit 96a145c

Please sign in to comment.