Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
url: use internal/util's getConstructorOf
  • Loading branch information
TimothyGu committed Apr 20, 2017
commit 0f495ff1674bb939877279007d86d04108a9149a
14 changes: 2 additions & 12 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
hexTable,
isHexTable
} = require('internal/querystring');
const { getConstructorOf } = require('internal/util');
const binding = process.binding('url');
const context = Symbol('context');
const cannotBeBase = Symbol('cannot-be-base');
Expand Down Expand Up @@ -184,17 +185,6 @@ 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.
Expand Down Expand Up @@ -225,7 +215,7 @@ class URL {
if (typeof depth === 'number' && depth < 0)
return opts.stylize('[Object]', 'special');

const ctor = getEligibleConstructor(this);
const ctor = getConstructorOf(this);

const obj = Object.create({
constructor: ctor === null ? URL : ctor
Expand Down