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: https://github.com/nodejs/node/pull/11930 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
a6e69f8c08
commit
14a91957f8
@ -3,8 +3,7 @@
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const {
|
const {
|
||||||
hexTable,
|
hexTable,
|
||||||
isHexTable,
|
isHexTable
|
||||||
StorageObject
|
|
||||||
} = require('internal/querystring');
|
} = require('internal/querystring');
|
||||||
const binding = process.binding('url');
|
const binding = process.binding('url');
|
||||||
const context = Symbol('context');
|
const context = Symbol('context');
|
||||||
@ -97,6 +96,26 @@ class TupleOrigin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This class provides the internal state of a URL object. An instance of this
|
||||||
|
// class is stored in every URL object and is accessed internally by setters
|
||||||
|
// and getters. It roughly corresponds to the concept of a URL record in the
|
||||||
|
// URL Standard, with a few differences. It is also the object transported to
|
||||||
|
// the C++ binding.
|
||||||
|
// Refs: https://url.spec.whatwg.org/#concept-url
|
||||||
|
class URLContext {
|
||||||
|
constructor() {
|
||||||
|
this.flags = 0;
|
||||||
|
this.scheme = undefined;
|
||||||
|
this.username = undefined;
|
||||||
|
this.password = undefined;
|
||||||
|
this.host = undefined;
|
||||||
|
this.port = undefined;
|
||||||
|
this.path = [];
|
||||||
|
this.query = undefined;
|
||||||
|
this.fragment = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onParseComplete(flags, protocol, username, password,
|
function onParseComplete(flags, protocol, username, password,
|
||||||
host, port, path, query, fragment) {
|
host, port, path, query, fragment) {
|
||||||
var ctx = this[context];
|
var ctx = this[context];
|
||||||
@ -125,7 +144,7 @@ function onParseError(flags, input) {
|
|||||||
// Reused by URL constructor and URL#href setter.
|
// Reused by URL constructor and URL#href setter.
|
||||||
function parse(url, input, base) {
|
function parse(url, input, base) {
|
||||||
const base_context = base ? base[context] : undefined;
|
const base_context = base ? base[context] : undefined;
|
||||||
url[context] = new StorageObject();
|
url[context] = new URLContext();
|
||||||
binding.parse(input.trim(), -1,
|
binding.parse(input.trim(), -1,
|
||||||
base_context, undefined,
|
base_context, undefined,
|
||||||
onParseComplete.bind(url), onParseError);
|
onParseComplete.bind(url), onParseError);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user