Repository: nodejs/node
File: test/parallel/test-util-inspect-proxy.js (JavaScript)

Code before:
assert.strictEqual(util.inspect(proxy8, opts), expected8);
assert.strictEqual(util.inspect(proxy9, opts), expected9);
assert.strictEqual(util.inspect(proxy8), '[Function: Date]');
assert.strictEqual(util.inspect(proxy9), '[Function: Date]');

const proxy10 = new Proxy(() => {}, {});
const proxy11 = new Proxy(() => {}, {
  get() {
    return proxy11;
  },
  apply() {
    return proxy11;
  }
});
const expected10 = '[Function (anonymous)]';
const expected11 = '[Function (anonymous)]';
assert.strictEqual(util.inspect(proxy10), expected10);
assert.strictEqual(util.inspect(proxy11), expected11);

{
  // Nested proxies should not trigger any proxy handlers.
  const errorProxy = new Proxy({}, { get(...cause) { throw new EvalError('boom', { cause }); } });
  const nestedProxy = new Proxy(errorProxy, {});

  util.inspect(nestedProxy, { showProxy: true });
  util.inspect(nestedProxy, { showProxy: false });
}


Review comment (suggestion):
Just in case of potential regressions, we can doublecheck deeper nested proxy and handler being a proxified proxy itself.
```suggestion
  util.inspect(nestedProxy, { showProxy: false });
  util.inspect(new Proxy(nestedProxy, handler), { showProxy: false });
  util.inspect(new Proxy(nestedProxy, nestedProxy), { showProxy: false });
```

Code after:
assert.strictEqual(util.inspect(proxy7, opts), expected7);
assert.strictEqual(util.inspect(proxy7), 'Proxy([])');

// Now we're just getting silly, right?
const proxy8 = new Proxy(Date, []);
const proxy9 = new Proxy(Date, String);
const expected8 = 'Proxy [ [Function: Date], [] ]';
const expected9 = 'Proxy [ [Function: Date], [Function: String] ]';
assert.strictEqual(util.inspect(proxy8, opts), expected8);
assert.strictEqual(util.inspect(proxy9, opts), expected9);
assert.strictEqual(util.inspect(proxy8), 'Proxy([Function: Date])');
assert.strictEqual(util.inspect(proxy9), 'Proxy([Function: Date])');

const proxy10 = new Proxy(() => {}, {});
const proxy11 = new Proxy(() => {}, {
  get() {
    return proxy11;
  },
  apply() {
    return proxy11;
  }
});
const expected10 = 'Proxy([Function (anonymous)])';
const expected11 = 'Proxy([Function (anonymous)])';
assert.strictEqual(util.inspect(proxy10), expected10);
assert.strictEqual(util.inspect(proxy11), expected11);

const proxy12 = new Proxy([1, 2, 3], proxy5);
assert.strictEqual(
  util.inspect(proxy12, { colors: true, breakLength: 1 }),
  '\x1B[36mProxy(\x1B[39m' +
    '[\n  \x1B[33m1\x1B[39m,\n  \x1B[33m2\x1B[39m,\n  \x1B[33m3\x1B[39m\n]\x1B[36m' +
    ')\x1B[39m'
);
assert.strictEqual(util.format('%s', proxy12), 'Proxy([ 1, 2, 3 ])');

{
  // Nested proxies should not trigger any proxy handlers.
  const nestedProxy = new Proxy(new Proxy(new Proxy({}, handler), {}), {});

  assert.strictEqual(
    util.inspect(nestedProxy, { showProxy: true }),
    'Proxy [ Proxy [ Proxy [ {}, [Object] ], {} ], {} ]'
  );
  assert.strictEqual(util.inspect(nestedProxy, { showProxy: false }), expected3NoShowProxy);
}

{
  // Nested revoked proxies should work as expected as well as custom inspection functions.
  const revocable = Proxy.revocable({}, handler);
  revocable.revoke();