buffer: fix custom inspection with extra properties · nodejs/node@d834275 (original) (raw)
`@@ -59,8 +59,7 @@ const {
`
59
59
` isUint8Array
`
60
60
`} = require('internal/util/types');
`
61
61
`const {
`
62
``
`-
formatProperty,
`
63
``
`-
kObjectType
`
``
62
`+
inspect: utilInspect
`
64
63
`} = require('internal/util/inspect');
`
65
64
``
66
65
`const {
`
`@@ -665,13 +664,24 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
`
665
664
`` str += ... <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>r</mi><mi>e</mi><mi>m</mi><mi>a</mi><mi>i</mi><mi>n</mi><mi>i</mi><mi>n</mi><mi>g</mi></mrow><mi>m</mi><mi>o</mi><mi>r</mi><mi>e</mi><mi>b</mi><mi>y</mi><mi>t</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">{remaining} more byte</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal">re</span><span class="mord mathnormal">mainin</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span></span><span class="mord mathnormal">m</span><span class="mord mathnormal">ore</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span></span></span></span>{remaining > 1 ? 's' : ''}
;
``
666
665
`// Inspect special properties as well, if possible.
`
667
666
`if (ctx) {
`
``
667
`+
let extras = false;
`
668
668
`const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE;
`
669
``
`-
str += getOwnNonIndexProperties(this, filter).reduce((str, key) => {
`
670
``
`` -
// Using formatProperty()
expects an indentationLvl to be set.
``
671
``
`-
ctx.indentationLvl = 0;
`
672
``
`` -
str += , ${formatProperty(ctx, this, recurseTimes, key, kObjectType)}
;
``
673
``
`-
return str;
`
674
``
`-
}, '');
`
``
669
`+
const obj = getOwnNonIndexProperties(this, filter).reduce((obj, key) => {
`
``
670
`+
extras = true;
`
``
671
`+
obj[key] = this[key];
`
``
672
`+
return obj;
`
``
673
`+
}, Object.create(null));
`
``
674
`+
if (extras) {
`
``
675
`+
if (this.length !== 0)
`
``
676
`+
str += ', ';
`
``
677
`+
// '[Object: null prototype] {'.length === 26
`
``
678
`+
// This is guarded with a test.
`
``
679
`+
str += utilInspect(obj, {
`
``
680
`+
...ctx,
`
``
681
`+
breakLength: Infinity,
`
``
682
`+
compact: true
`
``
683
`+
}).slice(27, -2);
`
``
684
`+
}
`
675
685
`}
`
676
686
`` return <${this.constructor.name} ${str}>
;
``
677
687
`};
`