File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,16 @@ describe('inspect', () => {
96
96
expect ( inspect ( object ) ) . to . equal ( '<custom inspect>' ) ;
97
97
} ) ;
98
98
99
+ it ( 'custom inspect that return `this` should work' , ( ) => {
100
+ const object = {
101
+ inspect ( ) {
102
+ return this ;
103
+ } ,
104
+ } ;
105
+
106
+ expect ( inspect ( object ) ) . to . equal ( '{ inspect: [function inspect] }' ) ;
107
+ } ) ;
108
+
99
109
it ( 'custom symbol inspect is take precedence' , ( ) => {
100
110
invariant ( nodejsCustomInspectSymbol ) ;
101
111
Original file line number Diff line number Diff line change @@ -32,9 +32,13 @@ function formatValue(value, recurseTimes) {
32
32
if ( customInspectFn ) {
33
33
// $FlowFixMe(>=0.90.0)
34
34
const customValue = customInspectFn . call ( value ) ;
35
- return typeof customValue === 'string'
36
- ? customValue
37
- : formatValue ( customValue , recurseTimes ) ;
35
+
36
+ // check for infinite recursion
37
+ if ( customValue !== value ) {
38
+ return typeof customValue === 'string'
39
+ ? customValue
40
+ : formatValue ( customValue , recurseTimes ) ;
41
+ }
38
42
} else if ( Array . isArray ( value ) ) {
39
43
return formatArray ( value , recurseTimes ) ;
40
44
}
You can’t perform that action at this time.
0 commit comments