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);
|
return fileURLToPath(fileURLOrPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function NativeURL(ctx) {
|
|
||||||
this[context] = ctx;
|
|
||||||
}
|
|
||||||
NativeURL.prototype = URL.prototype;
|
|
||||||
|
|
||||||
function constructUrl(flags, protocol, username, password,
|
function constructUrl(flags, protocol, username, password,
|
||||||
host, port, path, query, fragment) {
|
host, port, path, query, fragment) {
|
||||||
var ctx = new URLContext();
|
var ctx = new URLContext();
|
||||||
@ -1386,10 +1381,13 @@ function constructUrl(flags, protocol, username, password,
|
|||||||
ctx.query = query;
|
ctx.query = query;
|
||||||
ctx.fragment = fragment;
|
ctx.fragment = fragment;
|
||||||
ctx.host = host;
|
ctx.host = host;
|
||||||
const url = new NativeURL(ctx);
|
|
||||||
url[searchParams] = new URLSearchParams();
|
const url = Object.create(URL.prototype);
|
||||||
url[searchParams][context] = url;
|
url[context] = ctx;
|
||||||
initSearchParams(url[searchParams], query);
|
const params = new URLSearchParams();
|
||||||
|
url[searchParams] = params;
|
||||||
|
params[context] = url;
|
||||||
|
initSearchParams(params, query);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
setURLConstructor(constructUrl);
|
setURLConstructor(constructUrl);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user