mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
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>
36 lines
832 B
JavaScript
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] {}',
|
|
);
|