mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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:
1 parent
d919a87cdc
commit
1d2be62b5e
3 files changed
+15
-4
No files matched your search
@@ -1148,6 +1148,7 @@ module.exports = {
|
||||
createUnsafeAlignedBuffer,
|
||||
readUInt16BE,
|
||||
readUInt32BE,
|
||||
hexSlice,
|
||||
asciiWrite,
|
||||
latin1Write,
|
||||
utf8Write,
|
||||
|
||||
@@ -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);
|
||||
Reference in new issue
Block a user