mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
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:
1 parent
0d7ee19786
commit
540929d597
1 file changed
+7
-9
+7
-9
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user