| 918 | } |
| 919 | |
| 920 | function copyElement(source) { |
| 921 | // Simple values |
| 922 | if (!isObject(source)) { |
| 923 | return source; |
| 924 | } |
| 925 | |
| 926 | // Already copied values |
| 927 | var index = stackSource.indexOf(source); |
| 928 | if (index !== -1) { |
| 929 | return stackDest[index]; |
| 930 | } |
| 931 | |
| 932 | if (isWindow(source) || isScope(source)) { |
| 933 | throw ngMinErr('cpws', |
| 934 | "Can't copy! Making copies of Window or Scope instances is not supported."); |
| 935 | } |
| 936 | |
| 937 | var needsRecurse = false; |
| 938 | var destination = copyType(source); |
| 939 | |
| 940 | if (destination === undefined) { |
| 941 | destination = isArray(source) ? [] : Object.create(getPrototypeOf(source)); |
| 942 | needsRecurse = true; |
| 943 | } |
| 944 | |
| 945 | stackSource.push(source); |
| 946 | stackDest.push(destination); |
| 947 | |
| 948 | return needsRecurse |
| 949 | ? copyRecurse(source, destination) |
| 950 | : destination; |
| 951 | } |
| 952 | |
| 953 | function copyType(source) { |
| 954 | switch (toString.call(source)) { |