File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -316,7 +316,7 @@ export function isSupported(): boolean {
316316 'every' in IteratorPrototype &&
317317 'find' in IteratorPrototype &&
318318 IteratorConstructor !== undefined &&
319- typeof IteratorConstructor === 'object' &&
319+ ( typeof IteratorConstructor === 'object' || typeof IteratorConstructor === 'function' ) &&
320320 IteratorConstructor !== null &&
321321 'from' in IteratorConstructor
322322 )
Original file line number Diff line number Diff line change @@ -11,6 +11,40 @@ describe('Iterator helpers', () => {
1111 expect ( isPolyfilled ( ) ) . to . equal ( false )
1212 } )
1313
14+ it ( 'isSupported returns true when Iterator is a function (native support)' , ( ) => {
15+ // Native Iterator in Chromium is a function, not an object.
16+ // Simulate this by temporarily replacing globalThis.Iterator with a function.
17+ const original = globalThis . Iterator
18+ try {
19+ apply ( ) // ensure polyfill is applied first so prototype methods exist
20+ const proto = Object . getPrototypeOf ( Object . getPrototypeOf ( [ ] [ Symbol . iterator ] ( ) ) )
21+ // Create a function-based Iterator with a `from` method, like native Chromium
22+ globalThis . Iterator = function Iterator ( ) { }
23+ globalThis . Iterator . from = function from ( ) { }
24+ // Assign all required methods to the iterator prototype
25+ for ( const method of [
26+ 'map' ,
27+ 'filter' ,
28+ 'take' ,
29+ 'drop' ,
30+ 'flatMap' ,
31+ 'reduce' ,
32+ 'toArray' ,
33+ 'forEach' ,
34+ 'some' ,
35+ 'every' ,
36+ 'find' ,
37+ ] ) {
38+ if ( ! ( method in proto ) ) {
39+ proto [ method ] = function ( ) { }
40+ }
41+ }
42+ expect ( isSupported ( ) ) . to . equal ( true )
43+ } finally {
44+ globalThis . Iterator = original
45+ }
46+ } )
47+
1448 // Helper to create an iterator from an array
1549 function * arrayIterator ( arr ) {
1650 for ( const item of arr ) {
You can’t perform that action at this time.
0 commit comments