@@ -740,6 +740,49 @@ function arrayRemove(array, value) {
740
740
return index ;
741
741
}
742
742
743
+
744
+ function ES6MapShim ( ) {
745
+ this . _keys = [ ] ;
746
+ this . _values = [ ] ;
747
+ }
748
+ ES6MapShim . prototype = {
749
+ get : function ( key ) {
750
+ var idx = this . _keys . indexOf ( key ) ;
751
+ if ( idx !== - 1 ) {
752
+ return this . _values [ idx ] ;
753
+ }
754
+ } ,
755
+ set : function ( key , value ) {
756
+ var idx = this . _keys . indexOf ( key ) ;
757
+ if ( idx === - 1 ) {
758
+ idx = this . _keys . length ;
759
+ }
760
+ this . _keys [ idx ] = key ;
761
+ this . _values [ idx ] = value ;
762
+ return this ;
763
+ }
764
+ } ;
765
+
766
+ function testES6Map ( Map ) {
767
+ var m , o = { } ;
768
+ return isFunction ( Map ) && ( m = new Map ( ) )
769
+
770
+ // Required functions
771
+ && isFunction ( m . get ) && isFunction ( m . set )
772
+
773
+ // Number keys, must not call toString
774
+ && m . get ( 1 ) === undefined
775
+ && m . set ( 1 , o ) === m
776
+ && m . get ( 1 ) === o
777
+ && m . get ( "1" ) === undefined
778
+
779
+ // Object keys, must use instance as key and not call toString
780
+ && m . set ( o , 2 ) === m && m . get ( o ) === 2
781
+ && m . get ( { } ) === undefined ;
782
+ }
783
+
784
+ var ES6Map = testES6Map ( window . Map ) ? window . Map : ES6MapShim ;
785
+
743
786
/**
744
787
* @ngdoc function
745
788
* @name angular.copy
@@ -799,8 +842,7 @@ function arrayRemove(array, value) {
799
842
</example>
800
843
*/
801
844
function copy ( source , destination ) {
802
- var stackSource = [ ] ;
803
- var stackDest = [ ] ;
845
+ var stack = new ES6Map ( ) ;
804
846
805
847
if ( destination ) {
806
848
if ( isTypedArray ( destination ) ) {
@@ -821,8 +863,7 @@ function copy(source, destination) {
821
863
} ) ;
822
864
}
823
865
824
- stackSource . push ( source ) ;
825
- stackDest . push ( destination ) ;
866
+ stack . set ( source , destination ) ;
826
867
return copyRecurse ( source , destination ) ;
827
868
}
828
869
@@ -866,9 +907,9 @@ function copy(source, destination) {
866
907
}
867
908
868
909
// Already copied values
869
- var index = stackSource . indexOf ( source ) ;
870
- if ( index !== - 1 ) {
871
- return stackDest [ index ] ;
910
+ var existingCopy = stack . get ( source ) ;
911
+ if ( existingCopy ) {
912
+ return existingCopy ;
872
913
}
873
914
874
915
if ( isWindow ( source ) || isScope ( source ) ) {
@@ -896,8 +937,7 @@ function copy(source, destination) {
896
937
needsRecurse = true ;
897
938
}
898
939
899
- stackSource . push ( source ) ;
900
- stackDest . push ( destination ) ;
940
+ stack . set ( source , destination ) ;
901
941
902
942
return needsRecurse
903
943
? copyRecurse ( source , destination )
0 commit comments