@@ -855,7 +855,7 @@ var ES6Map = isFunction(window.Map) && toString.call(window.Map.prototype) === '
855
855
</example>
856
856
*/
857
857
function copy ( source , destination ) {
858
- var stack = new ES6Map ( ) ;
858
+ var stack ;
859
859
860
860
if ( destination ) {
861
861
if ( isTypedArray ( destination ) || isArrayBuffer ( destination ) ) {
@@ -876,13 +876,14 @@ function copy(source, destination) {
876
876
} ) ;
877
877
}
878
878
879
- stack . set ( source , destination ) ;
880
879
return copyRecurse ( source , destination ) ;
881
880
}
882
881
883
882
return copyElement ( source ) ;
884
883
885
884
function copyRecurse ( source , destination ) {
885
+ ( stack || ( stack = new ES6Map ( ) ) ) . set ( source , destination ) ;
886
+
886
887
var h = destination . $$hashKey ;
887
888
var key ;
888
889
if ( isArray ( source ) ) {
@@ -920,7 +921,7 @@ function copy(source, destination) {
920
921
}
921
922
922
923
// Already copied values
923
- var existingCopy = stack . get ( source ) ;
924
+ var existingCopy = stack && stack . get ( source ) ;
924
925
if ( existingCopy ) {
925
926
return existingCopy ;
926
927
}
@@ -930,19 +931,15 @@ function copy(source, destination) {
930
931
'Can\'t copy! Making copies of Window or Scope instances is not supported.' ) ;
931
932
}
932
933
933
- var needsRecurse = false ;
934
934
var destination = copyType ( source ) ;
935
935
936
936
if ( destination === undefined ) {
937
- destination = isArray ( source ) ? [ ] : Object . create ( getPrototypeOf ( source ) ) ;
938
- needsRecurse = true ;
937
+ destination = copyRecurse ( source , isArray ( source ) ? [ ] : Object . create ( getPrototypeOf ( source ) ) ) ;
938
+ } else if ( stack ) {
939
+ stack . set ( source , destination ) ;
939
940
}
940
941
941
- stack . set ( source , destination ) ;
942
-
943
- return needsRecurse
944
- ? copyRecurse ( source , destination )
945
- : destination ;
942
+ return destination ;
946
943
}
947
944
948
945
function copyType ( source ) {
0 commit comments