Backed out changeset 856215476aa4 (bug 1386666) for eslint failures a=backout

MozReview-Commit-ID: FdO8WkzBvfj
This commit is contained in:
Wes Kocher 2017-08-02 11:47:42 -07:00
parent e2ffcaa665
commit 2f468040aa
16 changed files with 118 additions and 193 deletions

View File

@ -339,6 +339,7 @@ toolkit/components/workerloader/tests/moduleF-syntax-error.js
toolkit/modules/tests/xpcshell/test_task.js
# Not yet updated
toolkit/components/osfile/**
toolkit/components/url-classifier/**
# External code:
@ -350,7 +351,6 @@ toolkit/components/reader/JSDOMParser.js
# Uses preprocessing
toolkit/content/widgets/wizard.xml
toolkit/components/jsdownloads/src/DownloadIntegration.jsm
toolkit/components/osfile/osfile.jsm
toolkit/components/urlformatter/nsURLFormatter.js
toolkit/modules/AppConstants.jsm
toolkit/mozapps/downloads/nsHelperAppDlg.js

View File

@ -1,32 +0,0 @@
"use strict";
module.exports = {
"rules": {
"brace-style": "off",
"comma-spacing": "off",
"consistent-return": "off",
"eol-last": "off",
"func-call-spacing": "off",
"key-spacing": "off",
"keyword-spacing": "off",
"no-else-return": "off",
"no-extra-semi": "off",
"no-irregular-whitespace": "off",
"no-lone-blocks": "off",
"no-lonely-if": "off",
"no-multi-spaces": "off",
"no-redeclare": "off",
"no-self-assign": "off",
"no-shadow": "off",
"no-trailing-spaces": "off",
"no-undef": "off",
"no-unsafe-negation": "off",
"no-unused-vars": "off",
"no-useless-return": "off",
"object-shorthand": "off",
"quotes": "off",
"space-before-function-paren": "off",
"space-infix-ops": "off",
"spaced-comment": "off",
}
};

View File

@ -152,30 +152,24 @@ AbstractFile.openUnique = function openUnique(path, options = {}) {
path: path,
file: OS.File.open(path, mode)
};
} catch (ex) {
if (ex instanceof OS.File.Error && ex.becauseExists) {
for (let i = 0; i < maxAttempts; ++i) {
try {
if (humanReadable) {
uniquePath = Path.join(dirName, fileName + "-" + (i + 1) + suffix);
} else {
let hexNumber = Math.floor(Math.random() * MAX_HEX_NUMBER).toString(HEX_RADIX);
uniquePath = Path.join(dirName, fileName + "-" + hexNumber + suffix);
}
return {
path: uniquePath,
file: OS.File.open(uniquePath, mode)
};
} catch (ex) {
if (ex instanceof OS.File.Error && ex.becauseExists) {
// keep trying ...
} else {
throw ex;
}
} catch (ex if ex instanceof OS.File.Error && ex.becauseExists) {
for (let i = 0; i < maxAttempts; ++i) {
try {
if (humanReadable) {
uniquePath = Path.join(dirName, fileName + "-" + (i + 1) + suffix);
} else {
let hexNumber = Math.floor(Math.random() * MAX_HEX_NUMBER).toString(HEX_RADIX);
uniquePath = Path.join(dirName, fileName + "-" + hexNumber + suffix);
}
return {
path: uniquePath,
file: OS.File.open(uniquePath, mode)
};
} catch (ex if ex instanceof OS.File.Error && ex.becauseExists) {
// keep trying ...
}
throw OS.File.Error.exists("could not find an unused file name.", path);
}
throw OS.File.Error.exists("could not find an unused file name.", path);
}
};
@ -345,12 +339,8 @@ AbstractFile.read = function read(path, bytes, options = {}) {
let decoder;
try {
decoder = new TextDecoder(options.encoding);
} catch (ex) {
if (ex instanceof RangeError) {
throw OS.File.Error.invalidArgument("Decode");
} else {
throw ex;
}
} catch (ex if ex instanceof RangeError) {
throw OS.File.Error.invalidArgument("Decode");
}
return decoder.decode(buffer);
} finally {
@ -435,12 +425,8 @@ AbstractFile.writeAtomic =
if (options.backupTo) {
try {
OS.File.move(path, options.backupTo, {noCopy: true});
} catch (ex) {
if (ex.becauseNoSuchFile) {
// The file doesn't exist, nothing to backup.
} else {
throw ex;
}
} catch (ex if ex.becauseNoSuchFile) {
// The file doesn't exist, nothing to backup.
}
}
// Just write, without any renaming trick
@ -472,12 +458,8 @@ AbstractFile.writeAtomic =
if (options.backupTo) {
try {
OS.File.move(path, options.backupTo, {noCopy: true});
} catch (ex) {
if (ex.becauseNoSuchFile) {
// The file doesn't exist, nothing to backup.
} else {
throw ex;
}
} catch (ex if ex.becauseNoSuchFile) {
// The file doesn't exist, nothing to backup.
}
}

View File

@ -344,14 +344,10 @@ var test_iter = maketest("iter", function iter(test) {
let exn = null;
try {
await iterator.next();
} catch (ex) {
if (ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
exn = ex;
let exists = await iterator.exists();
test.ok(!exists, "After one iteration, iterator detects that the directory doesn't exist");
} else {
throw ex;
}
} catch (ex if ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
exn = ex;
let exists = await iterator.exists();
test.ok(!exists, "After one iteration, iterator detects that the directory doesn't exist");
}
test.ok(exn, "Iterating through a directory that does not exist has failed with becauseNoSuchFile");
} finally {
@ -424,3 +420,5 @@ var test_debug_test = maketest("debug_test", function debug_test(test) {
toggleDebugTest(false, consoleListener);
})();
});

View File

@ -192,13 +192,10 @@ function test_passing_undefined()
| OS.Constants.libc.O_CREAT
| OS.Constants.libc.O_TRUNC,
OS.Constants.libc.S_IRWXU);
} catch(e) {
if (e instanceof TypeError && e.message.indexOf("open") > -1) {
exceptionRaised = true;
} else {
throw e;
}
} catch(e if e instanceof TypeError && e.message.indexOf("open") > -1) {
exceptionRaised = true;
}
ok(exceptionRaised, "test_passing_undefined: exception gets thrown")
}

View File

@ -203,12 +203,8 @@ function test_passing_undefined()
OS.Constants.Win.OPEN_EXISTING,
0,
null);
} catch(e) {
if (e instanceof TypeError && e.message.indexOf("CreateFile") > -1) {
exceptionRaised = true;
} else {
throw e;
}
} catch(e if e instanceof TypeError && e.message.indexOf("CreateFile") > -1) {
exceptionRaised = true;
}
ok(exceptionRaised, "test_passing_undefined: exception gets thrown")

View File

@ -3,9 +3,5 @@
module.exports = {
"extends": [
"plugin:mozilla/xpcshell-test"
],
"rules": {
"no-shadow": "off",
}
]
};

View File

@ -95,13 +95,3 @@ function reference_compare_files(a, b, test) {
do_check_eq(a_contents, b_contents);
})();
};
async function removeTestFile(filePath, ignoreNoSuchFile = true) {
try {
await OS.File.remove(filePath);
} catch (ex) {
if (!ignoreNoSuchFile || !ex.becauseNoSuchFile) {
do_throw(ex);
}
}
}

View File

@ -31,51 +31,35 @@ add_test_pair(async function test_bad_encoding() {
try {
await OS.File.read(EXISTING_FILE, { encoding: "baby-speak-encoded" });
do_throw("Should have thrown with an ex.becauseInvalidArgument");
} catch (ex) {
if (ex.becauseInvalidArgument) {
do_print("Wrong encoding caused the correct exception");
} else {
throw ex;
}
} catch (ex if ex.becauseInvalidArgument) {
do_print("Wrong encoding caused the correct exception");
}
try {
await OS.File.read(EXISTING_FILE, { encoding: 4 });
do_throw("Should have thrown a TypeError");
} catch (ex) {
if (ex.constructor.name == "TypeError") {
// Note that TypeError doesn't carry across compartments
do_print("Non-string encoding caused the correct exception");
} else {
throw ex;
}
} catch (ex if ex.constructor.name == "TypeError") {
// Note that TypeError doesn't carry across compartments
do_print("Non-string encoding caused the correct exception");
}
});
});
add_test_pair(async function test_bad_compression() {
do_print("Testing with a non-existing compression");
try {
await OS.File.read(EXISTING_FILE, { compression: "mmmh-crunchy" });
do_throw("Should have thrown with an ex.becauseInvalidArgument");
} catch (ex) {
if (ex.becauseInvalidArgument) {
do_print("Wrong encoding caused the correct exception");
} else {
throw ex;
}
} catch (ex if ex.becauseInvalidArgument) {
do_print("Wrong encoding caused the correct exception");
}
do_print("Testing with a bad type for option compression");
try {
await OS.File.read(EXISTING_FILE, { compression: 5 });
do_throw("Should have thrown a TypeError");
} catch (ex) {
if (ex.constructor.name == "TypeError") {
// Note that TypeError doesn't carry across compartments
do_print("Non-string encoding caused the correct exception");
} else {
throw ex;
}
} catch (ex if ex.constructor.name == "TypeError") {
// Note that TypeError doesn't carry across compartments
do_print("Non-string encoding caused the correct exception");
}
});
@ -84,13 +68,9 @@ add_test_pair(async function test_bad_bytes() {
try {
await OS.File.read(EXISTING_FILE, { bytes: "five" });
do_throw("Should have thrown a TypeError");
} catch (ex) {
if (ex.constructor.name == "TypeError") {
// Note that TypeError doesn't carry across compartments
do_print("Non-number bytes caused the correct exception");
} else {
throw ex;
}
} catch (ex if ex.constructor.name == "TypeError") {
// Note that TypeError doesn't carry across compartments
do_print("Non-number bytes caused the correct exception");
}
});
@ -99,12 +79,8 @@ add_test_pair(async function read_non_existent() {
try {
await OS.File.read("I/do/not/exist");
do_throw("Should have thrown with an ex.becauseNoSuchFile");
} catch (ex) {
if (ex.becauseNoSuchFile) {
do_print("Correct exceptions");
} else {
throw ex;
}
} catch (ex if ex.becauseNoSuchFile) {
do_print("Correct exceptions");
}
});

View File

@ -19,15 +19,12 @@ add_task(async function() {
// Attempt to open a file that does not exist, ensure that it yields the
// appropriate error.
try {
await OS.File.open(OS.Path.join(".", "This file does not exist"));
let fd = await OS.File.open(OS.Path.join(".", "This file does not exist"));
do_check_true(false, "File opening 1 succeeded (it should fail)");
} catch (err) {
if (err instanceof OS.File.Error && err.becauseNoSuchFile) {
do_print("File opening 1 failed " + err);
} else {
throw err;
}
} catch (err if err instanceof OS.File.Error && err.becauseNoSuchFile) {
do_print("File opening 1 failed " + err);
}
// Attempt to open a file with the wrong args, so that it fails before
// serialization, ensure that it yields the appropriate error.
do_print("Attempting to open a file with wrong arguments");

View File

@ -27,7 +27,11 @@ async function test_append(mode) {
"test_osfile_async_append.tmp");
// Clear any left-over files from previous runs.
await removeTestFile(path)
try {
await OS.File.remove(path);
} catch (ex if ex.becauseNoSuchFile) {
// ignore
}
try {
mode = setup_mode(mode);
@ -49,8 +53,12 @@ async function test_append(mode) {
} finally {
await file.close();
}
} catch (ex) {
await removeTestFile(path)
} catch(ex) {
try {
await OS.File.remove(path);
} catch (ex if ex.becauseNoSuchFile) {
// ignore.
}
}
}
@ -60,7 +68,11 @@ async function test_no_append(mode) {
"test_osfile_async_noappend.tmp");
// Clear any left-over files from previous runs.
await removeTestFile(path)
try {
await OS.File.remove(path);
} catch (ex if ex.becauseNoSuchFile) {
// ignore
}
try {
mode = setup_mode(mode);
@ -83,14 +95,18 @@ async function test_no_append(mode) {
await file.close();
}
} finally {
await removeTestFile(path)
try {
await OS.File.remove(path);
} catch (ex if ex.becauseNoSuchFile) {
// ignore.
}
}
}
var test_flags = [
{},
{create: true},
{trunc: true}
{create:true},
{trunc:true}
];
function run_test() {
do_test_pending();

View File

@ -90,8 +90,16 @@ async function test_copymove(options = {}) {
// 3. Check that the moved file was really moved.
do_check_eq((await OS.File.exists(dest)), false);
} finally {
await removeTestFile(dest);
await removeTestFile(dest2);
try {
await OS.File.remove(dest);
} catch (ex if ex.becauseNoSuchFile) {
// ignore
}
try {
await OS.File.remove(dest2);
} catch (ex if ex.becauseNoSuchFile) {
// ignore
}
}
}

View File

@ -17,7 +17,11 @@ async function test_setPosition(forward, current, backward) {
"test_osfile_async_largefiles.tmp");
// Clear any left-over files from previous runs.
await removeTestFile(path);
try {
await OS.File.remove(path);
} catch (ex if ex.becauseNoSuchFile) {
// ignore
}
try {
let file = await OS.File.open(path, {write:true, append:false});
@ -47,7 +51,12 @@ async function test_setPosition(forward, current, backward) {
await file.close();
}
} catch(ex) {
await removeTestFile(path);
try {
await OS.File.remove(path);
} catch (ex if ex.becauseNoSuchFile) {
// ignore.
}
do_throw(ex);
}
}
@ -57,7 +66,11 @@ async function test_setPosition_failures() {
"test_osfile_async_largefiles.tmp");
// Clear any left-over files from previous runs.
await removeTestFile(path);
try {
await OS.File.remove(path);
} catch (ex if ex.becauseNoSuchFile) {
// ignore
}
try {
let file = await OS.File.open(path, {write:true, append:false});
@ -101,7 +114,11 @@ async function test_setPosition_failures() {
} finally {
await file.setPosition(0, OS.File.POS_START);
await file.close();
await removeTestFile(path);
try {
await OS.File.remove(path);
} catch (ex if ex.becauseNoSuchFile) {
// ignore.
}
}
} catch(ex) {
do_throw(ex);

View File

@ -62,12 +62,8 @@ add_test_pair(async function read_write_all() {
opt.noOverwrite = true;
await OS.File.writeAtomic(DEST_PATH, view, opt);
do_throw("With noOverwrite, writeAtomic should have refused to overwrite file (" + suffix + ")");
} catch (err) {
if (err instanceof OS.File.Error && err.becauseExists) {
do_print("With noOverwrite, writeAtomic correctly failed (" + suffix + ")");
} else {
throw err;
}
} catch (err if err instanceof OS.File.Error && err.becauseExists) {
do_print("With noOverwrite, writeAtomic correctly failed (" + suffix + ")");
}
await reference_compare_files(pathSource, DEST_PATH, TEST);
@ -93,7 +89,7 @@ add_test_pair(async function read_write_all() {
await OS.File.remove(DEST_PATH);
await OS.File.remove(TMP_PATH);
})();
}
};
await test_with_options({tmpPath: TMP_PATH}, "Renaming, not flushing");
await test_with_options({tmpPath: TMP_PATH, flush: true}, "Renaming, flushing");

View File

@ -35,12 +35,8 @@ add_task(async function file_open_cannot_reset() {
let thrown = false;
try {
await OS.File.resetWorker();
} catch (ex) {
if (ex.message.indexOf(OS.Path.basename(TEST_FILE)) != -1 ) {
thrown = true;
} else {
throw ex;
}
} catch (ex if ex.message.indexOf(OS.Path.basename(TEST_FILE)) != -1 ) {
thrown = true;
}
do_check_true(thrown);
@ -56,12 +52,8 @@ add_task(async function dir_open_cannot_reset() {
let thrown = false;
try {
await OS.File.resetWorker();
} catch (ex) {
if (ex.message.indexOf(OS.Path.basename(TEST_DIR)) != -1 ) {
thrown = true;
} else {
throw ex;
}
} catch (ex if ex.message.indexOf(OS.Path.basename(TEST_DIR)) != -1 ) {
thrown = true;
}
do_check_true(thrown);
@ -95,7 +87,7 @@ add_task(async function finish_with_a_reset() {
} catch (ex) {
}
// Now reset
/* don't yield*/ OS.File.resetWorker();
/*don't yield*/ OS.File.resetWorker();
});
function run_test() {

View File

@ -59,12 +59,8 @@ add_task(async function system_shutdown() {
try {
await deferred.promise;
resolved = true;
} catch (ex) {
if (ex == "timeout") {
resolved = false;
} else {
throw ex;
}
} catch (ex if ex == "timeout") {
resolved = false;
}
Services.console.unregisterListener(observer);
Services.prefs.clearUserPref("toolkit.osfile.log");