Skip to content

Commit db2f056

Browse files
committed
url: use a class for url[context]
The object is used as a structure, not as a map, which `StorageObject` was designed for.
1 parent 6fd9a99 commit db2f056

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

lib/internal/url.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
const util = require('util');
44
const {
55
hexTable,
6-
isHexTable,
7-
StorageObject
6+
isHexTable
87
} = require('internal/querystring');
98
const binding = process.binding('url');
109
const context = Symbol('context');
@@ -97,6 +96,26 @@ class TupleOrigin {
9796
}
9897
}
9998

99+
// This class provides the internal state of a URL object. An instance of this
100+
// class is stored in every URL object and is accessed internally by setters
101+
// and getters. It roughly corresponds to the concept of a URL record in the
102+
// URL Standard, with a few differences. It is also the object transported to
103+
// the C++ binding.
104+
// Refs: https://url.spec.whatwg.org/#concept-url
105+
class URLContext {
106+
constructor() {
107+
this.flags = 0;
108+
this.scheme = undefined;
109+
this.username = undefined;
110+
this.password = undefined;
111+
this.host = undefined;
112+
this.port = undefined;
113+
this.path = [];
114+
this.query = undefined;
115+
this.fragment = undefined;
116+
}
117+
}
118+
100119
function onParseComplete(flags, protocol, username, password,
101120
host, port, path, query, fragment) {
102121
if (flags & binding.URL_FLAGS_FAILED)
@@ -121,7 +140,7 @@ function onParseComplete(flags, protocol, username, password,
121140
// Reused by URL constructor and URL#href setter.
122141
function parse(url, input, base) {
123142
const base_context = base ? base[context] : undefined;
124-
url[context] = new StorageObject();
143+
url[context] = new URLContext();
125144
binding.parse(input.trim(), -1,
126145
base_context, undefined,
127146
onParseComplete.bind(url));

0 commit comments

Comments
 (0)