From 061c5da010e0d249379618382a499840d38247b8 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Wed, 19 Apr 2017 23:08:09 -0700 Subject: [PATCH] url: use internal/util's getConstructorOf PR-URL: https://github.com/nodejs/node/pull/12526 Reviewed-By: James M Snell --- lib/internal/url.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index cacdff7c3aa0f5..25a4f51ba23542 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -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'); @@ -171,17 +172,6 @@ function onParseHashComplete(flags, protocol, username, password, this[context].fragment = fragment; } -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. @@ -220,7 +210,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