| 946 | } |
| 947 | |
| 948 | function copyElement(source) { |
| 949 | // Simple values |
| 950 | if (!isObject(source)) { |
| 951 | return source; |
| 952 | } |
| 953 | |
| 954 | // Already copied values |
| 955 | var index = stackSource.indexOf(source); |
| 956 | if (index !== -1) { |
| 957 | return stackDest[index]; |
| 958 | } |
| 959 | |
| 960 | if (isWindow(source) || isScope(source)) { |
| 961 | throw ngMinErr('cpws', |
| 962 | 'Can\'t copy! Making copies of Window or Scope instances is not supported.'); |
| 963 | } |
| 964 | |
| 965 | var needsRecurse = false; |
| 966 | var destination = copyType(source); |
| 967 | |
| 968 | if (destination === undefined) { |
| 969 | destination = isArray(source) ? [] : Object.create(getPrototypeOf(source)); |
| 970 | needsRecurse = true; |
| 971 | } |
| 972 | |
| 973 | stackSource.push(source); |
| 974 | stackDest.push(destination); |
| 975 | |
| 976 | return needsRecurse |
| 977 | ? copyRecurse(source, destination) |
| 978 | : destination; |
| 979 | } |
| 980 | |
| 981 | function copyType(source) { |
| 982 | switch (toString.call(source)) { |