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