|
|
@ -184,6 +184,17 @@ function onParseHashComplete(flags, protocol, username, password, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function getEligibleConstructor(obj) { |
|
|
|
while (obj !== null) { |
|
|
|
if (Object.prototype.hasOwnProperty.call(obj, 'constructor') && |
|
|
|
typeof obj.constructor === 'function') { |
|
|
|
return obj.constructor; |
|
|
|
} |
|
|
|
obj = Object.getPrototypeOf(obj); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
class URL { |
|
|
|
constructor(input, base) { |
|
|
|
// toUSVString is not needed.
|
|
|
@ -204,33 +215,43 @@ class URL { |
|
|
|
} |
|
|
|
|
|
|
|
[util.inspect.custom](depth, opts) { |
|
|
|
if (this == null || |
|
|
|
Object.getPrototypeOf(this[context]) !== URLContext.prototype) { |
|
|
|
throw new TypeError('Value of `this` is not a URL'); |
|
|
|
} |
|
|
|
|
|
|
|
const ctx = this[context]; |
|
|
|
var ret = 'URL {\n'; |
|
|
|
ret += ` href: ${this.href}\n`; |
|
|
|
if (ctx.scheme !== undefined) |
|
|
|
ret += ` protocol: ${this.protocol}\n`; |
|
|
|
if (ctx.username !== undefined) |
|
|
|
ret += ` username: ${this.username}\n`; |
|
|
|
if (ctx.password !== undefined) { |
|
|
|
const pwd = opts.showHidden ? ctx.password : '--------'; |
|
|
|
ret += ` password: ${pwd}\n`; |
|
|
|
} |
|
|
|
if (ctx.host !== undefined) |
|
|
|
ret += ` hostname: ${this.hostname}\n`; |
|
|
|
if (ctx.port !== undefined) |
|
|
|
ret += ` port: ${this.port}\n`; |
|
|
|
if (ctx.path !== undefined) |
|
|
|
ret += ` pathname: ${this.pathname}\n`; |
|
|
|
if (ctx.query !== undefined) |
|
|
|
ret += ` search: ${this.search}\n`; |
|
|
|
if (ctx.fragment !== undefined) |
|
|
|
ret += ` hash: ${this.hash}\n`; |
|
|
|
|
|
|
|
if (typeof depth === 'number' && depth < 0) |
|
|
|
return opts.stylize('[Object]', 'special'); |
|
|
|
|
|
|
|
const ctor = getEligibleConstructor(this); |
|
|
|
|
|
|
|
const obj = Object.create({ |
|
|
|
constructor: ctor === null ? URL : ctor |
|
|
|
}); |
|
|
|
|
|
|
|
obj.href = this.href; |
|
|
|
obj.origin = this.origin; |
|
|
|
obj.protocol = this.protocol; |
|
|
|
obj.username = this.username; |
|
|
|
obj.password = (opts.showHidden || ctx.password == null) ? |
|
|
|
this.password : '--------'; |
|
|
|
obj.host = this.host; |
|
|
|
obj.hostname = this.hostname; |
|
|
|
obj.port = this.port; |
|
|
|
obj.pathname = this.pathname; |
|
|
|
obj.search = this.search; |
|
|
|
obj.searchParams = this.searchParams; |
|
|
|
obj.hash = this.hash; |
|
|
|
|
|
|
|
if (opts.showHidden) { |
|
|
|
ret += ` cannot-be-base: ${this[cannotBeBase]}\n`; |
|
|
|
ret += ` special: ${this[special]}\n`; |
|
|
|
obj.cannotBeBase = this[cannotBeBase]; |
|
|
|
obj.special = this[special]; |
|
|
|
obj[context] = this[context]; |
|
|
|
} |
|
|
|
ret += '}'; |
|
|
|
return ret; |
|
|
|
|
|
|
|
return util.inspect(obj, opts); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -858,6 +879,9 @@ class URLSearchParams { |
|
|
|
throw new TypeError('Value of `this` is not a URLSearchParams'); |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof recurseTimes === 'number' && recurseTimes < 0) |
|
|
|
return ctx.stylize('[Object]', 'special'); |
|
|
|
|
|
|
|
const separator = ', '; |
|
|
|
const innerOpts = Object.assign({}, ctx); |
|
|
|
if (recurseTimes !== null) { |
|
|
@ -1211,6 +1235,12 @@ defineIDLClass(URLSearchParamsIteratorPrototype, 'URLSearchParamsIterator', { |
|
|
|
}; |
|
|
|
}, |
|
|
|
[util.inspect.custom](recurseTimes, ctx) { |
|
|
|
if (this == null || this[context] == null || this[context].target == null) |
|
|
|
throw new TypeError('Value of `this` is not a URLSearchParamsIterator'); |
|
|
|
|
|
|
|
if (typeof recurseTimes === 'number' && recurseTimes < 0) |
|
|
|
return ctx.stylize('[Object]', 'special'); |
|
|
|
|
|
|
|
const innerOpts = Object.assign({}, ctx); |
|
|
|
if (recurseTimes !== null) { |
|
|
|
innerOpts.depth = recurseTimes - 1; |
|
|
|