Skip to content

Commit 4b6097d

Browse files
TimothyGuevanlucas
authored andcommitted
url: use a class for WHATWG url[context]
The object is used as a structure, not as a map, which `StorageObject` was designed for. PR-URL: #12507 Reviewed-By: James M Snell <[email protected]>
1 parent 01b8839 commit 4b6097d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

‎lib/internal/url.js‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
constutil=require('util');
44
const{
55
hexTable,
6-
isHexTable,
7-
StorageObject
6+
isHexTable
87
}=require('internal/querystring');
98
constbinding=process.binding('url');
109
constcontext=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+
classURLContext{
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
functiononParseComplete(flags,protocol,username,password,
101120
host,port,path,query,fragment){
102121
varctx=this[context];
@@ -125,7 +144,7 @@ function onParseError(flags, input){
125144
// Reused by URL constructor and URL#href setter.
126145
functionparse(url,input,base){
127146
constbase_context=base ? base[context] : undefined;
128-
url[context]=newStorageObject();
147+
url[context]=newURLContext();
129148
binding.parse(input.trim(),-1,
130149
base_context,undefined,
131150
onParseComplete.bind(url),onParseError);

0 commit comments

Comments
(0)