Files
node/test/parallel/test-util-inspect-url.js
Donghoon Kang 531d28fc36 util: fix inspecting URL subclass prototypes
Check the URL private field brand before accessing href to avoid
throwing when inspecting URL subclass prototypes.

Assisted-by: Codex:6.1SolHigh
Signed-off-by: HoonDongKang <d159123@naver.com>
PR-URL: https://github.com/nodejs/node/pull/66822
Fixes: https://github.com/nodejs/node/issues/66821
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
2026-10-20 04:54:54 +00:00

36 lines
832 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const { format, inspect } = require('util');
class TestURL extends URL {}
assert.strictEqual(inspect(TestURL.prototype), 'URL {}');
assert.strictEqual(
inspect(TestURL.prototype, { customInspect: false }),
'URL {}',
);
// Inspecting hidden properties must not throw when reaching the prototype.
inspect(TestURL, { showHidden: true });
inspect({ TestURL }, { showHidden: true });
format('%o', { TestURL });
const url = new TestURL('https://example.org/');
assert.strictEqual(
inspect(url, { customInspect: false }),
'https://example.org/',
);
class NonStringURL extends URL {
get href() {
return undefined;
}
}
assert.strictEqual(
inspect(new NonStringURL('https://example.org/'), { customInspect: false }),
'NonStringURL [URL] {}',
);