Skip to content

util.inspect is not so hot on large typed arrays #3648

Closed
@jacksonloper

Description

@jacksonloper

Typing...

> x=new Float32Array(100000);

... leads to death and sorrow, as the interpreter decides to util.inspect(x).

There are, of course, workarounds, such as

> x=new Float32Array(100000); 0

... but I was wondering if we might be able to do better.

What if we told util.inspect to handle ArrayBuffers and their views a bit differently from other objects?

Now obviously we don't want to go changing the code for util.inspect any time some new-fangled object that comes on the scene. However, typed arrays are definitely here to stay and currently growing in popularity.

Two reasonable courses would be

 >  new Float32Array(36)
 [Float32Array: length 36]

or

> new Float32Array(36)
{ BYTES_PER_ELEMENT: 4,
  get: [Function: get],
  set: [Function: set],
  slice: [Function: slice],
  subarray: [Function: subarray],
  buffer: {slice: [Function: slice], byteLength:144}
  length: 36,
  byteOffset: 0,
  byteLength: 4 }

What do you think. Am I crazy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.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