Enable the consistent-return ESLint rule

This rule is already enabled in mozilla-central, and helps ensure more consistent functions/methods, see https://searchfox.org/mozilla-central/rev/b9da45f63cb567244933c77b2c7e827a057d3f9b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#119-120

Please see https://eslint.org/docs/rules/consistent-return for additional information.
This commit is contained in:
Jonas Jenwald 2019-05-10 12:54:06 +02:00
parent ca2fee3d51
commit 173fbef05b
26 changed files with 105 additions and 55 deletions

View File

@ -57,6 +57,7 @@
// Best Practices // Best Practices
"accessor-pairs": ["error", { "setWithoutGet": true, }], "accessor-pairs": ["error", { "setWithoutGet": true, }],
"consistent-return": "error",
"curly": ["error", "all"], "curly": ["error", "all"],
"eqeqeq": ["error", "always"], "eqeqeq": ["error", "always"],
"no-caller": "error", "no-caller": "error",

View File

@ -43,7 +43,7 @@ limitations under the License.
// Find the (url-encoded) colon and verify that the scheme is whitelisted. // Find the (url-encoded) colon and verify that the scheme is whitelisted.
var schemeIndex = url.search(/:|%3A/i); var schemeIndex = url.search(/:|%3A/i);
if (schemeIndex === -1) { if (schemeIndex === -1) {
return; return undefined;
} }
var scheme = url.slice(0, schemeIndex).toLowerCase(); var scheme = url.slice(0, schemeIndex).toLowerCase();
if (schemes.includes(scheme)) { if (schemes.includes(scheme)) {
@ -53,6 +53,7 @@ limitations under the License.
} }
return url; return url;
} }
return undefined;
} }
// TODO(rob): Use declarativeWebRequest once declared URL-encoding is // TODO(rob): Use declarativeWebRequest once declared URL-encoding is
@ -72,6 +73,7 @@ limitations under the License.
console.log('Redirecting ' + details.url + ' to ' + url); console.log('Redirecting ' + details.url + ' to ' + url);
return { redirectUrl: url, }; return { redirectUrl: url, };
} }
return undefined;
}, { }, {
types: ['main_frame', 'sub_frame'], types: ['main_frame', 'sub_frame'],
urls: schemes.map(function(scheme) { urls: schemes.map(function(scheme) {

View File

@ -59,6 +59,7 @@ function getHeaderFromHeaders(headers, headerName) {
return header; return header;
} }
} }
return undefined;
} }
/** /**
@ -86,6 +87,7 @@ function isPdfFile(details) {
} }
} }
} }
return false;
} }
/** /**
@ -108,16 +110,17 @@ function getHeadersWithContentDispositionAttachment(details) {
cdHeader.value = 'attachment' + cdHeader.value.replace(/^[^;]+/i, ''); cdHeader.value = 'attachment' + cdHeader.value.replace(/^[^;]+/i, '');
return { responseHeaders: headers, }; return { responseHeaders: headers, };
} }
return undefined;
} }
chrome.webRequest.onHeadersReceived.addListener( chrome.webRequest.onHeadersReceived.addListener(
function(details) { function(details) {
if (details.method !== 'GET') { if (details.method !== 'GET') {
// Don't intercept POST requests until http://crbug.com/104058 is fixed. // Don't intercept POST requests until http://crbug.com/104058 is fixed.
return; return undefined;
} }
if (!isPdfFile(details)) { if (!isPdfFile(details)) {
return; return undefined;
} }
if (isPdfDownloadable(details)) { if (isPdfDownloadable(details)) {
// Force download by ensuring that Content-Disposition: attachment is set // Force download by ensuring that Content-Disposition: attachment is set
@ -142,7 +145,7 @@ chrome.webRequest.onHeadersReceived.addListener(
chrome.webRequest.onBeforeRequest.addListener( chrome.webRequest.onBeforeRequest.addListener(
function(details) { function(details) {
if (isPdfDownloadable(details)) { if (isPdfDownloadable(details)) {
return; return undefined;
} }
var viewerUrl = getViewerURL(details.url); var viewerUrl = getViewerURL(details.url);
@ -200,7 +203,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
// sensitive (local) file in a frame. // sensitive (local) file in a frame.
if (!sender.tab) { if (!sender.tab) {
sendResponse(''); sendResponse('');
return; return undefined;
} }
// TODO: This should be the URL of the parent frame, not the tab. But // TODO: This should be the URL of the parent frame, not the tab. But
// chrome-extension:-URLs are not visible in the webNavigation API // chrome-extension:-URLs are not visible in the webNavigation API
@ -209,11 +212,11 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
var parentUrl = sender.tab.url; var parentUrl = sender.tab.url;
if (!parentUrl) { if (!parentUrl) {
sendResponse(''); sendResponse('');
return; return undefined;
} }
if (parentUrl.lastIndexOf('file:', 0) === 0) { if (parentUrl.lastIndexOf('file:', 0) === 0) {
sendResponse('file://'); sendResponse('file://');
return; return undefined;
} }
// The regexp should always match for valid URLs, but in case it doesn't, // The regexp should always match for valid URLs, but in case it doesn't,
// just give the full URL (e.g. data URLs). // just give the full URL (e.g. data URLs).
@ -240,6 +243,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
}); });
} }
} }
return undefined;
}); });
// Remove keys from storage that were once part of the deleted feature-detect.js // Remove keys from storage that were once part of the deleted feature-detect.js

View File

@ -130,7 +130,7 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
function onBeforeSendHeaders(details) { function onBeforeSendHeaders(details) {
if (details.frameId !== frameId) { if (details.frameId !== frameId) {
return; return undefined;
} }
var headers = details.requestHeaders; var headers = details.requestHeaders;
var refererHeader = getHeaderFromHeaders(headers, 'referer'); var refererHeader = getHeaderFromHeaders(headers, 'referer');
@ -141,7 +141,7 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
refererHeader.value.lastIndexOf('chrome-extension:', 0) !== 0) { refererHeader.value.lastIndexOf('chrome-extension:', 0) !== 0) {
// Sanity check. If the referer is set, and the value is not the URL of // Sanity check. If the referer is set, and the value is not the URL of
// this extension, then the request was not initiated by this extension. // this extension, then the request was not initiated by this extension.
return; return undefined;
} }
refererHeader.value = referer; refererHeader.value = referer;
return { requestHeaders: headers, }; return { requestHeaders: headers, };
@ -149,7 +149,7 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
function exposeOnHeadersReceived(details) { function exposeOnHeadersReceived(details) {
if (details.frameId !== frameId) { if (details.frameId !== frameId) {
return; return undefined;
} }
var headers = details.responseHeaders; var headers = details.responseHeaders;
var aceh = getHeaderFromHeaders(headers, 'access-control-expose-headers'); var aceh = getHeaderFromHeaders(headers, 'access-control-expose-headers');

View File

@ -19,7 +19,7 @@
var preprocessor2 = require('../builder/preprocessor2.js'); var preprocessor2 = require('../builder/preprocessor2.js');
var path = require('path'); var path = require('path');
module.exports = function (source) { module.exports = function(source) {
// Options must be specified, ignoring request if not. // Options must be specified, ignoring request if not.
if (!this.query || typeof this.query !== 'object') { if (!this.query || typeof this.query !== 'object') {
return source; return source;
@ -40,4 +40,5 @@ module.exports = function (source) {
// escodegen does not embed source -- setting map's sourcesContent. // escodegen does not embed source -- setting map's sourcesContent.
map.sourcesContent = [source]; map.sourcesContent = [source];
callback(null, sourceAndMap.code, map); callback(null, sourceAndMap.code, map);
return undefined;
}; };

View File

@ -365,7 +365,7 @@ function getTempFile(prefix, suffix) {
function createTestSource(testsName, bot) { function createTestSource(testsName, bot) {
var source = stream.Readable({ objectMode: true, }); var source = stream.Readable({ objectMode: true, });
source._read = function () { source._read = function() {
console.log(); console.log();
console.log('### Running ' + testsName + ' tests'); console.log('### Running ' + testsName + ' tests');
@ -409,6 +409,7 @@ function createTestSource(testsName, bot) {
testProcess.on('close', function (code) { testProcess.on('close', function (code) {
source.push(null); source.push(null);
}); });
return undefined;
}; };
return source; return source;
} }
@ -1245,9 +1246,10 @@ gulp.task('gh-pages-prepare', function () {
gulp.task('wintersmith', function (done) { gulp.task('wintersmith', function (done) {
var wintersmith = require('wintersmith'); var wintersmith = require('wintersmith');
var env = wintersmith('docs/config.json'); var env = wintersmith('docs/config.json');
env.build(GH_PAGES_DIR, function (error) { env.build(GH_PAGES_DIR, function(error) {
if (error) { if (error) {
return done(error); done(error);
return;
} }
replaceInFile(GH_PAGES_DIR + '/getting_started/index.html', replaceInFile(GH_PAGES_DIR + '/getting_started/index.html',
/STABLE_VERSION/g, config.stableVersion); /STABLE_VERSION/g, config.stableVersion);

View File

@ -48,7 +48,7 @@ class AnnotationFactory {
static _create(xref, ref, pdfManager, idFactory) { static _create(xref, ref, pdfManager, idFactory) {
let dict = xref.fetchIfRef(ref); let dict = xref.fetchIfRef(ref);
if (!isDict(dict)) { if (!isDict(dict)) {
return; return undefined;
} }
let id = isRef(ref) ? ref.toString() : `annot_${idFactory.createObjId()}`; let id = isRef(ref) ? ref.toString() : `annot_${idFactory.createObjId()}`;
@ -432,7 +432,7 @@ class Annotation {
loadResources(keys) { loadResources(keys) {
return this.appearance.dict.getAsync('Resources').then((resources) => { return this.appearance.dict.getAsync('Resources').then((resources) => {
if (!resources) { if (!resources) {
return; return undefined;
} }
let objectLoader = new ObjectLoader(resources, keys, resources.xref); let objectLoader = new ObjectLoader(resources, keys, resources.xref);

View File

@ -302,12 +302,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (!(w && isNum(w)) || !(h && isNum(h))) { if (!(w && isNum(w)) || !(h && isNum(h))) {
warn('Image dimensions are missing, or not numbers.'); warn('Image dimensions are missing, or not numbers.');
return; return undefined;
} }
var maxImageSize = this.options.maxImageSize; var maxImageSize = this.options.maxImageSize;
if (maxImageSize !== -1 && w * h > maxImageSize) { if (maxImageSize !== -1 && w * h > maxImageSize) {
warn('Image exceeded maximum allowed size and was removed.'); warn('Image exceeded maximum allowed size and was removed.');
return; return undefined;
} }
var imageMask = (dict.get('ImageMask', 'IM') || false); var imageMask = (dict.get('ImageMask', 'IM') || false);
@ -343,7 +343,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
args, args,
}; };
} }
return; return undefined;
} }
var softMask = (dict.get('SMask', 'SM') || false); var softMask = (dict.get('SMask', 'SM') || false);
@ -364,7 +364,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// any other kind. // any other kind.
imgData = imageObj.createImageData(/* forceRGBA = */ true); imgData = imageObj.createImageData(/* forceRGBA = */ true);
operatorList.addOp(OPS.paintInlineImageXObject, [imgData]); operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
return; return undefined;
} }
const nativeImageDecoderSupport = forceDisableNativeImageDecoder ? const nativeImageDecoderSupport = forceDisableNativeImageDecoder ?
@ -452,6 +452,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} }
this.handler.send('obj', [objId, this.pageIndex, 'Image', imgData], this.handler.send('obj', [objId, this.pageIndex, 'Image', imgData],
[imgData.data.buffer]); [imgData.data.buffer]);
return undefined;
}).catch((reason) => { }).catch((reason) => {
warn('Unable to decode image: ' + reason); warn('Unable to decode image: ' + reason);
@ -460,6 +461,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
[objId, 'FontType3Res', null]); [objId, 'FontType3Res', null]);
} }
this.handler.send('obj', [objId, this.pageIndex, 'Image', null]); this.handler.send('obj', [objId, this.pageIndex, 'Image', null]);
return undefined;
}); });
if (this.parsingType3Font) { if (this.parsingType3Font) {
@ -476,6 +478,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
args, args,
}; };
} }
return undefined;
}, },
handleSMask: function PartialEvaluator_handleSmask(smask, resources, handleSMask: function PartialEvaluator_handleSmask(smask, resources,

View File

@ -973,6 +973,7 @@ var JpegImage = (function JpegImageClosure() {
}); });
} }
this.numComponents = this.components.length; this.numComponents = this.components.length;
return undefined;
}, },
_getLinearizedBlockData(width, height, isSourcePDF = false) { _getLinearizedBlockData(width, height, isSourcePDF = false) {

View File

@ -266,6 +266,7 @@ class Catalog {
} else if (this.catDict.has('Dests')) { // Simple destination dictionary. } else if (this.catDict.has('Dests')) { // Simple destination dictionary.
return this.catDict.get('Dests'); return this.catDict.get('Dests');
} }
return undefined;
} }
get pageLabels() { get pageLabels() {
@ -1596,7 +1597,7 @@ var XRef = (function XRefClosure() {
} }
if (recoveryMode) { if (recoveryMode) {
return; return undefined;
} }
throw new XRefParseException(); throw new XRefParseException();
}, },

View File

@ -71,6 +71,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
case 3: case 3:
return fnArray[i] === OPS.restore; return fnArray[i] === OPS.restore;
} }
throw new Error(`iterateInlineImageGroup - invalid pos: ${pos}`);
}, },
function foundInlineImageGroup(context, i) { function foundInlineImageGroup(context, i) {
var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10; var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
@ -173,6 +174,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
case 3: case 3:
return fnArray[i] === OPS.restore; return fnArray[i] === OPS.restore;
} }
throw new Error(`iterateImageMaskGroup - invalid pos: ${pos}`);
}, },
function foundImageMaskGroup(context, i) { function foundImageMaskGroup(context, i) {
var MIN_IMAGES_IN_MASKS_BLOCK = 10; var MIN_IMAGES_IN_MASKS_BLOCK = 10;
@ -266,7 +268,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
return argsArray[iFirstTransform][1] === 0 && return argsArray[iFirstTransform][1] === 0 &&
argsArray[iFirstTransform][2] === 0; argsArray[iFirstTransform][2] === 0;
}, },
function (context, i) { function iterateImageGroup(context, i) {
var fnArray = context.fnArray, argsArray = context.argsArray; var fnArray = context.fnArray, argsArray = context.argsArray;
var iFirstSave = context.iCurr - 3; var iFirstSave = context.iCurr - 3;
var pos = (i - iFirstSave) % 4; var pos = (i - iFirstSave) % 4;
@ -300,6 +302,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
case 3: case 3:
return fnArray[i] === OPS.restore; return fnArray[i] === OPS.restore;
} }
throw new Error(`iterateImageGroup - invalid pos: ${pos}`);
}, },
function (context, i) { function (context, i) {
var MIN_IMAGES_IN_BLOCK = 3; var MIN_IMAGES_IN_BLOCK = 3;
@ -346,7 +349,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
addState(InitialState, addState(InitialState,
[OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText], [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
null, null,
function (context, i) { function iterateShowTextGroup(context, i) {
var fnArray = context.fnArray, argsArray = context.argsArray; var fnArray = context.fnArray, argsArray = context.argsArray;
var iFirstSave = context.iCurr - 4; var iFirstSave = context.iCurr - 4;
var pos = (i - iFirstSave) % 5; var pos = (i - iFirstSave) % 5;
@ -372,6 +375,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
case 4: case 4:
return fnArray[i] === OPS.endText; return fnArray[i] === OPS.endText;
} }
throw new Error(`iterateShowTextGroup - invalid pos: ${pos}`);
}, },
function (context, i) { function (context, i) {
var MIN_CHARS_IN_BLOCK = 3; var MIN_CHARS_IN_BLOCK = 3;

View File

@ -2021,13 +2021,14 @@ class WorkerTransport {
messageHandler.on('obj', function(data) { messageHandler.on('obj', function(data) {
if (this.destroyed) { if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated. // Ignore any pending requests if the worker was terminated.
return undefined;
} }
const [id, pageIndex, type, imageData] = data; const [id, pageIndex, type, imageData] = data;
const pageProxy = this.pageCache[pageIndex]; const pageProxy = this.pageCache[pageIndex];
if (pageProxy.objs.has(id)) { if (pageProxy.objs.has(id)) {
return; return undefined;
} }
switch (type) { switch (type) {
@ -2064,6 +2065,7 @@ class WorkerTransport {
default: default:
throw new Error(`Got unknown object type ${type}`); throw new Error(`Got unknown object type ${type}`);
} }
return undefined;
}, this); }, this);
messageHandler.on('DocProgress', function(data) { messageHandler.on('DocProgress', function(data) {

View File

@ -1435,7 +1435,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var fontSize = current.fontSize; var fontSize = current.fontSize;
if (fontSize === 0) { if (fontSize === 0) {
return; return undefined;
} }
var ctx = this.ctx; var ctx = this.ctx;

View File

@ -64,7 +64,7 @@ class BaseFontLoader {
async bind(font) { async bind(font) {
// Add the font to the DOM only once; skip if the font is already loaded. // Add the font to the DOM only once; skip if the font is already loaded.
if (font.attached || font.missingFile) { if (font.attached || font.missingFile) {
return; return undefined;
} }
font.attached = true; font.attached = true;
@ -83,7 +83,7 @@ class BaseFontLoader {
throw ex; throw ex;
} }
} }
return; // The font was, asynchronously, loaded. return undefined; // The font was, asynchronously, loaded.
} }
// !this.isFontLoadingAPISupported // !this.isFontLoadingAPISupported
@ -92,13 +92,14 @@ class BaseFontLoader {
this.insertRule(rule); this.insertRule(rule);
if (this.isSyncFontLoadingSupported) { if (this.isSyncFontLoadingSupported) {
return; // The font was, synchronously, loaded. return undefined; // The font was, synchronously, loaded.
} }
return new Promise((resolve) => { return new Promise((resolve) => {
const request = this._queueLoadingCallback(resolve); const request = this._queueLoadingCallback(resolve);
this._prepareFontLoadEvent([rule], [font], request); this._prepareFontLoadEvent([rule], [font], request);
}); });
} }
return undefined;
} }
_queueLoadingCallback(callback) { _queueLoadingCallback(callback) {

View File

@ -20,7 +20,7 @@ import {
async function resolveCall(fn, args, thisArg = null) { async function resolveCall(fn, args, thisArg = null) {
if (!fn) { if (!fn) {
return; return undefined;
} }
return fn.apply(thisArg, args); return fn.apply(thisArg, args);
} }

View File

@ -296,10 +296,11 @@ function getTestManifest() {
testFilter.splice(i, 1); testFilter.splice(i, 1);
return true; return true;
} }
return false;
}); });
if (testFilter.length) { if (testFilter.length) {
console.error('Unrecognized test IDs: ' + testFilter.join(' ')); console.error('Unrecognized test IDs: ' + testFilter.join(' '));
return; return undefined;
} }
} }
return manifest; return manifest;

View File

@ -39,7 +39,7 @@ describe('fetch_stream', function() {
const read = function() { const read = function() {
return fullReader.read().then(function(result) { return fullReader.read().then(function(result) {
if (result.done) { if (result.done) {
return; return undefined;
} }
len += result.value.byteLength; len += result.value.byteLength;
@ -85,7 +85,7 @@ describe('fetch_stream', function() {
const read = function(reader, lenResult) { const read = function(reader, lenResult) {
return reader.read().then(function(result) { return reader.read().then(function(result) {
if (result.done) { if (result.done) {
return; return undefined;
} }
lenResult.value += result.value.byteLength; lenResult.value += result.value.byteLength;

View File

@ -39,7 +39,7 @@ describe('network', function() {
var read = function () { var read = function () {
return fullReader.read().then(function (result) { return fullReader.read().then(function (result) {
if (result.done) { if (result.done) {
return; return undefined;
} }
count++; count++;
len += result.value.byteLength; len += result.value.byteLength;
@ -94,7 +94,7 @@ describe('network', function() {
var read = function (reader, lenResult) { var read = function (reader, lenResult) {
return reader.read().then(function (result) { return reader.read().then(function (result) {
if (result.done) { if (result.done) {
return; return undefined;
} }
lenResult.value += result.value.byteLength; lenResult.value += result.value.byteLength;
return read(reader, lenResult); return read(reader, lenResult);

View File

@ -37,6 +37,7 @@ describe('network_utils', function() {
if (headerName === 'Content-Length') { if (headerName === 'Content-Length') {
return 8; return 8;
} }
throw new Error(`Unexpected headerName: ${headerName}`);
}, },
rangeChunkSize: 64, rangeChunkSize: 64,
})).toEqual({ })).toEqual({
@ -51,6 +52,7 @@ describe('network_utils', function() {
if (headerName === 'Content-Length') { if (headerName === 'Content-Length') {
return 8; return 8;
} }
throw new Error(`Unexpected headerName: ${headerName}`);
}, },
rangeChunkSize: 64, rangeChunkSize: 64,
})).toEqual({ })).toEqual({
@ -69,6 +71,7 @@ describe('network_utils', function() {
} else if (headerName === 'Content-Length') { } else if (headerName === 'Content-Length') {
return 8; return 8;
} }
throw new Error(`Unexpected headerName: ${headerName}`);
}, },
rangeChunkSize: 64, rangeChunkSize: 64,
})).toEqual({ })).toEqual({
@ -89,6 +92,7 @@ describe('network_utils', function() {
} else if (headerName === 'Content-Length') { } else if (headerName === 'Content-Length') {
return 8; return 8;
} }
throw new Error(`Unexpected headerName: ${headerName}`);
}, },
rangeChunkSize: 64, rangeChunkSize: 64,
})).toEqual({ })).toEqual({
@ -109,6 +113,7 @@ describe('network_utils', function() {
} else if (headerName === 'Content-Length') { } else if (headerName === 'Content-Length') {
return 'eight'; return 'eight';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
}, },
rangeChunkSize: 64, rangeChunkSize: 64,
})).toEqual({ })).toEqual({
@ -129,6 +134,7 @@ describe('network_utils', function() {
} else if (headerName === 'Content-Length') { } else if (headerName === 'Content-Length') {
return 8; return 8;
} }
throw new Error(`Unexpected headerName: ${headerName}`);
}, },
rangeChunkSize: 64, rangeChunkSize: 64,
})).toEqual({ })).toEqual({
@ -149,6 +155,7 @@ describe('network_utils', function() {
} else if (headerName === 'Content-Length') { } else if (headerName === 'Content-Length') {
return 8192; return 8192;
} }
throw new Error(`Unexpected headerName: ${headerName}`);
}, },
rangeChunkSize: 64, rangeChunkSize: 64,
})).toEqual({ })).toEqual({
@ -164,18 +171,21 @@ describe('network_utils', function() {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return null; return null;
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toBeNull(); })).toBeNull();
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return undefined; return undefined;
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toBeNull(); })).toBeNull();
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return ''; return '';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toBeNull(); })).toBeNull();
}); });
@ -184,42 +194,49 @@ describe('network_utils', function() {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'inline'; return 'inline';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toBeNull(); })).toBeNull();
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment'; return 'attachment';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toBeNull(); })).toBeNull();
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename="filename.pdf"'; return 'attachment; filename="filename.pdf"';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename="filename.pdf and spaces.pdf"'; return 'attachment; filename="filename.pdf and spaces.pdf"';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf and spaces.pdf'); })).toEqual('filename.pdf and spaces.pdf');
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename="tl;dr.pdf"'; return 'attachment; filename="tl;dr.pdf"';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('tl;dr.pdf'); })).toEqual('tl;dr.pdf');
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename=filename.pdf'; return 'attachment; filename=filename.pdf';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename=filename.pdf someotherparam'; return 'attachment; filename=filename.pdf someotherparam';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
}); });
@ -228,30 +245,35 @@ describe('network_utils', function() {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename*=filename.pdf'; return 'attachment; filename*=filename.pdf';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename*=\'\'filename.pdf'; return 'attachment; filename*=\'\'filename.pdf';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename*=utf-8\'\'filename.pdf'; return 'attachment; filename*=utf-8\'\'filename.pdf';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename=no.pdf; filename*=utf-8\'\'filename.pdf'; return 'attachment; filename=no.pdf; filename*=utf-8\'\'filename.pdf';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
expect(extractFilenameFromHeader((headerName) => { expect(extractFilenameFromHeader((headerName) => {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename*=utf-8\'\'filename.pdf; filename=no.pdf'; return 'attachment; filename*=utf-8\'\'filename.pdf; filename=no.pdf';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
}); });
@ -261,6 +283,7 @@ describe('network_utils', function() {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename*0=filename; filename*1=.pdf'; return 'attachment; filename*0=filename; filename*1=.pdf';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('filename.pdf'); })).toEqual('filename.pdf');
}); });
@ -269,6 +292,7 @@ describe('network_utils', function() {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'attachment; filename="filename.png"'; return 'attachment; filename="filename.png"';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toBeNull(); })).toBeNull();
}); });
@ -277,6 +301,7 @@ describe('network_utils', function() {
if (headerName === 'Content-Disposition') { if (headerName === 'Content-Disposition') {
return 'form-data; name="fieldName"; filename="file.PdF"'; return 'form-data; name="fieldName"; filename="file.PdF"';
} }
throw new Error(`Unexpected headerName: ${headerName}`);
})).toEqual('file.PdF'); })).toEqual('file.PdF');
}); });
}); });

View File

@ -109,7 +109,7 @@ describe('node_stream', function() {
let read1 = function () { let read1 = function () {
return fullReader1.read().then(function (result) { return fullReader1.read().then(function (result) {
if (result.done) { if (result.done) {
return; return undefined;
} }
len1 += result.value.byteLength; len1 += result.value.byteLength;
return read1(); return read1();
@ -118,7 +118,7 @@ describe('node_stream', function() {
let read2 = function () { let read2 = function () {
return fullReader2.read().then(function (result) { return fullReader2.read().then(function (result) {
if (result.done) { if (result.done) {
return; return undefined;
} }
len2 += result.value.byteLength; len2 += result.value.byteLength;
return read2(); return read2();
@ -195,7 +195,7 @@ describe('node_stream', function() {
let read = function (reader, lenResult) { let read = function (reader, lenResult) {
return reader.read().then(function (result) { return reader.read().then(function (result) {
if (result.done) { if (result.done) {
return; return undefined;
} }
lenResult.value += result.value.byteLength; lenResult.value += result.value.byteLength;
return read(reader, lenResult); return read(reader, lenResult);

View File

@ -198,7 +198,7 @@ let PDFViewerApplication = {
async _parseHashParameters() { async _parseHashParameters() {
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION') && if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION') &&
!AppOptions.get('pdfBugEnabled')) { !AppOptions.get('pdfBugEnabled')) {
return; return undefined;
} }
const waitOn = []; const waitOn = [];
@ -576,7 +576,7 @@ let PDFViewerApplication = {
errorWrapper.setAttribute('hidden', 'true'); errorWrapper.setAttribute('hidden', 'true');
if (!this.pdfLoadingTask) { if (!this.pdfLoadingTask) {
return; return undefined;
} }
let promise = this.pdfLoadingTask.destroy(); let promise = this.pdfLoadingTask.destroy();
@ -681,7 +681,7 @@ let PDFViewerApplication = {
this.load(pdfDocument); this.load(pdfDocument);
}, (exception) => { }, (exception) => {
if (loadingTask !== this.pdfLoadingTask) { if (loadingTask !== this.pdfLoadingTask) {
return; // Ignore errors for previously opened PDF files. return undefined; // Ignore errors for previously opened PDF files.
} }
let message = exception && exception.message; let message = exception && exception.message;

View File

@ -58,8 +58,8 @@ class DownloadManager {
downloadData(data, filename, contentType) { downloadData(data, filename, contentType) {
if (navigator.msSaveBlob) { // IE10 and above if (navigator.msSaveBlob) { // IE10 and above
return navigator.msSaveBlob(new Blob([data], { type: contentType, }), navigator.msSaveBlob(new Blob([data], { type: contentType, }), filename);
filename); return;
} }
let blobUrl = createObjectURL(data, contentType, let blobUrl = createObjectURL(data, contentType,
this.disableCreateObjectURL); this.disableCreateObjectURL);

View File

@ -221,6 +221,7 @@ function isLeftMouseReleased(event) {
// Safari 6.0+ // Safari 6.0+
return event.which === 0; return event.which === 0;
} }
return false;
} }
export { export {

View File

@ -90,7 +90,7 @@ class PasswordPrompt {
let password = this.input.value; let password = this.input.value;
if (password && password.length > 0) { if (password && password.length > 0) {
this.close(); this.close();
return this.updateCallback(password); this.updateCallback(password);
} }
} }

View File

@ -256,10 +256,10 @@ class PDFDocumentProperties {
/** /**
* @private * @private
*/ */
_parseFileSize(fileSize = 0) { async _parseFileSize(fileSize = 0) {
let kb = fileSize / 1024; let kb = fileSize / 1024;
if (!kb) { if (!kb) {
return Promise.resolve(undefined); return undefined;
} else if (kb < 1024) { } else if (kb < 1024) {
return this.l10n.get('document_properties_kb', { return this.l10n.get('document_properties_kb', {
size_kb: (+kb.toPrecision(3)).toLocaleString(), size_kb: (+kb.toPrecision(3)).toLocaleString(),
@ -275,9 +275,9 @@ class PDFDocumentProperties {
/** /**
* @private * @private
*/ */
_parsePageSize(pageSizeInches, pagesRotation) { async _parsePageSize(pageSizeInches, pagesRotation) {
if (!pageSizeInches) { if (!pageSizeInches) {
return Promise.resolve(undefined); return undefined;
} }
// Take the viewer rotation into account as well; compare with Adobe Reader. // Take the viewer rotation into account as well; compare with Adobe Reader.
if (pagesRotation % 180 !== 0) { if (pagesRotation % 180 !== 0) {
@ -362,15 +362,15 @@ class PDFDocumentProperties {
/** /**
* @private * @private
*/ */
_parseDate(inputDate) { async _parseDate(inputDate) {
const dateObject = PDFDateString.toDateObject(inputDate); const dateObject = PDFDateString.toDateObject(inputDate);
if (dateObject) { if (!dateObject) {
const dateString = dateObject.toLocaleDateString(); return undefined;
const timeString = dateObject.toLocaleTimeString();
return this.l10n.get('document_properties_date_string',
{ date: dateString, time: timeString, },
'{{date}}, {{time}}');
} }
return this.l10n.get('document_properties_date_string', {
date: dateObject.toLocaleDateString(),
time: dateObject.toLocaleTimeString(),
}, '{{date}}, {{time}}');
} }
/** /**

View File

@ -292,6 +292,7 @@ window.addEventListener('keydown', function(event) {
} }
}, true); }, true);
if (hasAttachEvent) { if (hasAttachEvent) {
// eslint-disable-next-line consistent-return
document.attachEvent('onkeydown', function(event) { document.attachEvent('onkeydown', function(event) {
event = event || window.event; event = event || window.event;
if (event.keyCode === /* P= */ 80 && event.ctrlKey) { if (event.keyCode === /* P= */ 80 && event.ctrlKey) {