fix(util): render [Object: null prototype] prefix in util.inspect (Node parity)#5107
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesNull-prototype object prefix rendering
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
a94f8ce to
dd43d5b
Compare
dd43d5b to
90a8a53
Compare
…de parity)
`util.inspect` / `console.log` of a null-prototype object (e.g.
`Object.create(null)`) printed it as a bare `{}` / `{ a: 1 }`, where Node
prefixes it with `[Object: null prototype]` (it has no constructor to
name). These objects are common as option bags / lookup maps, so the
missing prefix is a visible parity gap.
Detect the existing `OBJ_FLAG_NULL_PROTO` GC-header flag (set by
`js_object_alloc_null_proto`) in the object formatter and introduce a
`name_prefix` that resolves to the constructor/class name when present,
else `[Object: null prototype]` for a null-proto plain object, else
nothing. `name_prefix` replaces `class_name_ref` only at the three
render sites (empty / single-line / multi-line); `has_class_name`
(private-field skip) still reflects a genuine class.
Verified vs Node v26.3.0: `Object.create(null)` → `[Object: null
prototype] {}`; all 17 other inspect probe cases (classes, Map/Set,
circular, Error, Date, RegExp, getters, bigint, …) unchanged.
formatting/inspect unit tests pass (12).
90a8a53 to
6023e60
Compare
Problem
util.inspect/console.logof a null-prototype object printed it as a bare{}, where Node prefixes it with[Object: null prototype]:These objects are common as option bags / lookup maps, so the missing prefix is a visible parity gap.
Fix
Detect the existing
OBJ_FLAG_NULL_PROTOGC-header flag (set byjs_object_alloc_null_proto) in the object formatter and introduce aname_prefixthat resolves to:[Object: null prototype]for a null-proto plain object,name_prefixreplacesclass_name_refonly at the three render sites (empty / single-line / multi-line).has_class_name(which drives the#private-field skip) still reflects a genuine class, so behavior for normal and class objects is unchanged.Verification (vs Node v26.3.0)
Object.create(null)→[Object: null prototype] {}✓Foo { x: 1 },Map(1) { … },Set, circular<ref *1>,Error,Date,RegExp,[Getter], bigint, NaN/Infinity, …).perry-runtimeformatting + inspect unit tests pass (12).Found via a
util.inspectdifferential sweep vs Node; relates to the console/util-formatting parity gap inCLAUDE.mdand the parity roadmap (#4315). (Known remaining inspect nits, left out of scope: sparse-array holes render asNaNnot<1 empty item>, and Node's quote-style heuristic /showHiddenarray[length].)No version bump / changelog per maintainer instruction.
Summary by CodeRabbit
[Object: null prototype]across both compact and expanded output views.