1010 splice,
1111 push,
1212 toString,
13+ minErrConfig,
14+ errorHandlingConfig,
15+ isValidObjectMaxDepth,
1316 ngMinErr,
1417 angularModule,
1518 uid,
@@ -125,6 +128,50 @@ var VALIDITY_STATE_PROPERTY = 'validity';
125128
126129var hasOwnProperty = Object . prototype . hasOwnProperty ;
127130
131+ var minErrConfig = {
132+ objectMaxDepth : 5
133+ } ;
134+
135+ /**
136+ * @ngdoc function
137+ * @name angular.errorHandlingConfig
138+ * @module ng
139+ * @kind function
140+ *
141+ * @description
142+ * Configure several aspects of error handling in AngularJS if used as a setter or return the
143+ * current configuration if used as a getter. The following options are supported:
144+ *
145+ * - **objectMaxDepth**: The maximum depth to which objects are traversed when stringified for error messages.
146+ *
147+ * Omitted or undefined options will leave the corresponding configuration values unchanged.
148+ *
149+ * @param {Object= } config - The configuration object. May only contain the options that need to be
150+ * updated. Supported keys:
151+ *
152+ * * `objectMaxDepth` **{Number}** - The max depth for stringifying objects. Setting to a
153+ * non-positive or non-numeric value, removes the max depth limit.
154+ * Default: 5
155+ */
156+ function errorHandlingConfig ( config ) {
157+ if ( isObject ( config ) ) {
158+ if ( isDefined ( config . objectMaxDepth ) ) {
159+ minErrConfig . objectMaxDepth = isValidObjectMaxDepth ( config . objectMaxDepth ) ? config . objectMaxDepth : NaN ;
160+ }
161+ } else {
162+ return minErrConfig ;
163+ }
164+ }
165+
166+ /**
167+ * @private
168+ * @param {Number } maxDepth
169+ * @return {boolean }
170+ */
171+ function isValidObjectMaxDepth ( maxDepth ) {
172+ return isNumber ( maxDepth ) && maxDepth > 0 ;
173+ }
174+
128175/**
129176 * @ngdoc function
130177 * @name angular.lowercase
@@ -847,9 +894,10 @@ function arrayRemove(array, value) {
847894 </file>
848895 </example>
849896 */
850- function copy ( source , destination ) {
897+ function copy ( source , destination , maxDepth ) {
851898 var stackSource = [ ] ;
852899 var stackDest = [ ] ;
900+ maxDepth = isValidObjectMaxDepth ( maxDepth ) ? maxDepth : NaN ;
853901
854902 if ( destination ) {
855903 if ( isTypedArray ( destination ) || isArrayBuffer ( destination ) ) {
@@ -872,43 +920,47 @@ function copy(source, destination) {
872920
873921 stackSource . push ( source ) ;
874922 stackDest . push ( destination ) ;
875- return copyRecurse ( source , destination ) ;
923+ return copyRecurse ( source , destination , maxDepth ) ;
876924 }
877925
878- return copyElement ( source ) ;
926+ return copyElement ( source , maxDepth ) ;
879927
880- function copyRecurse ( source , destination ) {
928+ function copyRecurse ( source , destination , maxDepth ) {
929+ maxDepth -- ;
930+ if ( maxDepth < 0 ) {
931+ return '...' ;
932+ }
881933 var h = destination . $$hashKey ;
882934 var key ;
883935 if ( isArray ( source ) ) {
884936 for ( var i = 0 , ii = source . length ; i < ii ; i ++ ) {
885- destination . push ( copyElement ( source [ i ] ) ) ;
937+ destination . push ( copyElement ( source [ i ] , maxDepth ) ) ;
886938 }
887939 } else if ( isBlankObject ( source ) ) {
888940 // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
889941 for ( key in source ) {
890- destination [ key ] = copyElement ( source [ key ] ) ;
942+ destination [ key ] = copyElement ( source [ key ] , maxDepth ) ;
891943 }
892944 } else if ( source && typeof source . hasOwnProperty === 'function' ) {
893945 // Slow path, which must rely on hasOwnProperty
894946 for ( key in source ) {
895947 if ( source . hasOwnProperty ( key ) ) {
896- destination [ key ] = copyElement ( source [ key ] ) ;
948+ destination [ key ] = copyElement ( source [ key ] , maxDepth ) ;
897949 }
898950 }
899951 } else {
900952 // Slowest path --- hasOwnProperty can't be called as a method
901953 for ( key in source ) {
902954 if ( hasOwnProperty . call ( source , key ) ) {
903- destination [ key ] = copyElement ( source [ key ] ) ;
955+ destination [ key ] = copyElement ( source [ key ] , maxDepth ) ;
904956 }
905957 }
906958 }
907959 setHashKey ( destination , h ) ;
908960 return destination ;
909961 }
910962
911- function copyElement ( source ) {
963+ function copyElement ( source , maxDepth ) {
912964 // Simple values
913965 if ( ! isObject ( source ) ) {
914966 return source ;
@@ -937,7 +989,7 @@ function copy(source, destination) {
937989 stackDest . push ( destination ) ;
938990
939991 return needsRecurse
940- ? copyRecurse ( source , destination )
992+ ? copyRecurse ( source , destination , maxDepth )
941993 : destination ;
942994 }
943995
0 commit comments