MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / copy

Function copy

lib/test/angular/1.6.7/angular.js:1002–1145  ·  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. * * * If no destination is supplied, a copy of the object or array is created. * * If a destination is provided, all of its element

(source, destination, maxDepth)

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected