55
66const regexFlagsSupported = / a / g. flags !== undefined ;
77
8+ const arrayFrom = require ( 'array-from' ) ;
9+
810const objectIs = Object . is ? Object . is : require ( 'object-is' ) ;
911const objectGetOwnPropertySymbols = Object . getOwnPropertySymbols ? Object . getOwnPropertySymbols : ( ) => [ ] ;
1012
@@ -344,7 +346,9 @@ function keyCheck(val1, val2, strict, memos, iterationType, aKeys) {
344346
345347function setHasEqualElement ( set , val1 , strict , memo ) {
346348 // Go looking.
347- for ( const val2 of set ) {
349+ const setValues = arrayFrom ( set . values ( ) ) ;
350+ for ( let i = 0 ; i < setValues . length ; i ++ ) {
351+ const val2 = setValues [ i ] ;
348352 if ( innerDeepEqual ( val1 , val2 , strict , memo ) ) {
349353 // Remove the matching element to make sure we do not check that again.
350354 set . delete ( val2 ) ;
@@ -405,7 +409,9 @@ function setEquiv(a, b, strict, memo) {
405409 // This is a lazily initiated Set of entries which have to be compared
406410 // pairwise.
407411 let set = null ;
408- for ( const val of a ) {
412+ const aValues = arrayFrom ( a . values ( ) ) ;
413+ for ( let i = 0 ; i < aValues . length ; i ++ ) {
414+ const val = aValues [ i ] ;
409415 // Note: Checking for the objects first improves the performance for object
410416 // heavy sets but it is a minor slow down for primitives. As they are fast
411417 // to check this improves the worst case scenario instead.
@@ -435,7 +441,9 @@ function setEquiv(a, b, strict, memo) {
435441 }
436442
437443 if ( set !== null ) {
438- for ( const val of b ) {
444+ const bValues = arrayFrom ( b . values ( ) ) ;
445+ for ( let i = 0 ; i < bValues . length ; i ++ ) {
446+ const val = bValues [ i ] ;
439447 // We have to check if a primitive value is already
440448 // matching and only if it's not, go hunting for it.
441449 if ( typeof val === 'object' && val !== null ) {
@@ -457,7 +465,9 @@ function mapHasEqualEntry(set, map, key1, item1, strict, memo) {
457465 // To be able to handle cases like:
458466 // Map([[{}, 'a'], [{}, 'b']]) vs Map([[{}, 'b'], [{}, 'a']])
459467 // ... we need to consider *all* matching keys, not just the first we find.
460- for ( const key2 of set ) {
468+ const setValues = arrayFrom ( set . values ( ) ) ;
469+ for ( let i = 0 ; i < setValues . length ; i ++ ) {
470+ const key2 = setValues [ i ] ;
461471 if ( innerDeepEqual ( key1 , key2 , strict , memo ) &&
462472 innerDeepEqual ( item1 , map . get ( key2 ) , strict , memo ) ) {
463473 set . delete ( key2 ) ;
@@ -471,7 +481,9 @@ function mapHasEqualEntry(set, map, key1, item1, strict, memo) {
471481function mapEquiv ( a , b , strict , memo ) {
472482 let set = null ;
473483
474- for ( const [ key , item1 ] of a ) {
484+ const aEntries = arrayFrom ( a . entries ( ) ) ;
485+ for ( let i = 0 ; i < aEntries . length ; i ++ ) {
486+ const [ key , item1 ] = aEntries [ i ] ;
475487 if ( typeof key === 'object' && key !== null ) {
476488 if ( set === null ) {
477489 set = new Set ( ) ;
@@ -498,7 +510,9 @@ function mapEquiv(a, b, strict, memo) {
498510 }
499511
500512 if ( set !== null ) {
501- for ( const [ key , item ] of b ) {
513+ const bEntries = arrayFrom ( b . entries ( ) ) ;
514+ for ( let i = 0 ; i < bEntries . length ; i ++ ) {
515+ const [ key , item ] = bEntries [ i ] ;
502516 if ( typeof key === 'object' && key !== null ) {
503517 if ( ! mapHasEqualEntry ( set , a , key , item , strict , memo ) )
504518 return false ;
0 commit comments