Enable the ESLint no-shadow rule

This rule is *not* currently enabled in mozilla-central, but it appears commented out[1] in the ESLint definition file; see https://searchfox.org/mozilla-central/rev/c80fa7258c935223fe319c5345b58eae85d4c6ae/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#238-239

Unfortunately this rule is, for fairly obvious reasons, impossible to `--fix` automatically (even partially) and each case thus required careful manual analysis.
Hence this ESLint rule is, by some margin, probably the most difficult one that we've enabled thus far. However, using this rule does seem like a good idea in general since allowing variable shadowing could lead to subtle (and difficult to find) bugs or at the very least confusing code.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-shadow

---
[1] Most likely, a very large number of lint errors have prevented this rule from being enabled thus far.
This commit is contained in:
Jonas Jenwald 2020-03-25 09:42:50 +01:00
parent 475fa1f97f
commit 1d2f787d6a
12 changed files with 95 additions and 87 deletions

View File

@ -119,8 +119,8 @@
"no-catch-shadow": "error", "no-catch-shadow": "error",
"no-delete-var": "error", "no-delete-var": "error",
"no-label-var": "error", "no-label-var": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error", "no-shadow-restricted-names": "error",
"no-shadow": "off",
"no-undef-init": "error", "no-undef-init": "error",
"no-undef": ["error", { "typeof": true, }], "no-undef": ["error", { "typeof": true, }],
"no-unused-vars": ["error", { "no-unused-vars": ["error", {

View File

@ -289,7 +289,7 @@ function traverseTree(ctx, node) {
for (var i in node) { for (var i in node) {
var child = node[i]; var child = node[i];
if (typeof child === "object" && child !== null && child.type) { if (typeof child === "object" && child !== null && child.type) {
var result = traverseTree(ctx, child); const result = traverseTree(ctx, child);
if (result !== child) { if (result !== child) {
node[i] = result; node[i] = result;
} }
@ -300,7 +300,7 @@ function traverseTree(ctx, node) {
childItem !== null && childItem !== null &&
childItem.type childItem.type
) { ) {
var result = traverseTree(ctx, childItem); const result = traverseTree(ctx, childItem);
if (result !== childItem) { if (result !== childItem) {
child[index] = result; child[index] = result;
} }

View File

@ -167,8 +167,6 @@ function createStringSource(filename, content) {
} }
function createWebpackConfig(defines, output) { function createWebpackConfig(defines, output) {
var path = require("path");
var versionInfo = getVersionJSON(); var versionInfo = getVersionJSON();
var bundleDefines = builder.merge(defines, { var bundleDefines = builder.merge(defines, {
BUNDLE_VERSION: versionInfo.version, BUNDLE_VERSION: versionInfo.version,
@ -243,9 +241,9 @@ function createWebpackConfig(defines, output) {
}; };
} }
function webpack2Stream(config) { function webpack2Stream(webpackConfig) {
// Replacing webpack1 to webpack2 in the webpack-stream. // Replacing webpack1 to webpack2 in the webpack-stream.
return webpackStream(config, webpack2); return webpackStream(webpackConfig, webpack2);
} }
function getVersionJSON() { function getVersionJSON() {
@ -378,28 +376,28 @@ function createImageDecodersBundle(defines) {
.pipe(replaceJSRootName(imageDecodersAMDName, "pdfjsImageDecoders")); .pipe(replaceJSRootName(imageDecodersAMDName, "pdfjsImageDecoders"));
} }
function checkFile(path) { function checkFile(filePath) {
try { try {
var stat = fs.lstatSync(path); var stat = fs.lstatSync(filePath);
return stat.isFile(); return stat.isFile();
} catch (e) { } catch (e) {
return false; return false;
} }
} }
function checkDir(path) { function checkDir(dirPath) {
try { try {
var stat = fs.lstatSync(path); var stat = fs.lstatSync(dirPath);
return stat.isDirectory(); return stat.isDirectory();
} catch (e) { } catch (e) {
return false; return false;
} }
} }
function replaceInFile(path, find, replacement) { function replaceInFile(filePath, find, replacement) {
var content = fs.readFileSync(path).toString(); var content = fs.readFileSync(filePath).toString();
content = content.replace(find, replacement); content = content.replace(find, replacement);
fs.writeFileSync(path, content); fs.writeFileSync(filePath, content);
} }
function getTempFile(prefix, suffix) { function getTempFile(prefix, suffix) {
@ -407,9 +405,9 @@ function getTempFile(prefix, suffix) {
var bytes = require("crypto") var bytes = require("crypto")
.randomBytes(6) .randomBytes(6)
.toString("hex"); .toString("hex");
var path = BUILD_DIR + "tmp/" + prefix + bytes + suffix; var filePath = BUILD_DIR + "tmp/" + prefix + bytes + suffix;
fs.writeFileSync(path, ""); fs.writeFileSync(filePath, "");
return path; return filePath;
} }
function createTestSource(testsName, bot) { function createTestSource(testsName, bot) {
@ -527,10 +525,10 @@ gulp.task("buildnumber", function(done) {
var version = config.versionPrefix + buildNumber; var version = config.versionPrefix + buildNumber;
exec('git log --format="%h" -n 1', function(err, stdout, stderr) { exec('git log --format="%h" -n 1', function(err2, stdout2, stderr2) {
var buildCommit = ""; var buildCommit = "";
if (!err) { if (!err2) {
buildCommit = stdout.replace("\n", ""); buildCommit = stdout2.replace("\n", "");
} }
createStringSource( createStringSource(
@ -559,9 +557,9 @@ gulp.task("default_preferences-pre", function() {
function babelPluginReplaceNonWebPackRequire(babel) { function babelPluginReplaceNonWebPackRequire(babel) {
return { return {
visitor: { visitor: {
Identifier(path, state) { Identifier(curPath, state) {
if (path.node.name === "__non_webpack_require__") { if (curPath.node.name === "__non_webpack_require__") {
path.replaceWith(babel.types.identifier("require")); curPath.replaceWith(babel.types.identifier("require"));
} }
}, },
}, },
@ -643,8 +641,8 @@ gulp.task("locale", function() {
var locales = []; var locales = [];
for (var i = 0; i < subfolders.length; i++) { for (var i = 0; i < subfolders.length; i++) {
var locale = subfolders[i]; var locale = subfolders[i];
var path = L10N_DIR + locale; var dirPath = L10N_DIR + locale;
if (!checkDir(path)) { if (!checkDir(dirPath)) {
continue; continue;
} }
if (!/^[a-z][a-z]([a-z])?(-[A-Z][A-Z])?$/.test(locale)) { if (!/^[a-z][a-z]([a-z])?(-[A-Z][A-Z])?$/.test(locale)) {
@ -656,7 +654,7 @@ gulp.task("locale", function() {
locales.push(locale); locales.push(locale);
if (checkFile(path + "/viewer.properties")) { if (checkFile(dirPath + "/viewer.properties")) {
viewerOutput += viewerOutput +=
"[" + "[" +
locale + locale +
@ -1163,9 +1161,9 @@ gulp.task(
function babelPluginReplaceNonWebPackRequire(babel) { function babelPluginReplaceNonWebPackRequire(babel) {
return { return {
visitor: { visitor: {
Identifier(path, state) { Identifier(curPath, state) {
if (path.node.name === "__non_webpack_require__") { if (curPath.node.name === "__non_webpack_require__") {
path.replaceWith(babel.types.identifier("require")); curPath.replaceWith(babel.types.identifier("require"));
} }
}, },
}, },
@ -1358,9 +1356,9 @@ gulp.task("baseline", function(done) {
} }
exec("git checkout " + baselineCommit, { cwd: workingDirectory }, function( exec("git checkout " + baselineCommit, { cwd: workingDirectory }, function(
error error2
) { ) {
if (error) { if (error2) {
done(new Error("Baseline commit checkout failed.")); done(new Error("Baseline commit checkout failed."));
return; return;
} }

View File

@ -23,6 +23,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["Courier-Bold"] = 600; t["Courier-Bold"] = 600;
t["Courier-BoldOblique"] = 600; t["Courier-BoldOblique"] = 600;
t["Courier-Oblique"] = 600; t["Courier-Oblique"] = 600;
// eslint-disable-next-line no-shadow
t["Helvetica"] = getLookupTableFactory(function(t) { t["Helvetica"] = getLookupTableFactory(function(t) {
t["space"] = 278; t["space"] = 278;
t["exclam"] = 278; t["exclam"] = 278;
@ -340,6 +341,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["imacron"] = 278; t["imacron"] = 278;
t["Euro"] = 556; t["Euro"] = 556;
}); });
// eslint-disable-next-line no-shadow
t["Helvetica-Bold"] = getLookupTableFactory(function(t) { t["Helvetica-Bold"] = getLookupTableFactory(function(t) {
t["space"] = 278; t["space"] = 278;
t["exclam"] = 333; t["exclam"] = 333;
@ -657,6 +659,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["imacron"] = 278; t["imacron"] = 278;
t["Euro"] = 556; t["Euro"] = 556;
}); });
// eslint-disable-next-line no-shadow
t["Helvetica-BoldOblique"] = getLookupTableFactory(function(t) { t["Helvetica-BoldOblique"] = getLookupTableFactory(function(t) {
t["space"] = 278; t["space"] = 278;
t["exclam"] = 333; t["exclam"] = 333;
@ -974,6 +977,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["imacron"] = 278; t["imacron"] = 278;
t["Euro"] = 556; t["Euro"] = 556;
}); });
// eslint-disable-next-line no-shadow
t["Helvetica-Oblique"] = getLookupTableFactory(function(t) { t["Helvetica-Oblique"] = getLookupTableFactory(function(t) {
t["space"] = 278; t["space"] = 278;
t["exclam"] = 278; t["exclam"] = 278;
@ -1291,6 +1295,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["imacron"] = 278; t["imacron"] = 278;
t["Euro"] = 556; t["Euro"] = 556;
}); });
// eslint-disable-next-line no-shadow
t["Symbol"] = getLookupTableFactory(function(t) { t["Symbol"] = getLookupTableFactory(function(t) {
t["space"] = 250; t["space"] = 250;
t["exclam"] = 333; t["exclam"] = 333;
@ -1483,6 +1488,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["bracerightbt"] = 494; t["bracerightbt"] = 494;
t["apple"] = 790; t["apple"] = 790;
}); });
// eslint-disable-next-line no-shadow
t["Times-Roman"] = getLookupTableFactory(function(t) { t["Times-Roman"] = getLookupTableFactory(function(t) {
t["space"] = 250; t["space"] = 250;
t["exclam"] = 333; t["exclam"] = 333;
@ -1800,6 +1806,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["imacron"] = 278; t["imacron"] = 278;
t["Euro"] = 500; t["Euro"] = 500;
}); });
// eslint-disable-next-line no-shadow
t["Times-Bold"] = getLookupTableFactory(function(t) { t["Times-Bold"] = getLookupTableFactory(function(t) {
t["space"] = 250; t["space"] = 250;
t["exclam"] = 333; t["exclam"] = 333;
@ -2117,6 +2124,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["imacron"] = 278; t["imacron"] = 278;
t["Euro"] = 500; t["Euro"] = 500;
}); });
// eslint-disable-next-line no-shadow
t["Times-BoldItalic"] = getLookupTableFactory(function(t) { t["Times-BoldItalic"] = getLookupTableFactory(function(t) {
t["space"] = 250; t["space"] = 250;
t["exclam"] = 389; t["exclam"] = 389;
@ -2434,6 +2442,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["imacron"] = 278; t["imacron"] = 278;
t["Euro"] = 500; t["Euro"] = 500;
}); });
// eslint-disable-next-line no-shadow
t["Times-Italic"] = getLookupTableFactory(function(t) { t["Times-Italic"] = getLookupTableFactory(function(t) {
t["space"] = 250; t["space"] = 250;
t["exclam"] = 333; t["exclam"] = 333;
@ -2751,6 +2760,7 @@ var getMetrics = getLookupTableFactory(function(t) {
t["imacron"] = 278; t["imacron"] = 278;
t["Euro"] = 500; t["Euro"] = 500;
}); });
// eslint-disable-next-line no-shadow
t["ZapfDingbats"] = getLookupTableFactory(function(t) { t["ZapfDingbats"] = getLookupTableFactory(function(t) {
t["space"] = 278; t["space"] = 278;
t["a1"] = 974; t["a1"] = 974;

View File

@ -114,15 +114,15 @@ class MessageHandler {
throw new Error(`Unknown action from worker: ${data.action}`); throw new Error(`Unknown action from worker: ${data.action}`);
} }
if (data.callbackId) { if (data.callbackId) {
const sourceName = this.sourceName; const cbSourceName = this.sourceName;
const targetName = data.sourceName; const cbTargetName = data.sourceName;
new Promise(function(resolve) { new Promise(function(resolve) {
resolve(action(data.data)); resolve(action(data.data));
}).then( }).then(
function(result) { function(result) {
comObj.postMessage({ comObj.postMessage({
sourceName, sourceName: cbSourceName,
targetName, targetName: cbTargetName,
callback: CallbackKind.DATA, callback: CallbackKind.DATA,
callbackId: data.callbackId, callbackId: data.callbackId,
data: result, data: result,
@ -130,8 +130,8 @@ class MessageHandler {
}, },
function(reason) { function(reason) {
comObj.postMessage({ comObj.postMessage({
sourceName, sourceName: cbSourceName,
targetName, targetName: cbTargetName,
callback: CallbackKind.ERROR, callback: CallbackKind.ERROR,
callbackId: data.callbackId, callbackId: data.callbackId,
reason: wrapReason(reason), reason: wrapReason(reason),

View File

@ -22,9 +22,9 @@ if (!fs.existsSync(file)) {
throw new Error(`PDF file does not exist '${file}'.`); throw new Error(`PDF file does not exist '${file}'.`);
} }
function calculateMD5(file, callback) { function calculateMD5(pdfFile, callback) {
var hash = crypto.createHash("md5"); var hash = crypto.createHash("md5");
var stream = fs.createReadStream(file); var stream = fs.createReadStream(pdfFile);
stream.on("data", function(data) { stream.on("data", function(data) {
hash.update(data); hash.update(data);
}); });

View File

@ -228,10 +228,10 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
for (var i = 0, ii = data.length; i < ii; i++) { for (var i = 0, ii = data.length; i < ii; i++) {
images[i].src = data[i]; images[i].src = data[i];
loadedPromises.push( loadedPromises.push(
new Promise(function(resolve, reject) { new Promise(function(resolveImage, rejectImage) {
images[i].onload = resolve; images[i].onload = resolveImage;
images[i].onerror = function(e) { images[i].onerror = function(e) {
reject(new Error("Error loading image " + e)); rejectImage(new Error("Error loading image " + e));
}; };
}) })
); );

View File

@ -24,10 +24,10 @@ var ttxResourcesHome = path.join(__dirname, "..", "ttx");
var nextTTXTaskId = Date.now(); var nextTTXTaskId = Date.now();
function runTtx(ttxResourcesHome, fontPath, registerOnCancel, callback) { function runTtx(ttxResourcesHomePath, fontPath, registerOnCancel, callback) {
fs.realpath(ttxResourcesHome, function(err, ttxResourcesHome) { fs.realpath(ttxResourcesHomePath, function(error, realTtxResourcesHomePath) {
var fontToolsHome = path.join(ttxResourcesHome, "fonttools-code"); var fontToolsHome = path.join(realTtxResourcesHomePath, "fonttools-code");
fs.realpath(fontPath, function(err, fontPath) { fs.realpath(fontPath, function(errorFontPath, realFontPath) {
var ttxPath = path.join("Tools", "ttx"); var ttxPath = path.join("Tools", "ttx");
if (!fs.existsSync(path.join(fontToolsHome, ttxPath))) { if (!fs.existsSync(path.join(fontToolsHome, ttxPath))) {
callback("TTX was not found, please checkout PDF.js submodules"); callback("TTX was not found, please checkout PDF.js submodules");
@ -38,7 +38,7 @@ function runTtx(ttxResourcesHome, fontPath, registerOnCancel, callback) {
PYTHONDONTWRITEBYTECODE: true, PYTHONDONTWRITEBYTECODE: true,
}; };
var ttxStdioMode = "ignore"; var ttxStdioMode = "ignore";
var ttx = spawn("python", [ttxPath, fontPath], { var ttx = spawn("python", [ttxPath, realFontPath], {
cwd: fontToolsHome, cwd: fontToolsHome,
stdio: ttxStdioMode, stdio: ttxStdioMode,
env: ttxEnv, env: ttxEnv,
@ -49,8 +49,8 @@ function runTtx(ttxResourcesHome, fontPath, registerOnCancel, callback) {
callback(reason); callback(reason);
ttx.kill(); ttx.kill();
}); });
ttx.on("error", function(err) { ttx.on("error", function(errorTtx) {
ttxRunError = err; ttxRunError = errorTtx;
callback("Unable to execute ttx"); callback("Unable to execute ttx");
}); });
ttx.on("close", function(code) { ttx.on("close", function(code) {

View File

@ -37,16 +37,16 @@ function parseOptions() {
function group(stats, groupBy) { function group(stats, groupBy) {
var vals = []; var vals = [];
for (var i = 0; i < stats.length; i++) { for (var i = 0; i < stats.length; i++) {
var stat = stats[i]; var curStat = stats[i];
var keyArr = []; var keyArr = [];
for (var j = 0; j < groupBy.length; j++) { for (var j = 0; j < groupBy.length; j++) {
keyArr.push(stat[groupBy[j]]); keyArr.push(curStat[groupBy[j]]);
} }
var key = keyArr.join(","); var key = keyArr.join(",");
if (vals[key] === undefined) { if (vals[key] === undefined) {
vals[key] = []; vals[key] = [];
} }
vals[key].push(stat["time"]); vals[key].push(curStat["time"]);
} }
return vals; return vals;
} }
@ -57,13 +57,13 @@ function group(stats, groupBy) {
*/ */
function flatten(stats) { function flatten(stats) {
var rows = []; var rows = [];
stats.forEach(function(stat) { stats.forEach(function(curStat) {
stat["stats"].forEach(function(s) { curStat["stats"].forEach(function(s) {
rows.push({ rows.push({
browser: stat["browser"], browser: curStat["browser"],
page: stat["page"], page: curStat["page"],
pdf: stat["pdf"], pdf: curStat["pdf"],
round: stat["round"], round: curStat["round"],
stat: s["name"], stat: s["name"],
time: s["end"] - s["start"], time: s["end"] - s["start"],
}); });

View File

@ -619,8 +619,8 @@ function refTestPostHandler(req, res) {
if (pathname === "/tellMeToQuit") { if (pathname === "/tellMeToQuit") {
// finding by path // finding by path
var browserPath = parsedUrl.query.path; var browserPath = parsedUrl.query.path;
session = sessions.filter(function(session) { session = sessions.filter(function(curSession) {
return session.config.path === browserPath; return curSession.config.path === browserPath;
})[0]; })[0];
monitorBrowserTimeout(session, null); monitorBrowserTimeout(session, null);
closeSession(session.name); closeSession(session.name);
@ -689,7 +689,7 @@ function refTestPostHandler(req, res) {
return true; return true;
} }
function startUnitTest(url, name) { function startUnitTest(testUrl, name) {
var startTime = Date.now(); var startTime = Date.now();
startServer(); startServer();
server.hooks["POST"].push(unitTestPostHandler); server.hooks["POST"].push(unitTestPostHandler);
@ -712,7 +712,7 @@ function startUnitTest(url, name) {
var runtime = (Date.now() - startTime) / 1000; var runtime = (Date.now() - startTime) / 1000;
console.log(name + " tests runtime was " + runtime.toFixed(1) + " seconds"); console.log(name + " tests runtime was " + runtime.toFixed(1) + " seconds");
}; };
startBrowsers(url, function(session) { startBrowsers(testUrl, function(session) {
session.numRuns = 0; session.numRuns = 0;
session.numErrors = 0; session.numErrors = 0;
}); });
@ -784,7 +784,7 @@ function unitTestPostHandler(req, res) {
return true; return true;
} }
function startBrowsers(url, initSessionCallback) { function startBrowsers(testUrl, initSessionCallback) {
var browsers; var browsers;
if (options.browserManifestFile) { if (options.browserManifestFile) {
browsers = JSON.parse(fs.readFileSync(options.browserManifestFile)); browsers = JSON.parse(fs.readFileSync(options.browserManifestFile));
@ -801,7 +801,7 @@ function startBrowsers(url, initSessionCallback) {
var browser = WebBrowser.create(b); var browser = WebBrowser.create(b);
var startUrl = var startUrl =
getServerBaseAddress() + getServerBaseAddress() +
url + testUrl +
"?browser=" + "?browser=" +
encodeURIComponent(b.name) + encodeURIComponent(b.name) +
"&manifestFile=" + "&manifestFile=" +

View File

@ -26,9 +26,9 @@ var crypto = require("crypto");
var tempDirPrefix = "pdfjs_"; var tempDirPrefix = "pdfjs_";
function WebBrowser(name, path, headless) { function WebBrowser(name, execPath, headless) {
this.name = name; this.name = name;
this.path = path; this.path = execPath;
this.headless = headless; this.headless = headless;
this.tmpDir = null; this.tmpDir = null;
this.profileDir = null; this.profileDir = null;
@ -197,7 +197,7 @@ WebBrowser.prototype = {
// Note: First process' output it shown, the later outputs are suppressed. // Note: First process' output it shown, the later outputs are suppressed.
execAsyncNoStdin( execAsyncNoStdin(
cmdKillAll, cmdKillAll,
function checkAlive(exitCode, firstStdout) { function checkAlive(firstExitCode, firstStdout) {
execAsyncNoStdin( execAsyncNoStdin(
cmdCheckAllKilled, cmdCheckAllKilled,
function(exitCode, stdout) { function(exitCode, stdout) {
@ -227,14 +227,14 @@ WebBrowser.prototype = {
var firefoxResourceDir = path.join(__dirname, "resources", "firefox"); var firefoxResourceDir = path.join(__dirname, "resources", "firefox");
function FirefoxBrowser(name, path, headless) { function FirefoxBrowser(name, execPath, headless) {
if (os.platform() === "darwin") { if (os.platform() === "darwin") {
var m = /([^.\/]+)\.app(\/?)$/.exec(path); var m = /([^.\/]+)\.app(\/?)$/.exec(execPath);
if (m) { if (m) {
path += (m[2] ? "" : "/") + "Contents/MacOS/firefox"; execPath += (m[2] ? "" : "/") + "Contents/MacOS/firefox";
} }
} }
WebBrowser.call(this, name, path, headless); WebBrowser.call(this, name, execPath, headless);
} }
FirefoxBrowser.prototype = Object.create(WebBrowser.prototype); FirefoxBrowser.prototype = Object.create(WebBrowser.prototype);
FirefoxBrowser.prototype.buildArguments = function(url) { FirefoxBrowser.prototype.buildArguments = function(url) {
@ -253,15 +253,15 @@ FirefoxBrowser.prototype.setupProfileDir = function(dir) {
testUtils.copySubtreeSync(firefoxResourceDir, dir); testUtils.copySubtreeSync(firefoxResourceDir, dir);
}; };
function ChromiumBrowser(name, path, headless) { function ChromiumBrowser(name, execPath, headless) {
if (os.platform() === "darwin") { if (os.platform() === "darwin") {
var m = /([^.\/]+)\.app(\/?)$/.exec(path); var m = /([^.\/]+)\.app(\/?)$/.exec(execPath);
if (m) { if (m) {
path += (m[2] ? "" : "/") + "Contents/MacOS/" + m[1]; execPath += (m[2] ? "" : "/") + "Contents/MacOS/" + m[1];
console.log(path); console.log(execPath);
} }
} }
WebBrowser.call(this, name, path, headless); WebBrowser.call(this, name, execPath, headless);
} }
ChromiumBrowser.prototype = Object.create(WebBrowser.prototype); ChromiumBrowser.prototype = Object.create(WebBrowser.prototype);
ChromiumBrowser.prototype.buildArguments = function(url) { ChromiumBrowser.prototype.buildArguments = function(url) {
@ -291,18 +291,18 @@ ChromiumBrowser.prototype.buildArguments = function(url) {
WebBrowser.create = function(desc) { WebBrowser.create = function(desc) {
var name = desc.name; var name = desc.name;
var path = fs.realpathSync(desc.path); var execPath = fs.realpathSync(desc.path);
if (!path) { if (!execPath) {
throw new Error("Browser executable not found: " + desc.path); throw new Error("Browser executable not found: " + desc.path);
} }
if (/firefox/i.test(name)) { if (/firefox/i.test(name)) {
return new FirefoxBrowser(name, path, desc.headless); return new FirefoxBrowser(name, execPath, desc.headless);
} }
if (/(chrome|chromium|opera)/i.test(name)) { if (/(chrome|chromium|opera)/i.test(name)) {
return new ChromiumBrowser(name, path, desc.headless); return new ChromiumBrowser(name, execPath, desc.headless);
} }
return new WebBrowser(name, path, desc.headless); return new WebBrowser(name, execPath, desc.headless);
}; };
exports.WebBrowser = WebBrowser; exports.WebBrowser = WebBrowser;

View File

@ -283,15 +283,15 @@ WebServer.prototype = {
}); });
} }
function serveRequestedFile(filePath) { function serveRequestedFile(reqFilePath) {
var stream = fs.createReadStream(filePath, { flags: "rs" }); var stream = fs.createReadStream(reqFilePath, { flags: "rs" });
stream.on("error", function(error) { stream.on("error", function(error) {
res.writeHead(500); res.writeHead(500);
res.end(); res.end();
}); });
var ext = path.extname(filePath).toLowerCase(); var ext = path.extname(reqFilePath).toLowerCase();
var contentType = mimeTypes[ext] || defaultMimeType; var contentType = mimeTypes[ext] || defaultMimeType;
if (!disableRangeRequests) { if (!disableRangeRequests) {
@ -309,8 +309,8 @@ WebServer.prototype = {
stream.pipe(res); stream.pipe(res);
} }
function serveRequestedFileRange(filePath, start, end) { function serveRequestedFileRange(reqFilePath, start, end) {
var stream = fs.createReadStream(filePath, { var stream = fs.createReadStream(reqFilePath, {
flags: "rs", flags: "rs",
start: start, start: start,
end: end - 1, end: end - 1,
@ -321,7 +321,7 @@ WebServer.prototype = {
res.end(); res.end();
}); });
var ext = path.extname(filePath).toLowerCase(); var ext = path.extname(reqFilePath).toLowerCase();
var contentType = mimeTypes[ext] || defaultMimeType; var contentType = mimeTypes[ext] || defaultMimeType;
res.setHeader("Accept-Ranges", "bytes"); res.setHeader("Accept-Ranges", "bytes");