fix: fully encapsulate native generator

This commit is contained in:
TopchetoEU 2023-08-26 00:44:28 +03:00
parent 7a745faacf
commit 12093eda14
No known key found for this signature in database
GPG Key ID: 24E57B2E9C61AD19

View File

@ -166,8 +166,16 @@ setProps(Function, {
},
generator(func) {
if (typeof func !== 'function') throw new TypeError('Expected func to be function.');
return Object.assign(internals.makeGenerator(func), {
[Symbol.iterator]() { return this; }
});
const gen = internals.makeGenerator(func);
return (...args: any[]) => {
const it = gen(args);
return {
next: it.next,
return: it.return,
throw: it.throw,
[Symbol.iterator]() { return this; }
}
}
}
})