Skip to content

util: possibly confusing util.inspect() output #15474

Closed
@vsemozhetbyt

Description

@vsemozhetbyt
  • Version: 8.5.0
  • Platform: Windows 7 x64
  • Subsystem: util

I am trying to make a simple object autovivification with Proxy:

function autoVivify() {
  return new Proxy({}, {
    get(target, property) {
      if (target[property] === undefined) target[property] = autoVivify();
      return target[property];
    },
  });
}

const obj = autoVivify();

obj.a.b.c = 1;

console.log(obj);
{ a:
   { b: { c: 1, [Symbol(util.inspect.custom)]: [Object] },
     [Symbol(util.inspect.custom)]: { [Symbol(util.inspect.custom)]: [Object] } },
  [Symbol(util.inspect.custom)]: { [Symbol(util.inspect.custom)]: { [Symbol(util.inspect.custom)]: [Object] } } }

I understand that this is an edge case and maybe the output is correct. But I feel somehow that I should report this in case it is not completely intended. Feel free to close if it is by design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions