MCPcopy
hub / github.com/angular-ui/ui-grid / copy

Function copy

lib/test/angular/1.8.0/angular.js:1010–1153  ·  view source on GitHub ↗

* @ngdoc function * @name angular.copy * @module ng * @kind function * * @description * Creates a deep copy of `source`, which should be an object or an array. This functions is used * internally, mostly in the change-detection code. It is not intended as an all-purpose copy * function, and

(source, destination, maxDepth)

Source from the content-addressed store, hash-verified

1008 </example>
1009 */
1010function copy(source, destination, maxDepth) {
1011 var stackSource = [];
1012 var stackDest = [];
1013 maxDepth = isValidObjectMaxDepth(maxDepth) ? maxDepth : NaN;
1014
1015 if (destination) {
1016 if (isTypedArray(destination) || isArrayBuffer(destination)) {
1017 throw ngMinErr('cpta', 'Can\'t copy! TypedArray destination cannot be mutated.');
1018 }
1019 if (source === destination) {
1020 throw ngMinErr('cpi', 'Can\'t copy! Source and destination are identical.');
1021 }
1022
1023 // Empty the destination object
1024 if (isArray(destination)) {
1025 destination.length = 0;
1026 } else {
1027 forEach(destination, function(value, key) {
1028 if (key !== '$$hashKey') {
1029 delete destination[key];
1030 }
1031 });
1032 }
1033
1034 stackSource.push(source);
1035 stackDest.push(destination);
1036 return copyRecurse(source, destination, maxDepth);
1037 }
1038
1039 return copyElement(source, maxDepth);
1040
1041 function copyRecurse(source, destination, maxDepth) {
1042 maxDepth--;
1043 if (maxDepth < 0) {
1044 return '...';
1045 }
1046 var h = destination.$$hashKey;
1047 var key;
1048 if (isArray(source)) {
1049 for (var i = 0, ii = source.length; i < ii; i++) {
1050 destination.push(copyElement(source[i], maxDepth));
1051 }
1052 } else if (isBlankObject(source)) {
1053 // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
1054 for (key in source) {
1055 destination[key] = copyElement(source[key], maxDepth);
1056 }
1057 } else if (source && typeof source.hasOwnProperty === 'function') {
1058 // Slow path, which must rely on hasOwnProperty
1059 for (key in source) {
1060 if (source.hasOwnProperty(key)) {
1061 destination[key] = copyElement(source[key], maxDepth);
1062 }
1063 }
1064 } else {
1065 // Slowest path --- hasOwnProperty can't be called as a method
1066 for (key in source) {
1067 if (hasOwnProperty.call(source, key)) {

Callers 8

$CoreAnimateCssProviderFunction · 0.70
angular.jsFile · 0.70
$ParseProviderFunction · 0.70
$RootScopeProviderFunction · 0.70
parseOptionsExpressionFunction · 0.70
handleResponseFunction · 0.70
angular-animate.jsFile · 0.70
queueAnimationFunction · 0.70

Calls 7

isValidObjectMaxDepthFunction · 0.70
isTypedArrayFunction · 0.70
isArrayBufferFunction · 0.70
isArrayFunction · 0.70
forEachFunction · 0.70
copyRecurseFunction · 0.70
copyElementFunction · 0.70

Tested by

no test coverage detected