Skip to content

Commit 061c5da

Browse files
committed
url: use internal/util's getConstructorOf
PR-URL: #12526 Reviewed-By: James M Snell <[email protected]>
1 parent 3c0dd45 commit 061c5da

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

lib/internal/url.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
hexTable,
66
isHexTable
77
} = require('internal/querystring');
8+
const { getConstructorOf } = require('internal/util');
89
const binding = process.binding('url');
910
const context = Symbol('context');
1011
const cannotBeBase = Symbol('cannot-be-base');
@@ -171,17 +172,6 @@ function onParseHashComplete(flags, protocol, username, password,
171172
this[context].fragment = fragment;
172173
}
173174

174-
function getEligibleConstructor(obj) {
175-
while (obj !== null) {
176-
if (Object.prototype.hasOwnProperty.call(obj, 'constructor') &&
177-
typeof obj.constructor === 'function') {
178-
return obj.constructor;
179-
}
180-
obj = Object.getPrototypeOf(obj);
181-
}
182-
return null;
183-
}
184-
185175
class URL {
186176
constructor(input, base) {
187177
// toUSVString is not needed.
@@ -220,7 +210,7 @@ class URL {
220210
if (typeof depth === 'number' && depth < 0)
221211
return opts.stylize('[Object]', 'special');
222212

223-
const ctor = getEligibleConstructor(this);
213+
const ctor = getConstructorOf(this);
224214

225215
const obj = Object.create({
226216
constructor: ctor === null ? URL : ctor

0 commit comments

Comments
 (0)