node-chakracore icon indicating copy to clipboard operation
node-chakracore copied to clipboard

compat: util.inspect on arrays has differences with upstream Node

Open digitalinfinity opened this issue 8 years ago • 4 comments

util.inspect has compat differences because of differences in ChakraCore and v8 around the enumeration of properties with Arrays. v8's behavior for Arrays is to enumerate indexed properties, then the length property, and then finally any other properties on the Array. ChakraCore instead enumerates the indexed properties and user defined properties first, before enumerating over the special properties of which length is 1. This breaks the following in lib/util.js:

  if (ctx.showHidden && keys[keyLen - 1] === 'length') {
    // No extra keys
    output.push(formatProperty(ctx, value, recurseTimes, 'length', 2));
  } else if (valLen === 0 ||

The above assumes that the length property acts as a separator between index properties and other user properties, which is a v8-specific assumption. Since on ChakraCore the length property is the last property, the net effect is that showHidden doesn't show the extra keys.

Fixing this issue will also enable us to enable the array portion of the test in test/parallel/test-util-inspect.js

  • Version: 9+
  • Platform: all
  • Subsystem: compat

digitalinfinity avatar Sep 23 '17 01:09 digitalinfinity

util.inspect also doesn't print out property '4294967295' (one beyond the supported index). for_in does enumerate it.

IrinaYatsenko avatar Sep 10 '18 21:09 IrinaYatsenko

@irinayat-MS it looks like that issue was fixed by my shim update: https://github.com/nodejs/node-chakracore/commit/835789f6891c22fef92e555d03bed3b175a54156#diff-55320053aaa0abe61795d171a27dcbc8L432

kfarnung avatar Sep 11 '18 20:09 kfarnung

Yep, should be fixed by your change.

IrinaYatsenko avatar Sep 11 '18 20:09 IrinaYatsenko

Looks like there's a proposal to standardize the enumeration order: https://github.com/tc39/ecma262/pull/1243

kfarnung avatar Sep 25 '18 18:09 kfarnung