GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — url: improve resolveObject with ObjectAssign · nodejs/node@b25563d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • url.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/url.js‎

Copy file name to clipboardExpand all lines: lib/url.js
+10-16Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const {
2525
Boolean,
2626
Int8Array,
27+
ObjectAssign,
2728
ObjectKeys,
2829
StringPrototypeCharCodeAt,
2930
decodeURIComponent,
@@ -735,11 +736,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
735736
}
736737

737738
const result = new Url();
738-
const tkeys = ObjectKeys(this);
739-
for (let tk = 0; tk < tkeys.length; tk++) {
740-
const tkey = tkeys[tk];
741-
result[tkey] = this[tkey];
742-
}
739+
ObjectAssign(result, this);
743740

744741
// Hash is always overridden, no matter what.
745742
// even href="" will remove it.
@@ -754,12 +751,13 @@ Url.prototype.resolveObject = function resolveObject(relative) {
754751
// Hrefs like //foo/bar always cut to the protocol.
755752
if (relative.slashes && !relative.protocol) {
756753
// Take everything except the protocol from relative
757-
const rkeys = ObjectKeys(relative);
758-
for (let rk = 0; rk < rkeys.length; rk++) {
759-
const rkey = rkeys[rk];
760-
if (rkey !== 'protocol')
761-
result[rkey] = relative[rkey];
762-
}
754+
const relativeWithoutProtocol = ObjectKeys(relative).reduce((acc, key) => {
755+
if (key !== 'protocol') {
756+
acc[key] = relative[key];
757+
}
758+
return acc;
759+
}, {});
760+
ObjectAssign(result, relativeWithoutProtocol);
763761

764762
// urlParse appends trailing / to urls like http://www.example.com
765763
if (slashedProtocol.has(result.protocol) &&
@@ -781,11 +779,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
781779
// because that's known to be hostless.
782780
// anything else is assumed to be absolute.
783781
if (!slashedProtocol.has(relative.protocol)) {
784-
const keys = ObjectKeys(relative);
785-
for (let v = 0; v < keys.length; v++) {
786-
const k = keys[v];
787-
result[k] = relative[k];
788-
}
782+
ObjectAssign(result, relative);
789783
result.href = result.format();
790784
return result;
791785
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.