GeezerVison is showing github.com — url: simplify native URL object construction · nodejs/node@c0423cf
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/url.js +7-9Lines changed: 7 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1369,11 +1369,6 @@ function toPathIfFileURL(fileURLOrPath) { |
1369 | 1369 | return fileURLToPath(fileURLOrPath); |
1370 | 1370 | } |
1371 | 1371 |
|
1372 | | -function NativeURL(ctx) { |
1373 | | - this[context] = ctx; |
1374 | | -} |
1375 | | -NativeURL.prototype = URL.prototype; |
1376 | | - |
1377 | 1372 | function constructUrl(flags, protocol, username, password, |
1378 | 1373 | host, port, path, query, fragment) { |
1379 | 1374 | var ctx = new URLContext(); |
@@ -1386,10 +1381,13 @@ function constructUrl(flags, protocol, username, password, |
1386 | 1381 | ctx.query = query; |
1387 | 1382 | ctx.fragment = fragment; |
1388 | 1383 | ctx.host = host; |
1389 | | - const url = new NativeURL(ctx); |
1390 | | - url[searchParams] = new URLSearchParams(); |
1391 | | - url[searchParams][context] = url; |
1392 | | - initSearchParams(url[searchParams], query); |
| 1384 | + |
| 1385 | + const url = Object.create(URL.prototype); |
| 1386 | + url[context] = ctx; |
| 1387 | + const params = new URLSearchParams(); |
| 1388 | + url[searchParams] = params; |
| 1389 | + params[context] = url; |
| 1390 | + initSearchParams(params, query); |
1393 | 1391 | return url; |
1394 | 1392 | } |
1395 | 1393 | setURLConstructor(constructUrl); |
|