Fix #7978: Fixes ESLint yoda rule for the URL polyfill.

This commit is contained in:
Mukul Mishra 2017-01-21 22:47:28 +05:30
parent f8e793f8c2
commit 4e38200030

View File

@ -1755,8 +1755,6 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */ * http://creativecommons.org/publicdomain/zero/1.0/ */
(function checkURLConstructor(scope) { (function checkURLConstructor(scope) {
/* eslint-disable yoda */
// feature detect for URL constructor // feature detect for URL constructor
var hasWorkingUrl = false; var hasWorkingUrl = false;
try { try {
@ -1798,7 +1796,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
} }
function IDNAToASCII(h) { function IDNAToASCII(h) {
if ('' === h) { if (h === '') {
invalid.call(this); invalid.call(this);
} }
// XXX // XXX
@ -1868,7 +1866,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
case 'scheme': case 'scheme':
if (c && ALPHANUMERIC.test(c)) { if (c && ALPHANUMERIC.test(c)) {
buffer += c.toLowerCase(); // ASCII-safe buffer += c.toLowerCase(); // ASCII-safe
} else if (':' === c) { } else if (c === ':') {
this._scheme = buffer; this._scheme = buffer;
buffer = ''; buffer = '';
if (stateOverride) { if (stateOverride) {
@ -1877,7 +1875,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
if (isRelativeScheme(this._scheme)) { if (isRelativeScheme(this._scheme)) {
this._isRelative = true; this._isRelative = true;
} }
if ('file' === this._scheme) { if (this._scheme === 'file') {
state = 'relative'; state = 'relative';
} else if (this._isRelative && base && } else if (this._isRelative && base &&
base._scheme === this._scheme) { base._scheme === this._scheme) {
@ -1901,10 +1899,10 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'scheme data': case 'scheme data':
if ('?' === c) { if (c === '?') {
this._query = '?'; this._query = '?';
state = 'query'; state = 'query';
} else if ('#' === c) { } else if (c === '#') {
this._fragment = '#'; this._fragment = '#';
state = 'fragment'; state = 'fragment';
} else { } else {
@ -1926,7 +1924,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'relative or authority': case 'relative or authority':
if ('/' === c && '/' === input[cursor + 1]) { if (c === '/' && input[cursor + 1] === '/') {
state = 'authority ignore slashes'; state = 'authority ignore slashes';
} else { } else {
err('Expected /, got: ' + c); err('Expected /, got: ' + c);
@ -1948,12 +1946,12 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
this._username = base._username; this._username = base._username;
this._password = base._password; this._password = base._password;
break loop; break loop;
} else if ('/' === c || '\\' === c) { } else if (c === '/' || c === '\\') {
if ('\\' === c) { if (c === '\\') {
err('\\ is an invalid code point.'); err('\\ is an invalid code point.');
} }
state = 'relative slash'; state = 'relative slash';
} else if ('?' === c) { } else if (c === '?') {
this._host = base._host; this._host = base._host;
this._port = base._port; this._port = base._port;
this._path = base._path.slice(); this._path = base._path.slice();
@ -1961,7 +1959,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
this._username = base._username; this._username = base._username;
this._password = base._password; this._password = base._password;
state = 'query'; state = 'query';
} else if ('#' === c) { } else if (c === '#') {
this._host = base._host; this._host = base._host;
this._port = base._port; this._port = base._port;
this._path = base._path.slice(); this._path = base._path.slice();
@ -1990,11 +1988,11 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'relative slash': case 'relative slash':
if ('/' === c || '\\' === c) { if (c === '/' || c === '\\') {
if ('\\' === c) { if (c === '\\') {
err('\\ is an invalid code point.'); err('\\ is an invalid code point.');
} }
if ('file' === this._scheme) { if (this._scheme === 'file') {
state = 'file host'; state = 'file host';
} else { } else {
state = 'authority ignore slashes'; state = 'authority ignore slashes';
@ -2012,7 +2010,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'authority first slash': case 'authority first slash':
if ('/' === c) { if (c === '/') {
state = 'authority second slash'; state = 'authority second slash';
} else { } else {
err('Expected \'/\', got: ' + c); err('Expected \'/\', got: ' + c);
@ -2039,7 +2037,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'authority': case 'authority':
if ('@' === c) { if (c === '@') {
if (seenAt) { if (seenAt) {
err('@ already seen.'); err('@ already seen.');
buffer += '%40'; buffer += '%40';
@ -2047,12 +2045,12 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
seenAt = true; seenAt = true;
for (var i = 0; i < buffer.length; i++) { for (var i = 0; i < buffer.length; i++) {
var cp = buffer[i]; var cp = buffer[i];
if ('\t' === cp || '\n' === cp || '\r' === cp) { if (cp === '\t' || cp === '\n' || cp === '\r') {
err('Invalid whitespace in authority.'); err('Invalid whitespace in authority.');
continue; continue;
} }
// XXX check URL code points // XXX check URL code points
if (':' === cp && null === this._password) { if (cp === ':' && this._password === null) {
this._password = ''; this._password = '';
continue; continue;
} }
@ -2064,8 +2062,8 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
} }
} }
buffer = ''; buffer = '';
} else if (EOF === c || '/' === c || '\\' === c || } else if (c === EOF || c === '/' || c === '\\' ||
'?' === c || '#' === c) { c === '?' || c === '#') {
cursor -= buffer.length; cursor -= buffer.length;
buffer = ''; buffer = '';
state = 'host'; state = 'host';
@ -2076,7 +2074,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'file host': case 'file host':
if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) { if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
if (buffer.length === 2 && ALPHA.test(buffer[0]) && if (buffer.length === 2 && ALPHA.test(buffer[0]) &&
(buffer[1] === ':' || buffer[1] === '|')) { (buffer[1] === ':' || buffer[1] === '|')) {
state = 'relative path'; state = 'relative path';
@ -2088,7 +2086,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
state = 'relative path start'; state = 'relative path start';
} }
continue; continue;
} else if ('\t' === c || '\n' === c || '\r' === c) { } else if (c === '\t' || c === '\n' || c === '\r') {
err('Invalid whitespace in file host.'); err('Invalid whitespace in file host.');
} else { } else {
buffer += c; buffer += c;
@ -2097,16 +2095,16 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
case 'host': case 'host':
case 'hostname': case 'hostname':
if (':' === c && !seenBracket) { if (c === ':' && !seenBracket) {
// XXX host parsing // XXX host parsing
this._host = IDNAToASCII.call(this, buffer); this._host = IDNAToASCII.call(this, buffer);
buffer = ''; buffer = '';
state = 'port'; state = 'port';
if ('hostname' === stateOverride) { if (stateOverride === 'hostname') {
break loop; break loop;
} }
} else if (EOF === c || '/' === c || } else if (c === EOF || c === '/' ||
'\\' === c || '?' === c || '#' === c) { c === '\\' || c === '?' || c === '#') {
this._host = IDNAToASCII.call(this, buffer); this._host = IDNAToASCII.call(this, buffer);
buffer = ''; buffer = '';
state = 'relative path start'; state = 'relative path start';
@ -2115,9 +2113,9 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
} }
continue; continue;
} else if ('\t' !== c && '\n' !== c && '\r' !== c) { } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
if ('[' === c) { if (c === '[') {
seenBracket = true; seenBracket = true;
} else if (']' === c) { } else if (c === ']') {
seenBracket = false; seenBracket = false;
} }
buffer += c; buffer += c;
@ -2129,8 +2127,8 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
case 'port': case 'port':
if (/[0-9]/.test(c)) { if (/[0-9]/.test(c)) {
buffer += c; buffer += c;
} else if (EOF === c || '/' === c || '\\' === c || } else if (c === EOF || c === '/' || c === '\\' ||
'?' === c || '#' === c || stateOverride) { c === '?' || c === '#' || stateOverride) {
if ('' !== buffer) { if ('' !== buffer) {
var temp = parseInt(buffer, 10); var temp = parseInt(buffer, 10);
if (temp !== relative[this._scheme]) { if (temp !== relative[this._scheme]) {
@ -2143,7 +2141,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
} }
state = 'relative path start'; state = 'relative path start';
continue; continue;
} else if ('\t' === c || '\n' === c || '\r' === c) { } else if (c === '\t' || c === '\n' || c === '\r') {
err('Invalid code point in port: ' + c); err('Invalid code point in port: ' + c);
} else { } else {
invalid.call(this); invalid.call(this);
@ -2151,7 +2149,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'relative path start': case 'relative path start':
if ('\\' === c) { if (c === '\\') {
err('\'\\\' not allowed in path.'); err('\'\\\' not allowed in path.');
} }
state = 'relative path'; state = 'relative path';
@ -2161,24 +2159,24 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'relative path': case 'relative path':
if (EOF === c || '/' === c || '\\' === c || if (c === EOF || c === '/' || c === '\\' ||
(!stateOverride && ('?' === c || '#' === c))) { (!stateOverride && (c === '?' || c === '#'))) {
if ('\\' === c) { if (c === '\\') {
err('\\ not allowed in relative path.'); err('\\ not allowed in relative path.');
} }
var tmp; var tmp;
if ((tmp = relativePathDotMapping[buffer.toLowerCase()])) { if ((tmp = relativePathDotMapping[buffer.toLowerCase()])) {
buffer = tmp; buffer = tmp;
} }
if ('..' === buffer) { if (buffer === '..') {
this._path.pop(); this._path.pop();
if ('/' !== c && '\\' !== c) { if ('/' !== c && '\\' !== c) {
this._path.push(''); this._path.push('');
} }
} else if ('.' === buffer && '/' !== c && '\\' !== c) { } else if (buffer === '.' && '/' !== c && '\\' !== c) {
this._path.push(''); this._path.push('');
} else if ('.' !== buffer) { } else if ('.' !== buffer) {
if ('file' === this._scheme && this._path.length === 0 && if (this._scheme === 'file' && this._path.length === 0 &&
buffer.length === 2 && ALPHA.test(buffer[0]) && buffer.length === 2 && ALPHA.test(buffer[0]) &&
buffer[1] === '|') { buffer[1] === '|') {
buffer = buffer[0] + ':'; buffer = buffer[0] + ':';
@ -2186,10 +2184,10 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
this._path.push(buffer); this._path.push(buffer);
} }
buffer = ''; buffer = '';
if ('?' === c) { if (c === '?') {
this._query = '?'; this._query = '?';
state = 'query'; state = 'query';
} else if ('#' === c) { } else if (c === '#') {
this._fragment = '#'; this._fragment = '#';
state = 'fragment'; state = 'fragment';
} }
@ -2199,7 +2197,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
break; break;
case 'query': case 'query':
if (!stateOverride && '#' === c) { if (!stateOverride && c === '#') {
this._fragment = '#'; this._fragment = '#';
state = 'fragment'; state = 'fragment';
} else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) { } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
@ -2325,7 +2323,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
}, },
get search() { get search() {
return this._isInvalid || !this._query || '?' === this._query ? return this._isInvalid || !this._query || this._query === '?' ?
'' : this._query; '' : this._query;
}, },
set search(search) { set search(search) {
@ -2333,14 +2331,14 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
return; return;
} }
this._query = '?'; this._query = '?';
if ('?' === search[0]) { if (search[0] === '?') {
search = search.slice(1); search = search.slice(1);
} }
parse.call(this, search, 'query'); parse.call(this, search, 'query');
}, },
get hash() { get hash() {
return this._isInvalid || !this._fragment || '#' === this._fragment ? return this._isInvalid || !this._fragment || this._fragment === '#' ?
'' : this._fragment; '' : this._fragment;
}, },
set hash(hash) { set hash(hash) {
@ -2348,7 +2346,7 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
return; return;
} }
this._fragment = '#'; this._fragment = '#';
if ('#' === hash[0]) { if (hash[0] === '#') {
hash = hash.slice(1); hash = hash.slice(1);
} }
parse.call(this, hash, 'fragment'); parse.call(this, hash, 'fragment');
@ -2393,8 +2391,6 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
} }
scope.URL = JURL; scope.URL = JURL;
/* eslint-enable yoda */
})(globalScope); })(globalScope);
} }