@@ -849,7 +849,7 @@ var ES6Map = isFunction(window.Map) && toString.call(window.Map.prototype) === '
849
849
</example>
850
850
*/
851
851
function copy ( source , destination ) {
852
- var stack = new ES6Map ( ) ;
852
+ var stack ;
853
853
854
854
if ( destination ) {
855
855
if ( isTypedArray ( destination ) || isArrayBuffer ( destination ) ) {
@@ -870,13 +870,14 @@ function copy(source, destination) {
870
870
} ) ;
871
871
}
872
872
873
- stack . set ( source , destination ) ;
874
873
return copyRecurse ( source , destination ) ;
875
874
}
876
875
877
876
return copyElement ( source ) ;
878
877
879
878
function copyRecurse ( source , destination ) {
879
+ ( stack || ( stack = new ES6Map ( ) ) ) . set ( source , destination ) ;
880
+
880
881
var h = destination . $$hashKey ;
881
882
var key ;
882
883
if ( isArray ( source ) ) {
@@ -914,7 +915,7 @@ function copy(source, destination) {
914
915
}
915
916
916
917
// Already copied values
917
- var existingCopy = stack . get ( source ) ;
918
+ var existingCopy = stack && stack . get ( source ) ;
918
919
if ( existingCopy ) {
919
920
return existingCopy ;
920
921
}
@@ -924,19 +925,15 @@ function copy(source, destination) {
924
925
'Can\'t copy! Making copies of Window or Scope instances is not supported.' ) ;
925
926
}
926
927
927
- var needsRecurse = false ;
928
928
var destination = copyType ( source ) ;
929
929
930
930
if ( destination === undefined ) {
931
- destination = isArray ( source ) ? [ ] : Object . create ( getPrototypeOf ( source ) ) ;
932
- needsRecurse = true ;
931
+ destination = copyRecurse ( source , isArray ( source ) ? [ ] : Object . create ( getPrototypeOf ( source ) ) ) ;
932
+ } else if ( stack ) {
933
+ stack . set ( source , destination ) ;
933
934
}
934
935
935
- stack . set ( source , destination ) ;
936
-
937
- return needsRecurse
938
- ? copyRecurse ( source , destination )
939
- : destination ;
936
+ return destination ;
940
937
}
941
938
942
939
function copyType ( source ) {
0 commit comments