Fix lint warnings in URL polyfill

This commit is contained in:
Yash Srivastav 2016-09-12 19:09:25 +05:30
parent 03588ccbf7
commit 4e428c7675
No known key found for this signature in database
GPG Key ID: 67A09FFAC003E189

View File

@ -1719,8 +1719,6 @@ function loadJpegStream(id, imageUrl, objs) {
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
(function checkURLConstructor(scope) {
/* jshint ignore:start */
// feature detect for URL constructor
var hasWorkingUrl = false;
try {
@ -1733,8 +1731,9 @@ function loadJpegStream(id, imageUrl, objs) {
}
} catch(e) { }
if (hasWorkingUrl)
if (hasWorkingUrl) {
return;
}
var relative = Object.create(null);
relative['ftp'] = 21;
@ -1761,11 +1760,11 @@ function loadJpegStream(id, imageUrl, objs) {
}
function IDNAToASCII(h) {
if ('' == h) {
invalid.call(this)
if ('' === h) {
invalid.call(this);
}
// XXX
return h.toLowerCase()
return h.toLowerCase();
}
function percentEscape(c) {
@ -1773,7 +1772,7 @@ function loadJpegStream(id, imageUrl, objs) {
if (unicode > 0x20 &&
unicode < 0x7F &&
// " # < > ? `
[0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
[0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1
) {
return c;
}
@ -1788,20 +1787,19 @@ function loadJpegStream(id, imageUrl, objs) {
if (unicode > 0x20 &&
unicode < 0x7F &&
// " # < > ` (do not escape '?')
[0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
[0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1
) {
return c;
}
return encodeURIComponent(c);
}
var EOF = undefined,
ALPHA = /[a-zA-Z]/,
var EOF, ALPHA = /[a-zA-Z]/,
ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
function parse(input, stateOverride, base) {
function err(message) {
errors.push(message)
errors.push(message);
}
var state = stateOverride || 'scheme start',
@ -1811,7 +1809,8 @@ function loadJpegStream(id, imageUrl, objs) {
seenBracket = false,
errors = [];
loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
loop: while ((input[cursor - 1] !== EOF || cursor === 0) &&
!this._isInvalid) {
var c = input[cursor];
switch (state) {
case 'scheme start':
@ -1831,7 +1830,7 @@ function loadJpegStream(id, imageUrl, objs) {
case 'scheme':
if (c && ALPHANUMERIC.test(c)) {
buffer += c.toLowerCase(); // ASCII-safe
} else if (':' == c) {
} else if (':' === c) {
this._scheme = buffer;
buffer = '';
if (stateOverride) {
@ -1840,9 +1839,10 @@ function loadJpegStream(id, imageUrl, objs) {
if (isRelativeScheme(this._scheme)) {
this._isRelative = true;
}
if ('file' == this._scheme) {
if ('file' === this._scheme) {
state = 'relative';
} else if (this._isRelative && base && base._scheme == this._scheme) {
} else if (this._isRelative && base &&
base._scheme === this._scheme) {
state = 'relative or authority';
} else if (this._isRelative) {
state = 'authority first slash';
@ -1854,24 +1854,24 @@ function loadJpegStream(id, imageUrl, objs) {
cursor = 0;
state = 'no scheme';
continue;
} else if (EOF == c) {
} else if (EOF === c) {
break loop;
} else {
err('Code point not allowed in scheme: ' + c)
err('Code point not allowed in scheme: ' + c);
break loop;
}
break;
case 'scheme data':
if ('?' == c) {
if ('?' === c) {
this._query = '?';
state = 'query';
} else if ('#' == c) {
} else if ('#' === c) {
this._fragment = '#';
state = 'fragment';
} else {
// XXX error handling
if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
this._schemeData += percentEscape(c);
}
}
@ -1888,20 +1888,21 @@ function loadJpegStream(id, imageUrl, objs) {
break;
case 'relative or authority':
if ('/' == c && '/' == input[cursor+1]) {
if ('/' === c && '/' === input[cursor+1]) {
state = 'authority ignore slashes';
} else {
err('Expected /, got: ' + c);
state = 'relative';
continue
continue;
}
break;
case 'relative':
this._isRelative = true;
if ('file' != this._scheme)
if ('file' !== this._scheme) {
this._scheme = base._scheme;
if (EOF == c) {
}
if (EOF === c) {
this._host = base._host;
this._port = base._port;
this._path = base._path.slice();
@ -1909,11 +1910,12 @@ function loadJpegStream(id, imageUrl, objs) {
this._username = base._username;
this._password = base._password;
break loop;
} else if ('/' == c || '\\' == c) {
if ('\\' == c)
} else if ('/' === c || '\\' === c) {
if ('\\' === c) {
err('\\ is an invalid code point.');
}
state = 'relative slash';
} else if ('?' == c) {
} else if ('?' === c) {
this._host = base._host;
this._port = base._port;
this._path = base._path.slice();
@ -1921,7 +1923,7 @@ function loadJpegStream(id, imageUrl, objs) {
this._username = base._username;
this._password = base._password;
state = 'query';
} else if ('#' == c) {
} else if ('#' === c) {
this._host = base._host;
this._port = base._port;
this._path = base._path.slice();
@ -1931,12 +1933,12 @@ function loadJpegStream(id, imageUrl, objs) {
this._password = base._password;
state = 'fragment';
} else {
var nextC = input[cursor+1]
var nextNextC = input[cursor+2]
if (
'file' != this._scheme || !ALPHA.test(c) ||
(nextC != ':' && nextC != '|') ||
(EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
var nextC = input[cursor+1];
var nextNextC = input[cursor+2];
if ('file' !== this._scheme || !ALPHA.test(c) ||
(nextC !== ':' && nextC !== '|') ||
(EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC &&
'?' !== nextNextC && '#' !== nextNextC)) {
this._host = base._host;
this._port = base._port;
this._username = base._username;
@ -1950,17 +1952,17 @@ function loadJpegStream(id, imageUrl, objs) {
break;
case 'relative slash':
if ('/' == c || '\\' == c) {
if ('\\' == c) {
if ('/' === c || '\\' === c) {
if ('\\' === c) {
err('\\ is an invalid code point.');
}
if ('file' == this._scheme) {
if ('file' === this._scheme) {
state = 'file host';
} else {
state = 'authority ignore slashes';
}
} else {
if ('file' != this._scheme) {
if ('file' !== this._scheme) {
this._host = base._host;
this._port = base._port;
this._username = base._username;
@ -1972,10 +1974,10 @@ function loadJpegStream(id, imageUrl, objs) {
break;
case 'authority first slash':
if ('/' == c) {
if ('/' === c) {
state = 'authority second slash';
} else {
err("Expected '/', got: " + c);
err('Expected \'/\', got: ' + c);
state = 'authority ignore slashes';
continue;
}
@ -1983,14 +1985,14 @@ function loadJpegStream(id, imageUrl, objs) {
case 'authority second slash':
state = 'authority ignore slashes';
if ('/' != c) {
err("Expected '/', got: " + c);
if ('/' !== c) {
err('Expected \'/\', got: ' + c);
continue;
}
break;
case 'authority ignore slashes':
if ('/' != c && '\\' != c) {
if ('/' !== c && '\\' !== c) {
state = 'authority';
continue;
} else {
@ -1999,7 +2001,7 @@ function loadJpegStream(id, imageUrl, objs) {
break;
case 'authority':
if ('@' == c) {
if ('@' === c) {
if (seenAt) {
err('@ already seen.');
buffer += '%40';
@ -2007,20 +2009,25 @@ function loadJpegStream(id, imageUrl, objs) {
seenAt = true;
for (var i = 0; i < buffer.length; i++) {
var cp = buffer[i];
if ('\t' == cp || '\n' == cp || '\r' == cp) {
if ('\t' === cp || '\n' === cp || '\r' === cp) {
err('Invalid whitespace in authority.');
continue;
}
// XXX check URL code points
if (':' == cp && null === this._password) {
if (':' === cp && null === this._password) {
this._password = '';
continue;
}
var tempC = percentEscape(cp);
(null !== this._password) ? this._password += tempC : this._username += tempC;
if (null !== this._password) {
this._password += tempC;
} else {
this._username += tempC;
}
}
buffer = '';
} else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
} else if (EOF === c || '/' === c || '\\' === c ||
'?' === c || '#' === c) {
cursor -= buffer.length;
buffer = '';
state = 'host';
@ -2031,10 +2038,11 @@ function loadJpegStream(id, imageUrl, objs) {
break;
case 'file host':
if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
if (buffer.length === 2 && ALPHA.test(buffer[0]) &&
(buffer[1] === ':' || buffer[1] === '|')) {
state = 'relative path';
} else if (buffer.length == 0) {
} else if (buffer.length === 0) {
state = 'relative path start';
} else {
this._host = IDNAToASCII.call(this, buffer);
@ -2042,7 +2050,7 @@ function loadJpegStream(id, imageUrl, objs) {
state = 'relative path start';
}
continue;
} else if ('\t' == c || '\n' == c || '\r' == c) {
} else if ('\t' === c || '\n' === c || '\r' === c) {
err('Invalid whitespace in file host.');
} else {
buffer += c;
@ -2051,15 +2059,16 @@ function loadJpegStream(id, imageUrl, objs) {
case 'host':
case 'hostname':
if (':' == c && !seenBracket) {
if (':' === c && !seenBracket) {
// XXX host parsing
this._host = IDNAToASCII.call(this, buffer);
buffer = '';
state = 'port';
if ('hostname' == stateOverride) {
if ('hostname' === stateOverride) {
break loop;
}
} else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
} else if (EOF === c || '/' === c ||
'\\' === c || '?' === c || '#' === c) {
this._host = IDNAToASCII.call(this, buffer);
buffer = '';
state = 'relative path start';
@ -2067,10 +2076,10 @@ function loadJpegStream(id, imageUrl, objs) {
break loop;
}
continue;
} else if ('\t' != c && '\n' != c && '\r' != c) {
if ('[' == c) {
} else if ('\t' !== c && '\n' !== c && '\r' !== c) {
if ('[' === c) {
seenBracket = true;
} else if (']' == c) {
} else if (']' === c) {
seenBracket = false;
}
buffer += c;
@ -2082,10 +2091,11 @@ function loadJpegStream(id, imageUrl, objs) {
case 'port':
if (/[0-9]/.test(c)) {
buffer += c;
} else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
if ('' != buffer) {
} else if (EOF === c || '/' === c || '\\' === c ||
'?' === c || '#' === c || stateOverride) {
if ('' !== buffer) {
var temp = parseInt(buffer, 10);
if (temp != relative[this._scheme]) {
if (temp !== relative[this._scheme]) {
this._port = temp + '';
}
buffer = '';
@ -2095,7 +2105,7 @@ function loadJpegStream(id, imageUrl, objs) {
}
state = 'relative path start';
continue;
} else if ('\t' == c || '\n' == c || '\r' == c) {
} else if ('\t' === c || '\n' === c || '\r' === c) {
err('Invalid code point in port: ' + c);
} else {
invalid.call(this);
@ -2103,60 +2113,64 @@ function loadJpegStream(id, imageUrl, objs) {
break;
case 'relative path start':
if ('\\' == c)
err("'\\' not allowed in path.");
if ('\\' === c) {
err('\'\\\' not allowed in path.');
}
state = 'relative path';
if ('/' != c && '\\' != c) {
if ('/' !== c && '\\' !== c) {
continue;
}
break;
case 'relative path':
if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
if ('\\' == c) {
if (EOF === c || '/' === c || '\\' === c ||
(!stateOverride && ('?' === c || '#' === c))) {
if ('\\' === c) {
err('\\ not allowed in relative path.');
}
var tmp;
if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
buffer = tmp;
}
if ('..' == buffer) {
if ('..' === buffer) {
this._path.pop();
if ('/' != c && '\\' != c) {
if ('/' !== c && '\\' !== c) {
this._path.push('');
}
} else if ('.' == buffer && '/' != c && '\\' != c) {
} else if ('.' === buffer && '/' !== c && '\\' !== c) {
this._path.push('');
} else if ('.' != buffer) {
if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
} else if ('.' !== buffer) {
if ('file' === this._scheme && this._path.length === 0 &&
buffer.length === 2 && ALPHA.test(buffer[0]) &&
buffer[1] === '|') {
buffer = buffer[0] + ':';
}
this._path.push(buffer);
}
buffer = '';
if ('?' == c) {
if ('?' === c) {
this._query = '?';
state = 'query';
} else if ('#' == c) {
} else if ('#' === c) {
this._fragment = '#';
state = 'fragment';
}
} else if ('\t' != c && '\n' != c && '\r' != c) {
} else if ('\t' !== c && '\n' !== c && '\r' !== c) {
buffer += percentEscape(c);
}
break;
case 'query':
if (!stateOverride && '#' == c) {
if (!stateOverride && '#' === c) {
this._fragment = '#';
state = 'fragment';
} else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
} else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
this._query += percentEscapeQuery(c);
}
break;
case 'fragment':
if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
this._fragment += c;
}
break;
@ -2182,9 +2196,10 @@ function loadJpegStream(id, imageUrl, objs) {
// Does not process domain names or IP addresses.
// Does not handle encoding for the query parameter.
function jURL(url, base /* , encoding */) {
if (base !== undefined && !(base instanceof jURL))
base = new jURL(String(base));
function JURL(url, base /* , encoding */) {
if (base !== undefined && !(base instanceof JURL)) {
base = new JURL(String(base));
}
this._url = url;
clear.call(this);
@ -2195,18 +2210,18 @@ function loadJpegStream(id, imageUrl, objs) {
parse.call(this, input, null, base);
}
jURL.prototype = {
JURL.prototype = {
toString: function() {
return this.href;
},
get href() {
if (this._isInvalid)
if (this._isInvalid) {
return this._url;
}
var authority = '';
if ('' != this._username || null != this._password) {
if ('' !== this._username || null !== this._password) {
authority = this._username +
(null != this._password ? ':' + this._password : '') + '@';
(null !== this._password ? ':' + this._password : '') + '@';
}
return this.protocol +
@ -2222,8 +2237,9 @@ function loadJpegStream(id, imageUrl, objs) {
return this._scheme + ':';
},
set protocol(protocol) {
if (this._isInvalid)
if (this._isInvalid) {
return;
}
parse.call(this, protocol + ':', 'scheme start');
},
@ -2232,8 +2248,9 @@ function loadJpegStream(id, imageUrl, objs) {
this._host + ':' + this._port : this._host;
},
set host(host) {
if (this._isInvalid || !this._isRelative)
if (this._isInvalid || !this._isRelative) {
return;
}
parse.call(this, host, 'host');
},
@ -2241,8 +2258,9 @@ function loadJpegStream(id, imageUrl, objs) {
return this._host;
},
set hostname(hostname) {
if (this._isInvalid || !this._isRelative)
if (this._isInvalid || !this._isRelative) {
return;
}
parse.call(this, hostname, 'hostname');
},
@ -2250,8 +2268,9 @@ function loadJpegStream(id, imageUrl, objs) {
return this._port;
},
set port(port) {
if (this._isInvalid || !this._isRelative)
if (this._isInvalid || !this._isRelative) {
return;
}
parse.call(this, port, 'port');
},
@ -2260,35 +2279,40 @@ function loadJpegStream(id, imageUrl, objs) {
'/' + this._path.join('/') : this._schemeData;
},
set pathname(pathname) {
if (this._isInvalid || !this._isRelative)
if (this._isInvalid || !this._isRelative) {
return;
}
this._path = [];
parse.call(this, pathname, 'relative path start');
},
get search() {
return this._isInvalid || !this._query || '?' == this._query ?
return this._isInvalid || !this._query || '?' === this._query ?
'' : this._query;
},
set search(search) {
if (this._isInvalid || !this._isRelative)
if (this._isInvalid || !this._isRelative) {
return;
}
this._query = '?';
if ('?' == search[0])
if ('?' === search[0]) {
search = search.slice(1);
}
parse.call(this, search, 'query');
},
get hash() {
return this._isInvalid || !this._fragment || '#' == this._fragment ?
return this._isInvalid || !this._fragment || '#' === this._fragment ?
'' : this._fragment;
},
set hash(hash) {
if (this._isInvalid)
if (this._isInvalid) {
return;
}
this._fragment = '#';
if ('#' == hash[0])
if ('#' === hash[0]) {
hash = hash.slice(1);
}
parse.call(this, hash, 'fragment');
},
@ -2320,18 +2344,17 @@ function loadJpegStream(id, imageUrl, objs) {
// Copy over the static methods
var OriginalURL = scope.URL;
if (OriginalURL) {
jURL.createObjectURL = function(blob) {
JURL.createObjectURL = function(blob) {
// IE extension allows a second optional options argument.
// http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
};
jURL.revokeObjectURL = function(url) {
JURL.revokeObjectURL = function(url) {
OriginalURL.revokeObjectURL(url);
};
}
scope.URL = jURL;
/* jshint ignore:end */
scope.URL = JURL;
})(globalScope);
//#endif