url: fix lint and deopt issues
The deopt issues arose from the use of const in specific situations that v8 does not fully support yet. Fixes: https://github.com/nodejs/node/issues/5299 PR-URL: https://github.com/nodejs/node/pull/5300 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
ff0d339324
commit
7d1d3a6621
48
lib/url.js
48
lib/url.js
@ -81,17 +81,18 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
var end = -1;
|
var end = -1;
|
||||||
var rest = '';
|
var rest = '';
|
||||||
var lastPos = 0;
|
var lastPos = 0;
|
||||||
for (var i = 0, inWs = false, split = false; i < url.length; ++i) {
|
var i = 0;
|
||||||
var code = url.charCodeAt(i);
|
for (var inWs = false, split = false; i < url.length; ++i) {
|
||||||
|
const code = url.charCodeAt(i);
|
||||||
|
|
||||||
// Find first and last non-whitespace characters for trimming
|
// Find first and last non-whitespace characters for trimming
|
||||||
var isWs = code === 32/* */ ||
|
const isWs = code === 32/* */ ||
|
||||||
code === 9/*\t*/ ||
|
code === 9/*\t*/ ||
|
||||||
code === 13/*\r*/ ||
|
code === 13/*\r*/ ||
|
||||||
code === 10/*\n*/ ||
|
code === 10/*\n*/ ||
|
||||||
code === 12/*\f*/ ||
|
code === 12/*\f*/ ||
|
||||||
code === 160/*\u00A0*/ ||
|
code === 160/*\u00A0*/ ||
|
||||||
code === 65279/*\uFEFF*/;
|
code === 65279/*\uFEFF*/;
|
||||||
if (start === -1) {
|
if (start === -1) {
|
||||||
if (isWs)
|
if (isWs)
|
||||||
continue;
|
continue;
|
||||||
@ -153,7 +154,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
|
|
||||||
if (!slashesDenoteHost && !hasHash) {
|
if (!slashesDenoteHost && !hasHash) {
|
||||||
// Try fast path regexp
|
// Try fast path regexp
|
||||||
var simplePath = simplePathPattern.exec(rest);
|
const simplePath = simplePathPattern.exec(rest);
|
||||||
if (simplePath) {
|
if (simplePath) {
|
||||||
this.path = rest;
|
this.path = rest;
|
||||||
this.href = rest;
|
this.href = rest;
|
||||||
@ -215,7 +216,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
var hostEnd = -1;
|
var hostEnd = -1;
|
||||||
var atSign = -1;
|
var atSign = -1;
|
||||||
var nonHost = -1;
|
var nonHost = -1;
|
||||||
for (var i = 0; i < rest.length; ++i) {
|
for (i = 0; i < rest.length; ++i) {
|
||||||
switch (rest.charCodeAt(i)) {
|
switch (rest.charCodeAt(i)) {
|
||||||
case 9: // '\t'
|
case 9: // '\t'
|
||||||
case 10: // '\n'
|
case 10: // '\n'
|
||||||
@ -255,7 +256,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
if (hostEnd !== -1)
|
if (hostEnd !== -1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var start = 0;
|
start = 0;
|
||||||
if (atSign !== -1) {
|
if (atSign !== -1) {
|
||||||
this.auth = decodeURIComponent(rest.slice(0, atSign));
|
this.auth = decodeURIComponent(rest.slice(0, atSign));
|
||||||
start = atSign + 1;
|
start = atSign + 1;
|
||||||
@ -284,9 +285,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
hostname.charCodeAt(hostname.length - 1) === 93/*]*/;
|
hostname.charCodeAt(hostname.length - 1) === 93/*]*/;
|
||||||
|
|
||||||
// validate a little.
|
// validate a little.
|
||||||
var result;
|
|
||||||
if (!ipv6Hostname) {
|
if (!ipv6Hostname) {
|
||||||
result = validateHostname(this, rest, hostname);
|
const result = validateHostname(this, rest, hostname);
|
||||||
if (result !== undefined)
|
if (result !== undefined)
|
||||||
rest = result;
|
rest = result;
|
||||||
}
|
}
|
||||||
@ -326,15 +326,15 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
// First, make 100% sure that any "autoEscape" chars get
|
// First, make 100% sure that any "autoEscape" chars get
|
||||||
// escaped, even if encodeURIComponent doesn't think they
|
// escaped, even if encodeURIComponent doesn't think they
|
||||||
// need to be.
|
// need to be.
|
||||||
result = autoEscapeStr(rest);
|
const result = autoEscapeStr(rest);
|
||||||
if (result !== undefined)
|
if (result !== undefined)
|
||||||
rest = result;
|
rest = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var questionIdx = -1;
|
var questionIdx = -1;
|
||||||
var hashIdx = -1;
|
var hashIdx = -1;
|
||||||
for (var i = 0; i < rest.length; ++i) {
|
for (i = 0; i < rest.length; ++i) {
|
||||||
var code = rest.charCodeAt(i);
|
const code = rest.charCodeAt(i);
|
||||||
if (code === 35/*#*/) {
|
if (code === 35/*#*/) {
|
||||||
this.hash = rest.slice(i);
|
this.hash = rest.slice(i);
|
||||||
hashIdx = i;
|
hashIdx = i;
|
||||||
@ -378,8 +378,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
|
|
||||||
// to support http.request
|
// to support http.request
|
||||||
if (this.pathname || this.search) {
|
if (this.pathname || this.search) {
|
||||||
var p = this.pathname || '';
|
const p = this.pathname || '';
|
||||||
var s = this.search || '';
|
const s = this.search || '';
|
||||||
this.path = p + s;
|
this.path = p + s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,17 +720,17 @@ Url.prototype.resolveObject = function(relative) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/');
|
var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/');
|
||||||
const isRelAbs = (
|
var isRelAbs = (
|
||||||
relative.host ||
|
relative.host ||
|
||||||
relative.pathname && relative.pathname.charAt(0) === '/'
|
relative.pathname && relative.pathname.charAt(0) === '/'
|
||||||
);
|
);
|
||||||
var mustEndAbs = (isRelAbs || isSourceAbs ||
|
var mustEndAbs = (isRelAbs || isSourceAbs ||
|
||||||
(result.host && relative.pathname));
|
(result.host && relative.pathname));
|
||||||
const removeAllDots = mustEndAbs;
|
var removeAllDots = mustEndAbs;
|
||||||
var srcPath = result.pathname && result.pathname.split('/') || [];
|
var srcPath = result.pathname && result.pathname.split('/') || [];
|
||||||
const relPath = relative.pathname && relative.pathname.split('/') || [];
|
var relPath = relative.pathname && relative.pathname.split('/') || [];
|
||||||
const psychotic = result.protocol && !slashedProtocol[result.protocol];
|
var psychotic = result.protocol && !slashedProtocol[result.protocol];
|
||||||
|
|
||||||
// if the url is a non-slashed url, then relative
|
// if the url is a non-slashed url, then relative
|
||||||
// links like ../.. should be able
|
// links like ../.. should be able
|
||||||
|
Loading…
x
Reference in New Issue
Block a user