@@ -8,11 +8,35 @@ const { internalBinding } = require('internal/test/binding');
88const processUtil = internalBinding ( 'util' ) ;
99const opts = { showProxy : true } ;
1010
11- const target = { } ;
11+ let proxyObj ;
12+ let called = false ;
13+ const target = {
14+ [ util . inspect . custom ] ( depth , { showProxy } ) {
15+ if ( showProxy === false ) {
16+ called = true ;
17+ if ( proxyObj !== this ) {
18+ throw new Error ( 'Failed' ) ;
19+ }
20+ }
21+ return [ 1 , 2 , 3 ] ;
22+ }
23+ } ;
1224const handler = {
13- get : function ( ) { throw new Error ( 'Getter should not be called' ) ; }
25+ getPrototypeOf ( ) { throw new Error ( 'getPrototypeOf' ) ; } ,
26+ setPrototypeOf ( ) { throw new Error ( 'setPrototypeOf' ) ; } ,
27+ isExtensible ( ) { throw new Error ( 'isExtensible' ) ; } ,
28+ preventExtensions ( ) { throw new Error ( 'preventExtensions' ) ; } ,
29+ getOwnPropertyDescriptor ( ) { throw new Error ( 'getOwnPropertyDescriptor' ) ; } ,
30+ defineProperty ( ) { throw new Error ( 'defineProperty' ) ; } ,
31+ has ( ) { throw new Error ( 'has' ) ; } ,
32+ get ( ) { throw new Error ( 'get' ) ; } ,
33+ set ( ) { throw new Error ( 'set' ) ; } ,
34+ deleteProperty ( ) { throw new Error ( 'deleteProperty' ) ; } ,
35+ ownKeys ( ) { throw new Error ( 'ownKeys' ) ; } ,
36+ apply ( ) { throw new Error ( 'apply' ) ; } ,
37+ construct ( ) { throw new Error ( 'construct' ) ; }
1438} ;
15- const proxyObj = new Proxy ( target , handler ) ;
39+ proxyObj = new Proxy ( target , handler ) ;
1640
1741// Inspecting the proxy should not actually walk it's properties
1842util . inspect ( proxyObj , opts ) ;
@@ -23,19 +47,31 @@ const details = processUtil.getProxyDetails(proxyObj);
2347assert . strictEqual ( target , details [ 0 ] ) ;
2448assert . strictEqual ( handler , details [ 1 ] ) ;
2549
26- assert . strictEqual ( util . inspect ( proxyObj , opts ) ,
27- 'Proxy [ {}, { get: [Function: get] } ]' ) ;
50+ assert . strictEqual (
51+ util . inspect ( proxyObj , opts ) ,
52+ 'Proxy [ [ 1, 2, 3 ],\n' +
53+ ' { getPrototypeOf: [Function: getPrototypeOf],\n' +
54+ ' setPrototypeOf: [Function: setPrototypeOf],\n' +
55+ ' isExtensible: [Function: isExtensible],\n' +
56+ ' preventExtensions: [Function: preventExtensions],\n' +
57+ ' getOwnPropertyDescriptor: [Function: getOwnPropertyDescriptor],\n' +
58+ ' defineProperty: [Function: defineProperty],\n' +
59+ ' has: [Function: has],\n' +
60+ ' get: [Function: get],\n' +
61+ ' set: [Function: set],\n' +
62+ ' deleteProperty: [Function: deleteProperty],\n' +
63+ ' ownKeys: [Function: ownKeys],\n' +
64+ ' apply: [Function: apply],\n' +
65+ ' construct: [Function: construct] } ]'
66+ ) ;
2867
2968// Using getProxyDetails with non-proxy returns undefined
3069assert . strictEqual ( processUtil . getProxyDetails ( { } ) , undefined ) ;
3170
32- // This will throw because the showProxy option is not used
33- // and the get function on the handler object defined above
34- // is actually invoked.
35- assert . throws (
36- ( ) => util . inspect ( proxyObj ) ,
37- / ^ E r r o r : G e t t e r s h o u l d n o t b e c a l l e d $ /
38- ) ;
71+ // Inspecting a proxy without the showProxy option set to true should not
72+ // trigger any proxy handlers.
73+ assert . strictEqual ( util . inspect ( proxyObj ) , '[ 1, 2, 3 ]' ) ;
74+ assert ( called ) ;
3975
4076// Yo dawg, I heard you liked Proxy so I put a Proxy
4177// inside your Proxy that proxies your Proxy's Proxy.
0 commit comments