Skip to content

Commit

Permalink
url: simplify native URL object construction
Browse files Browse the repository at this point in the history
Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>

PR-URL: #24495
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
TimothyGu authored and BethGriggs committed Feb 12, 2019
1 parent d06ea3e commit c0423cf
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,11 +1369,6 @@ function toPathIfFileURL(fileURLOrPath) {
return fileURLToPath(fileURLOrPath);
}

function NativeURL(ctx) {
this[context] = ctx;
}
NativeURL.prototype = URL.prototype;

function constructUrl(flags, protocol, username, password,
host, port, path, query, fragment) {
var ctx = new URLContext();
Expand All @@ -1386,10 +1381,13 @@ function constructUrl(flags, protocol, username, password,
ctx.query = query;
ctx.fragment = fragment;
ctx.host = host;
const url = new NativeURL(ctx);
url[searchParams] = new URLSearchParams();
url[searchParams][context] = url;
initSearchParams(url[searchParams], query);

const url = Object.create(URL.prototype);
url[context] = ctx;
const params = new URLSearchParams();
url[searchParams] = params;
params[context] = url;
initSearchParams(params, query);
return url;
}
setURLConstructor(constructUrl);
Expand Down

0 comments on commit c0423cf

Please sign in to comment.