util: use internal hexSlice directly in util.inspect()

Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/66974
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
Livia Medeiros authored and Antoine du Hamel committed 2026-11-12 17:45:29 +01:00
1 parent d919a87cdc
commit 1d2be62b5e
3 files changed
+15 -4

No files matched your search

+1
View File
@@ -1148,6 +1148,7 @@ module.exports = {
createUnsafeAlignedBuffer,
readUInt16BE,
readUInt32BE,
hexSlice,
asciiWrite,
latin1Write,
utf8Write,
+4 -4
View File
@@ -130,7 +130,6 @@ const {
WeakSet,
WeakSetPrototype,
globalThis,
uncurryThis,
} = primordials;
const {
@@ -195,7 +194,10 @@ const {
kValidateObjectAllowArray,
} = require('internal/validators');
let hexSlice;
const {
hexSlice,
} = require('internal/buffer');
let internalUrl;
function pathToFileUrlHref(filepath) {
@@ -2347,8 +2349,6 @@ function formatArrayBuffer(ctx, value) {
} catch {
return [ctx.stylize('(detached)', 'special')];
}
if (hexSlice === undefined)
hexSlice = uncurryThis(require('buffer').Buffer.prototype.hexSlice);
const rawString = hexSlice(buffer, 0, MathMin(ctx.maxArrayLength, buffer.length));
let str = '';
let i = 0;
@@ -0,0 +1,10 @@
import { mustNotCall } from '../common/index.mjs';
import assert from 'node:assert';
import { inspect } from 'node:util';
// util.inspect must not be affected by userland mutations of Buffer.prototype
Buffer.prototype.hexSlice = mustNotCall();
const { buffer } = new Uint8Array([0x04, 0x38, 0x73, 0xE6]);
const expected = 'ArrayBuffer { [Uint8Contents]: <04 38 73 e6>, [byteLength]: 4 }';
assert.strictEqual(inspect(buffer), expected);