From 2f468040aa470da660b0b52ed02550797d318518 Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Wed, 2 Aug 2017 11:47:42 -0700 Subject: [PATCH] Backed out changeset 856215476aa4 (bug 1386666) for eslint failures a=backout MozReview-Commit-ID: FdO8WkzBvfj --- .eslintignore | 2 +- toolkit/components/osfile/.eslintrc.js | 32 ---------- .../osfile/modules/osfile_shared_front.jsm | 60 +++++++------------ .../tests/mochi/main_test_osfile_async.js | 14 ++--- .../tests/mochi/worker_test_osfile_unix.js | 9 +-- .../tests/mochi/worker_test_osfile_win.js | 8 +-- .../osfile/tests/xpcshell/.eslintrc.js | 6 +- .../components/osfile/tests/xpcshell/head.js | 10 ---- .../osfile/tests/xpcshell/test_exception.js | 56 +++++------------ .../osfile/tests/xpcshell/test_open.js | 11 ++-- .../xpcshell/test_osfile_async_append.js | 30 +++++++--- .../tests/xpcshell/test_osfile_async_copy.js | 12 +++- .../xpcshell/test_osfile_async_largefiles.js | 25 ++++++-- .../osfile/tests/xpcshell/test_read_write.js | 10 +--- .../osfile/tests/xpcshell/test_reset.js | 18 ++---- .../osfile/tests/xpcshell/test_shutdown.js | 8 +-- 16 files changed, 118 insertions(+), 193 deletions(-) delete mode 100644 toolkit/components/osfile/.eslintrc.js diff --git a/.eslintignore b/.eslintignore index 5609d96ff5fe..ae97d88107d4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -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 diff --git a/toolkit/components/osfile/.eslintrc.js b/toolkit/components/osfile/.eslintrc.js deleted file mode 100644 index e4f5f33a77d7..000000000000 --- a/toolkit/components/osfile/.eslintrc.js +++ /dev/null @@ -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", - } -}; diff --git a/toolkit/components/osfile/modules/osfile_shared_front.jsm b/toolkit/components/osfile/modules/osfile_shared_front.jsm index 61c935d63363..a2971991d4cf 100644 --- a/toolkit/components/osfile/modules/osfile_shared_front.jsm +++ b/toolkit/components/osfile/modules/osfile_shared_front.jsm @@ -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. } } diff --git a/toolkit/components/osfile/tests/mochi/main_test_osfile_async.js b/toolkit/components/osfile/tests/mochi/main_test_osfile_async.js index 538efad482cb..d875548efdcf 100644 --- a/toolkit/components/osfile/tests/mochi/main_test_osfile_async.js +++ b/toolkit/components/osfile/tests/mochi/main_test_osfile_async.js @@ -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); })(); }); + + diff --git a/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js b/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js index cf1a11def7d5..9fe2d0b4e655 100644 --- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js +++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js @@ -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") } + diff --git a/toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js b/toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js index f4a87c0ac590..f41fdecfeac5 100644 --- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js +++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js @@ -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") diff --git a/toolkit/components/osfile/tests/xpcshell/.eslintrc.js b/toolkit/components/osfile/tests/xpcshell/.eslintrc.js index d4b574ff14d9..70fe35407782 100644 --- a/toolkit/components/osfile/tests/xpcshell/.eslintrc.js +++ b/toolkit/components/osfile/tests/xpcshell/.eslintrc.js @@ -3,9 +3,5 @@ module.exports = { "extends": [ "plugin:mozilla/xpcshell-test" - ], - - "rules": { - "no-shadow": "off", - } + ] }; diff --git a/toolkit/components/osfile/tests/xpcshell/head.js b/toolkit/components/osfile/tests/xpcshell/head.js index 657b1ef91ba4..4c826c26e032 100644 --- a/toolkit/components/osfile/tests/xpcshell/head.js +++ b/toolkit/components/osfile/tests/xpcshell/head.js @@ -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); - } - } -} diff --git a/toolkit/components/osfile/tests/xpcshell/test_exception.js b/toolkit/components/osfile/tests/xpcshell/test_exception.js index cf4fad1de214..0fab158f72e7 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_exception.js +++ b/toolkit/components/osfile/tests/xpcshell/test_exception.js @@ -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"); } }); diff --git a/toolkit/components/osfile/tests/xpcshell/test_open.js b/toolkit/components/osfile/tests/xpcshell/test_open.js index 51339e1156b1..a8a449644873 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_open.js +++ b/toolkit/components/osfile/tests/xpcshell/test_open.js @@ -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"); diff --git a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_append.js b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_append.js index dba9b10e586d..94cd2dd622c1 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_append.js +++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_append.js @@ -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(); diff --git a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_copy.js b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_copy.js index 555e298773aa..651669ff5e7a 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_copy.js +++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_copy.js @@ -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 + } } } diff --git a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js index ab9a5372a29b..16775c061bc6 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js +++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js @@ -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); diff --git a/toolkit/components/osfile/tests/xpcshell/test_read_write.js b/toolkit/components/osfile/tests/xpcshell/test_read_write.js index 227010329fff..1ea0bdb628ea 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_read_write.js +++ b/toolkit/components/osfile/tests/xpcshell/test_read_write.js @@ -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"); diff --git a/toolkit/components/osfile/tests/xpcshell/test_reset.js b/toolkit/components/osfile/tests/xpcshell/test_reset.js index 63531d26fe8f..165208d491cd 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_reset.js +++ b/toolkit/components/osfile/tests/xpcshell/test_reset.js @@ -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() { diff --git a/toolkit/components/osfile/tests/xpcshell/test_shutdown.js b/toolkit/components/osfile/tests/xpcshell/test_shutdown.js index 6cd6716ca858..2d50c3b65135 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_shutdown.js +++ b/toolkit/components/osfile/tests/xpcshell/test_shutdown.js @@ -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");