Skip to content

Commit

Permalink
url: use a class for WHATWG url[context]
Browse files Browse the repository at this point in the history
The object is used as a structure, not as a map, which `StorageObject`
was designed for.

PR-URL: #12507
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
TimothyGu authored and evanlucas committed May 1, 2017
1 parent 01b8839 commit 4b6097d
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
const util = require('util');
const {
hexTable,
isHexTable,
StorageObject
isHexTable
} = require('internal/querystring');
const binding = process.binding('url');
const context = Symbol('context');
Expand Down Expand Up @@ -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,
host, port, path, query, fragment) {
var ctx = this[context];
Expand Down Expand Up @@ -125,7 +144,7 @@ function onParseError(flags, input) {
// Reused by URL constructor and URL#href setter.
function parse(url, input, base) {
const base_context = base ? base[context] : undefined;
url[context] = new StorageObject();
url[context] = new URLContext();
binding.parse(input.trim(), -1,
base_context, undefined,
onParseComplete.bind(url), onParseError);
Expand Down

0 comments on commit 4b6097d

Please sign in to comment.