| 1034 | } |
| 1035 | |
| 1036 | function copyElement(source, maxDepth) { |
| 1037 | // Simple values |
| 1038 | if (!isObject(source)) { |
| 1039 | return source; |
| 1040 | } |
| 1041 | |
| 1042 | // Already copied values |
| 1043 | var index = stackSource.indexOf(source); |
| 1044 | if (index !== -1) { |
| 1045 | return stackDest[index]; |
| 1046 | } |
| 1047 | |
| 1048 | if (isWindow(source) || isScope(source)) { |
| 1049 | throw ngMinErr('cpws', |
| 1050 | 'Can\'t copy! Making copies of Window or Scope instances is not supported.'); |
| 1051 | } |
| 1052 | |
| 1053 | var needsRecurse = false; |
| 1054 | var destination = copyType(source); |
| 1055 | |
| 1056 | if (destination === undefined) { |
| 1057 | destination = isArray(source) ? [] : Object.create(getPrototypeOf(source)); |
| 1058 | needsRecurse = true; |
| 1059 | } |
| 1060 | |
| 1061 | stackSource.push(source); |
| 1062 | stackDest.push(destination); |
| 1063 | |
| 1064 | return needsRecurse |
| 1065 | ? copyRecurse(source, destination, maxDepth) |
| 1066 | : destination; |
| 1067 | } |
| 1068 | |
| 1069 | function copyType(source) { |
| 1070 | switch (toString.call(source)) { |