From 0feec6795ca0d20189b9a1ef17e1a29ca55972fc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 21:22:12 +0000 Subject: [PATCH 1/2] Initial plan From 35eb2836338b0c222ff703237a9b03192acadc66 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 21:25:17 +0000 Subject: [PATCH 2/2] Fix isSupported() for Iterator helpers to accept native function-based Iterator The typeof check `typeof IteratorConstructor === 'object'` incorrectly returns false for native Iterator in Chromium where Iterator is a function. Changed to also accept 'function' type. Co-authored-by: mattcosta7 <8616962+mattcosta7@users.noreply.github.com> --- src/iterator-helpers.ts | 2 +- test/iterator-helpers.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/iterator-helpers.ts b/src/iterator-helpers.ts index ef54c58..af98ee5 100644 --- a/src/iterator-helpers.ts +++ b/src/iterator-helpers.ts @@ -316,7 +316,7 @@ export function isSupported(): boolean { 'every' in IteratorPrototype && 'find' in IteratorPrototype && IteratorConstructor !== undefined && - typeof IteratorConstructor === 'object' && + (typeof IteratorConstructor === 'object' || typeof IteratorConstructor === 'function') && IteratorConstructor !== null && 'from' in IteratorConstructor ) diff --git a/test/iterator-helpers.js b/test/iterator-helpers.js index 78c7687..1c717e8 100644 --- a/test/iterator-helpers.js +++ b/test/iterator-helpers.js @@ -11,6 +11,40 @@ describe('Iterator helpers', () => { expect(isPolyfilled()).to.equal(false) }) + it('isSupported returns true when Iterator is a function (native support)', () => { + // Native Iterator in Chromium is a function, not an object. + // Simulate this by temporarily replacing globalThis.Iterator with a function. + const original = globalThis.Iterator + try { + apply() // ensure polyfill is applied first so prototype methods exist + const proto = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())) + // Create a function-based Iterator with a `from` method, like native Chromium + globalThis.Iterator = function Iterator() {} + globalThis.Iterator.from = function from() {} + // Assign all required methods to the iterator prototype + for (const method of [ + 'map', + 'filter', + 'take', + 'drop', + 'flatMap', + 'reduce', + 'toArray', + 'forEach', + 'some', + 'every', + 'find', + ]) { + if (!(method in proto)) { + proto[method] = function () {} + } + } + expect(isSupported()).to.equal(true) + } finally { + globalThis.Iterator = original + } + }) + // Helper to create an iterator from an array function* arrayIterator(arr) { for (const item of arr) {