compat: util.inspect on arrays has differences with upstream Node
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
util.inspect also doesn't print out property '4294967295' (one beyond the supported index). for_in does enumerate it.
@irinayat-MS it looks like that issue was fixed by my shim update: https://github.com/nodejs/node-chakracore/commit/835789f6891c22fef92e555d03bed3b175a54156#diff-55320053aaa0abe61795d171a27dcbc8L432
Yep, should be fixed by your change.
Looks like there's a proposal to standardize the enumeration order: https://github.com/tc39/ecma262/pull/1243