| 1076 | } |
| 1077 | |
| 1078 | function copyElement(source, maxDepth) { |
| 1079 | // Simple values |
| 1080 | if (!isObject(source)) { |
| 1081 | return source; |
| 1082 | } |
| 1083 | |
| 1084 | // Already copied values |
| 1085 | var index = stackSource.indexOf(source); |
| 1086 | if (index !== -1) { |
| 1087 | return stackDest[index]; |
| 1088 | } |
| 1089 | |
| 1090 | if (isWindow(source) || isScope(source)) { |
| 1091 | throw ngMinErr('cpws', |
| 1092 | 'Can\'t copy! Making copies of Window or Scope instances is not supported.'); |
| 1093 | } |
| 1094 | |
| 1095 | var needsRecurse = false; |
| 1096 | var destination = copyType(source); |
| 1097 | |
| 1098 | if (destination === undefined) { |
| 1099 | destination = isArray(source) ? [] : Object.create(getPrototypeOf(source)); |
| 1100 | needsRecurse = true; |
| 1101 | } |
| 1102 | |
| 1103 | stackSource.push(source); |
| 1104 | stackDest.push(destination); |
| 1105 | |
| 1106 | return needsRecurse |
| 1107 | ? copyRecurse(source, destination, maxDepth) |
| 1108 | : destination; |
| 1109 | } |
| 1110 | |
| 1111 | function copyType(source) { |
| 1112 | switch (toString.call(source)) { |