@@ -42,7 +42,11 @@ proxyObj = new Proxy(target, handler);
4242util . inspect ( proxyObj , opts ) ;
4343
4444// Make sure inspecting object does not trigger any proxy traps.
45- util . format ( '%s' , proxyObj ) ;
45+ // %i%f%d use Symbol.toPrimitive to convert the value to a string.
46+ // %j uses JSON.stringify, accessing the value's toJSON and toString method.
47+ util . format ( '%s%o%O%c' , proxyObj , proxyObj , proxyObj , proxyObj ) ;
48+ const nestedProxy = new Proxy ( new Proxy ( { } , handler ) , { } ) ;
49+ util . format ( '%s%o%O%c' , nestedProxy , nestedProxy , nestedProxy , nestedProxy ) ;
4650
4751// getProxyDetails is an internal method, not intended for public use.
4852// This is here to test that the internals are working correctly.
@@ -179,3 +183,31 @@ const expected10 = '[Function (anonymous)]';
179183const expected11 = '[Function (anonymous)]' ;
180184assert . strictEqual ( util . inspect ( proxy10 ) , expected10 ) ;
181185assert . strictEqual ( util . inspect ( proxy11 ) , expected11 ) ;
186+
187+ const proxy12 = new Proxy ( [ 1 , 2 , 3 ] , proxy5 ) ;
188+ assert . strictEqual (
189+ util . inspect ( proxy12 , { colors : true , breakLength : 1 } ) ,
190+ '[\n \x1B[33m1\x1B[39m,\n \x1B[33m2\x1B[39m,\n \x1B[33m3\x1B[39m\n]'
191+ ) ;
192+ assert . strictEqual ( util . format ( '%s' , proxy12 ) , '[ 1, 2, 3 ]' ) ;
193+
194+ {
195+ // Nested proxies should not trigger any proxy handlers.
196+ const nestedProxy = new Proxy ( new Proxy ( new Proxy ( { } , handler ) , { } ) , { } ) ;
197+
198+ assert . strictEqual (
199+ util . inspect ( nestedProxy , { showProxy : true } ) ,
200+ 'Proxy [ Proxy [ Proxy [ {}, [Object] ], {} ], {} ]'
201+ ) ;
202+ assert . strictEqual ( util . inspect ( nestedProxy , { showProxy : false } ) , '{}' ) ;
203+ }
204+
205+ {
206+ // Nested revoked proxies should work as expected as well as custom inspection functions.
207+ const revocable = Proxy . revocable ( { } , handler ) ;
208+ revocable . revoke ( ) ;
209+ const nestedProxy = new Proxy ( revocable . proxy , { } ) ;
210+
211+ assert . strictEqual ( util . inspect ( nestedProxy , { showProxy : true } ) , 'Proxy [ <Revoked Proxy>, {} ]' ) ;
212+ assert . strictEqual ( util . inspect ( nestedProxy , { showProxy : false } ) , '<Revoked Proxy>' ) ;
213+ }
0 commit comments