url: simplify native URL object construction
Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com> PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
f2be20b735
commit
f0b6b39324
@ -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();
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user