10
10
splice,
11
11
push,
12
12
toString,
13
+ minErrConfig,
14
+ errorHandlingConfig,
15
+ isValidObjectMaxDepth,
13
16
ngMinErr,
14
17
angularModule,
15
18
uid,
@@ -125,6 +128,50 @@ var VALIDITY_STATE_PROPERTY = 'validity';
125
128
126
129
var hasOwnProperty = Object . prototype . hasOwnProperty ;
127
130
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
+
128
175
/**
129
176
* @ngdoc function
130
177
* @name angular.lowercase
@@ -847,9 +894,10 @@ function arrayRemove(array, value) {
847
894
</file>
848
895
</example>
849
896
*/
850
- function copy ( source , destination ) {
897
+ function copy ( source , destination , maxDepth ) {
851
898
var stackSource = [ ] ;
852
899
var stackDest = [ ] ;
900
+ maxDepth = isValidObjectMaxDepth ( maxDepth ) ? maxDepth : NaN ;
853
901
854
902
if ( destination ) {
855
903
if ( isTypedArray ( destination ) || isArrayBuffer ( destination ) ) {
@@ -872,43 +920,47 @@ function copy(source, destination) {
872
920
873
921
stackSource . push ( source ) ;
874
922
stackDest . push ( destination ) ;
875
- return copyRecurse ( source , destination ) ;
923
+ return copyRecurse ( source , destination , maxDepth ) ;
876
924
}
877
925
878
- return copyElement ( source ) ;
926
+ return copyElement ( source , maxDepth ) ;
879
927
880
- function copyRecurse ( source , destination ) {
928
+ function copyRecurse ( source , destination , maxDepth ) {
929
+ maxDepth -- ;
930
+ if ( maxDepth < 0 ) {
931
+ return '...' ;
932
+ }
881
933
var h = destination . $$hashKey ;
882
934
var key ;
883
935
if ( isArray ( source ) ) {
884
936
for ( var i = 0 , ii = source . length ; i < ii ; i ++ ) {
885
- destination . push ( copyElement ( source [ i ] ) ) ;
937
+ destination . push ( copyElement ( source [ i ] , maxDepth ) ) ;
886
938
}
887
939
} else if ( isBlankObject ( source ) ) {
888
940
// createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
889
941
for ( key in source ) {
890
- destination [ key ] = copyElement ( source [ key ] ) ;
942
+ destination [ key ] = copyElement ( source [ key ] , maxDepth ) ;
891
943
}
892
944
} else if ( source && typeof source . hasOwnProperty === 'function' ) {
893
945
// Slow path, which must rely on hasOwnProperty
894
946
for ( key in source ) {
895
947
if ( source . hasOwnProperty ( key ) ) {
896
- destination [ key ] = copyElement ( source [ key ] ) ;
948
+ destination [ key ] = copyElement ( source [ key ] , maxDepth ) ;
897
949
}
898
950
}
899
951
} else {
900
952
// Slowest path --- hasOwnProperty can't be called as a method
901
953
for ( key in source ) {
902
954
if ( hasOwnProperty . call ( source , key ) ) {
903
- destination [ key ] = copyElement ( source [ key ] ) ;
955
+ destination [ key ] = copyElement ( source [ key ] , maxDepth ) ;
904
956
}
905
957
}
906
958
}
907
959
setHashKey ( destination , h ) ;
908
960
return destination ;
909
961
}
910
962
911
- function copyElement ( source ) {
963
+ function copyElement ( source , maxDepth ) {
912
964
// Simple values
913
965
if ( ! isObject ( source ) ) {
914
966
return source ;
@@ -937,7 +989,7 @@ function copy(source, destination) {
937
989
stackDest . push ( destination ) ;
938
990
939
991
return needsRecurse
940
- ? copyRecurse ( source , destination )
992
+ ? copyRecurse ( source , destination , maxDepth )
941
993
: destination ;
942
994
}
943
995
0 commit comments