Bug 1386666 - Remove try..catch(ex if ex) statements from toolkit/components/osfile/ so that ESLint can parse the files. r?Mossop draft
authorDan Banner <dbugs@thebanners.uk>
Mon, 31 Jul 2017 16:34:04 +0100
changeset 620490 c32758bb432ac1819cbd54d54897ef856f2a6965
parent 620489 60882000fe28b57fd578045f420d473cdaa05d1d
child 640704 a432012eeb8a35421c8b5bcada7045c260641554
push id72047
push userbmo:dbugs@thebanners.uk
push dateThu, 03 Aug 2017 13:28:21 +0000
reviewersMossop
bugs1386666
milestone57.0a1
Bug 1386666 - Remove try..catch(ex if ex) statements from toolkit/components/osfile/ so that ESLint can parse the files. r?Mossop MozReview-Commit-ID: 786dBxzN3Uc
.eslintignore
toolkit/components/osfile/.eslintrc.js
toolkit/components/osfile/modules/osfile_async_front.jsm
toolkit/components/osfile/modules/osfile_shared_front.jsm
toolkit/components/osfile/modules/osfile_unix_front.jsm
toolkit/components/osfile/tests/mochi/main_test_osfile_async.js
toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js
toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js
toolkit/components/osfile/tests/xpcshell/.eslintrc.js
toolkit/components/osfile/tests/xpcshell/head.js
toolkit/components/osfile/tests/xpcshell/test_exception.js
toolkit/components/osfile/tests/xpcshell/test_open.js
toolkit/components/osfile/tests/xpcshell/test_osfile_async_append.js
toolkit/components/osfile/tests/xpcshell/test_osfile_async_copy.js
toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js
toolkit/components/osfile/tests/xpcshell/test_read_write.js
toolkit/components/osfile/tests/xpcshell/test_reset.js
toolkit/components/osfile/tests/xpcshell/test_shutdown.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -335,28 +335,28 @@ toolkit/components/help/**
 
 # Intentionally invalid JS
 toolkit/components/workerloader/tests/moduleF-syntax-error.js
 
 # Tests old non-star function generators
 toolkit/modules/tests/xpcshell/test_task.js
 
 # Not yet updated
-toolkit/components/osfile/**
 toolkit/components/url-classifier/**
 
 # External code:
 toolkit/components/microformats/test/**
 toolkit/components/microformats/microformat-shiv.js
 toolkit/components/reader/Readability.js
 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
 toolkit/mozapps/update/tests/data/xpcshellConstantsPP.js
 
 # Third party
 toolkit/modules/third_party/**
 third_party/**
new file mode 100644
--- /dev/null
+++ b/toolkit/components/osfile/.eslintrc.js
@@ -0,0 +1,32 @@
+"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",
+  }
+};
--- a/toolkit/components/osfile/modules/osfile_async_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_async_front.jsm
@@ -416,19 +416,19 @@ var Scheduler = this.Scheduler = {
       // If we have delayed sending SET_DEBUG, do it now.
       this.worker.post("SET_DEBUG", [true]);
       Scheduler.Debugging.messagesSent++;
     }
 
     Scheduler.Debugging.messagesQueued++;
     return this.push(async () => {
       if (this.shutdown) {
-	LOG("OS.File is not available anymore. The following request has been rejected.",
-	  method, args);
-	throw new Error("OS.File has been shut down. Rejecting request to " + method);
+        LOG("OS.File is not available anymore. The following request has been rejected.",
+          method, args);
+        throw new Error("OS.File has been shut down. Rejecting request to " + method);
       }
 
       // Update debugging information. As |args| may be quite
       // expensive, we only keep a shortened version of it.
       Scheduler.Debugging.latestReceived = null;
       Scheduler.Debugging.latestSent = [Date.now(), method, summarizeObject(args)];
 
       // Don't kill the worker just yet
@@ -1218,17 +1218,17 @@ File.removeDir = function(path, options 
 File.Info = function Info(value) {
   // Note that we can't just do this[k] = value[k] because our
   // prototype defines getters for all of these fields.
   for (let k in value) {
     if (k != "creationDate") {
       Object.defineProperty(this, k, {value: value[k]});
     }
   }
-  Object.defineProperty(this, "_deprecatedCreationDate", {value: value["creationDate"]});
+  Object.defineProperty(this, "_deprecatedCreationDate", {value: value.creationDate});
 };
 File.Info.prototype = SysAll.AbstractInfo.prototype;
 
 // Deprecated
 Object.defineProperty(File.Info.prototype, "creationDate", {
   get: function creationDate() {
     let {Deprecated} = Cu.import("resource://gre/modules/Deprecated.jsm", {});
     Deprecated.warning("Field 'creationDate' is deprecated.", "https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.File.Info#Cross-platform_Attributes");
--- a/toolkit/components/osfile/modules/osfile_shared_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_shared_front.jsm
@@ -147,34 +147,40 @@ AbstractFile.openUnique = function openU
   // We produce HEX numbers between 0 and 2^24 - 1.
   const MAX_HEX_NUMBER = 16777215;
 
   try {
     return {
       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);
+  } 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;
+          }
         }
-        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);
   }
 };
 
 /**
  * Code shared by iterators.
  */
 AbstractFile.AbstractIterator = function AbstractIterator() {
 };
@@ -334,18 +340,22 @@ AbstractFile.read = function read(path, 
       }
     }
     if (!("encoding" in options)) {
       return buffer;
     }
     let decoder;
     try {
       decoder = new TextDecoder(options.encoding);
-    } catch (ex if ex instanceof RangeError) {
-      throw OS.File.Error.invalidArgument("Decode");
+    } catch (ex) {
+      if (ex instanceof RangeError) {
+        throw OS.File.Error.invalidArgument("Decode");
+      } else {
+        throw ex;
+      }
     }
     return decoder.decode(buffer);
   } finally {
     file.close();
   }
 };
 
 /**
@@ -420,18 +430,22 @@ AbstractFile.writeAtomic =
   }
 
   let bytesWritten = 0;
 
   if (!options.tmpPath) {
     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.
+      } catch (ex) {
+        if (ex.becauseNoSuchFile) {
+          // The file doesn't exist, nothing to backup.
+        } else {
+          throw ex;
+        }
       }
     }
     // Just write, without any renaming trick
     let dest = OS.File.open(path, {write: true, truncate: true});
     try {
       bytesWritten = dest.write(buffer, options);
       if (options.flush) {
         dest.flush();
@@ -453,18 +467,22 @@ AbstractFile.writeAtomic =
     throw x;
   } finally {
     tmpFile.close();
   }
 
   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.
+    } catch (ex) {
+     if (ex.becauseNoSuchFile) {
+        // The file doesn't exist, nothing to backup.
+      } else {
+        throw ex;
+      }
     }
   }
 
   OS.File.move(options.tmpPath, path, {noCopy: true});
   return bytesWritten;
 };
 
 /**
--- a/toolkit/components/osfile/modules/osfile_unix_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_unix_front.jsm
@@ -1047,24 +1047,24 @@
      };
 
      /**
       * Get the current directory by getCurrentDirectory.
       */
      File.getCurrentDirectory = function getCurrentDirectory() {
        let path, buf;
        if (UnixFile.get_current_dir_name) {
-	 path = UnixFile.get_current_dir_name();
+         path = UnixFile.get_current_dir_name();
        } else if (UnixFile.getwd_auto) {
          path = UnixFile.getwd_auto(null);
        } else {
-	 for (let length = Const.PATH_MAX; !path; length *= 2) {
-	   buf = new (ctypes.char.array(length));
-	   path = UnixFile.getcwd(buf, length);
-	 };
+         for (let length = Const.PATH_MAX; !path; length *= 2) {
+           buf = new (ctypes.char.array(length));
+           path = UnixFile.getcwd(buf, length);
+         }
        }
        throw_on_null("getCurrentDirectory", path);
        return path.readString();
      };
 
      /**
       * Set the current directory by setCurrentDirectory.
       */
--- a/toolkit/components/osfile/tests/mochi/main_test_osfile_async.js
+++ b/toolkit/components/osfile/tests/mochi/main_test_osfile_async.js
@@ -339,20 +339,24 @@ var test_iter = maketest("iter", functio
     try {
       iterator = null;
       iterator = new OS.File.DirectoryIterator("/I do not exist");
       let exists = await iterator.exists();
       test.ok(!exists, "Before any iteration, iterator detects that the directory doesn't exist");
       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");
+      } 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;
+        }
       }
       test.ok(exn, "Iterating through a directory that does not exist has failed with becauseNoSuchFile");
     } finally {
       if (iterator) {
         iterator.close();
       }
     }
     test.ok(!!iterator, "The directory iterator for a non-existing directory was correctly created");
@@ -415,10 +419,8 @@ var test_debug_test = maketest("debug_te
       }
     };
     toggleDebugTest(true, consoleListener);
     // Execution of OS.File.exist method will trigger OS.File.LOG several times.
     let fileExists = await OS.File.exists(EXISTING_FILE);
     toggleDebugTest(false, consoleListener);
   })();
 });
-
-
--- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js
+++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_unix.js
@@ -187,15 +187,18 @@ function test_passing_undefined()
   info("Testing that an exception gets thrown when an FFI function is passed undefined");
   let exceptionRaised = false;
 
   try {
     let file = OS.Unix.File.open(undefined, OS.Constants.libc.O_RDWR
                                             | 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;
+  } catch(e) {
+    if (e instanceof TypeError && e.message.indexOf("open") > -1) {
+      exceptionRaised = true;
+    } else {
+      throw e;
+    }
   }
 
   ok(exceptionRaised, "test_passing_undefined: exception gets thrown")
 }
-
--- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js
+++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_win.js
@@ -198,14 +198,18 @@ function test_passing_undefined()
     let file = OS.Win.File.CreateFile(
       undefined,
       OS.Constants.Win.GENERIC_READ,
       0,
       null,
       OS.Constants.Win.OPEN_EXISTING,
       0,
       null);
-  } catch(e if e instanceof TypeError && e.message.indexOf("CreateFile") > -1) {
-    exceptionRaised = true;
+  } catch(e) {
+    if (e instanceof TypeError && e.message.indexOf("CreateFile") > -1) {
+      exceptionRaised = true;
+    } else {
+      throw e;
+    }
   }
 
   ok(exceptionRaised, "test_passing_undefined: exception gets thrown")
 }
--- a/toolkit/components/osfile/tests/xpcshell/.eslintrc.js
+++ b/toolkit/components/osfile/tests/xpcshell/.eslintrc.js
@@ -1,7 +1,11 @@
 "use strict";
 
 module.exports = {
   "extends": [
     "plugin:mozilla/xpcshell-test"
-  ]
+  ],
+
+  "rules": {
+    "no-shadow": "off",
+  }
 };
--- a/toolkit/components/osfile/tests/xpcshell/head.js
+++ b/toolkit/components/osfile/tests/xpcshell/head.js
@@ -90,8 +90,18 @@ function reference_fetch_file(path, test
 function reference_compare_files(a, b, test) {
   return (async function() {
     do_print("Comparing files " + a + " and " + b);
     let a_contents = await reference_fetch_file(a, test);
     let b_contents = await reference_fetch_file(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);
+    }
+  }
+}
--- a/toolkit/components/osfile/tests/xpcshell/test_exception.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_exception.js
@@ -26,64 +26,88 @@ add_test_pair(async function test_typeer
 
 // Tests on |read|
 
 add_test_pair(async function test_bad_encoding() {
   do_print("Testing with a wrong 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");
+  } catch (ex) {
+    if (ex.becauseInvalidArgument) {
+      do_print("Wrong encoding caused the correct exception");
+    } else {
+      throw ex;
+    }
   }
 
   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");
+  } 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;
+    }
   }
- });
+});
 
 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");
+  } catch (ex) {
+    if (ex.becauseInvalidArgument) {
+      do_print("Wrong encoding caused the correct exception");
+    } else {
+      throw ex;
+    }
   }
 
   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");
+  } 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;
+    }
   }
 });
 
 add_test_pair(async function test_bad_bytes() {
   do_print("Testing with a bad type for option 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");
+  } 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;
+    }
   }
 });
 
 add_test_pair(async function read_non_existent() {
   do_print("Testing with a non-existent file");
   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");
+  } catch (ex) {
+    if (ex.becauseNoSuchFile) {
+      do_print("Correct exceptions");
+    } else {
+      throw ex;
+    }
   }
 });
 
 function run_test() {
   run_next_test();
 }
--- a/toolkit/components/osfile/tests/xpcshell/test_open.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_open.js
@@ -14,22 +14,25 @@ function run_test() {
  * - with an existing file (should succeed);
  * - with a non-existing file (should fail);
  * - with inconsistent arguments (should fail).
  */
 add_task(async function() {
   // Attempt to open a file that does not exist, ensure that it yields the
   // appropriate error.
   try {
-    let fd = await OS.File.open(OS.Path.join(".", "This file does not exist"));
+    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);
+  } catch (err) {
+    if (err instanceof OS.File.Error && err.becauseNoSuchFile) {
+      do_print("File opening 1 failed " + err);
+    } else {
+      throw 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");
   try {
     let fd = await OS.File.open(1, 2, 3);
     do_check_true(false, "File opening 2 succeeded (it should fail)" + fd);
   } catch (err) {
     do_print("File opening 2 failed " + err);
--- a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_append.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_append.js
@@ -22,21 +22,17 @@ function setup_mode(mode) {
 }
 
 // Test append mode.
 async function test_append(mode) {
   let path = OS.Path.join(OS.Constants.Path.tmpDir,
                           "test_osfile_async_append.tmp");
 
   // Clear any left-over files from previous runs.
-  try {
-    await OS.File.remove(path);
-  } catch (ex if ex.becauseNoSuchFile) {
-    // ignore
-  }
+  await removeTestFile(path)
 
   try {
     mode = setup_mode(mode);
     mode.append = true;
     if (mode.trunc) {
       // Pre-fill file with some data to see if |trunc| actually works.
       await OS.File.writeAtomic(path, new Uint8Array(500));
     }
@@ -48,36 +44,28 @@ async function test_append(mode) {
       // Should be at offset 100, length 1000 now.
       await file.write(new Uint8Array(100));
       // Should be at offset 1100, length 1100 now.
       let stat = await file.stat();
       do_check_eq(1100, stat.size);
     } finally {
       await file.close();
     }
-  } catch(ex) {
-    try {
-      await OS.File.remove(path);
-    } catch (ex if ex.becauseNoSuchFile) {
-      // ignore.
-    }
+  } catch (ex) {
+    await removeTestFile(path)
   }
 }
 
 // Test no-append mode.
 async function test_no_append(mode) {
   let path = OS.Path.join(OS.Constants.Path.tmpDir,
                           "test_osfile_async_noappend.tmp");
 
   // Clear any left-over files from previous runs.
-  try {
-    await OS.File.remove(path);
-  } catch (ex if ex.becauseNoSuchFile) {
-    // ignore
-  }
+  await removeTestFile(path)
 
   try {
     mode = setup_mode(mode);
     mode.append = false;
     if (mode.trunc) {
       // Pre-fill file with some data to see if |trunc| actually works.
       await OS.File.writeAtomic(path, new Uint8Array(500));
     }
@@ -90,28 +78,24 @@ async function test_no_append(mode) {
       await file.write(new Uint8Array(100));
       // Should be at offset 200, length 1000 now.
       let stat = await file.stat();
       do_check_eq(1000, stat.size);
     } finally {
       await file.close();
     }
   } finally {
-    try {
-      await OS.File.remove(path);
-    } catch (ex if ex.becauseNoSuchFile) {
-      // ignore.
-    }
+    await removeTestFile(path)
   }
 }
 
 var test_flags = [
   {},
-  {create:true},
-  {trunc:true}
+  {create: true},
+  {trunc: true}
 ];
 function run_test() {
   do_test_pending();
 
   for (let t of test_flags) {
     add_task(test_append.bind(null, t));
     add_task(test_no_append.bind(null, t));
   }
--- a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_copy.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_copy.js
@@ -85,26 +85,18 @@ async function test_copymove(options = {
     await OS.File.copy(source, dest, options);
     await reference_compare_files(source, dest);
     // 2. Test subsequent move.
     await OS.File.move(dest, dest2);
     await reference_compare_files(source, dest2);
     // 3. Check that the moved file was really moved.
     do_check_eq((await OS.File.exists(dest)), false);
   } finally {
-    try {
-      await OS.File.remove(dest);
-    } catch (ex if ex.becauseNoSuchFile) {
-      // ignore
-    }
-    try {
-      await OS.File.remove(dest2);
-    } catch (ex if ex.becauseNoSuchFile) {
-      // ignore
-    }
+    await removeTestFile(dest);
+    await removeTestFile(dest2);
   }
 }
 
 // Regular copy test.
 add_task(test_copymove);
 // Userland copy test.
 add_task(test_copymove.bind(null, {unixUserland: true}));
 
--- a/toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_largefiles.js
@@ -12,21 +12,17 @@ Components.utils.import("resource://gre/
  */
 
 // Test setPosition/getPosition.
 async function test_setPosition(forward, current, backward) {
   let path = OS.Path.join(OS.Constants.Path.tmpDir,
                           "test_osfile_async_largefiles.tmp");
 
   // Clear any left-over files from previous runs.
-  try {
-    await OS.File.remove(path);
-  } catch (ex if ex.becauseNoSuchFile) {
-    // ignore
-  }
+  await removeTestFile(path);
 
   try {
     let file = await OS.File.open(path, {write:true, append:false});
     try {
       let pos = 0;
 
       // 1. seek forward from start
       do_print("Moving forward: " + forward);
@@ -46,36 +42,27 @@ async function test_setPosition(forward,
       pos -= backward;
       do_check_eq((await file.getPosition()), pos);
 
     } finally {
       await file.setPosition(0, OS.File.POS_START);
       await file.close();
     }
   } catch(ex) {
-    try {
-      await OS.File.remove(path);
-    } catch (ex if ex.becauseNoSuchFile) {
-      // ignore.
-    }
-    do_throw(ex);
+    await removeTestFile(path);
   }
 }
 
 // Test setPosition/getPosition expected failures.
 async function test_setPosition_failures() {
   let path = OS.Path.join(OS.Constants.Path.tmpDir,
                           "test_osfile_async_largefiles.tmp");
 
   // Clear any left-over files from previous runs.
-  try {
-    await OS.File.remove(path);
-  } catch (ex if ex.becauseNoSuchFile) {
-    // ignore
-  }
+  await removeTestFile(path);
 
   try {
     let file = await OS.File.open(path, {write:true, append:false});
     try {
       let pos = 0;
 
       // 1. Use an invalid position value
       try {
@@ -109,21 +96,17 @@ async function test_setPosition_failures
       } catch (ex) {
         do_print(ex.toString());
         do_check_true(!!ex);
       }
 
     } finally {
       await file.setPosition(0, OS.File.POS_START);
       await file.close();
-      try {
-        await OS.File.remove(path);
-      } catch (ex if ex.becauseNoSuchFile) {
-        // ignore.
-      }
+      await removeTestFile(path);
     }
   } catch(ex) {
     do_throw(ex);
   }
 }
 
 function run_test() {
   // First verify stuff works for small values.
--- a/toolkit/components/osfile/tests/xpcshell/test_read_write.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_read_write.js
@@ -57,18 +57,22 @@ add_test_pair(async function read_write_
       // file already exists!
       contents = new Uint8Array(300);
       let view = new Uint8Array(contents.buffer, 10, 200);
       try {
         let opt = JSON.parse(JSON.stringify(options));
         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 + ")");
+      } catch (err) {
+        if (err instanceof OS.File.Error && err.becauseExists) {
+          do_print("With noOverwrite, writeAtomic correctly failed (" + suffix + ")");
+        } else {
+          throw err;
+        }
       }
       await reference_compare_files(pathSource, DEST_PATH, TEST);
 
       // Check that temporary file was removed or never created
       do_check_false(new FileUtils.File(TMP_PATH).exists());
 
       // Now write a subset
       let START = 10;
@@ -84,17 +88,17 @@ add_test_pair(async function read_write_
       do_check_eq(LENGTH, array2.length);
       for (var i = 0; i < LENGTH; i++)
         do_check_eq(array2[i], (i + START) % 256);
 
       // Cleanup.
       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");
   await test_with_options({}, "Not renaming, not flushing");
   await test_with_options({flush: true}, "Not renaming, flushing");
 });
 
 
--- a/toolkit/components/osfile/tests/xpcshell/test_reset.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_reset.js
@@ -30,35 +30,43 @@ add_task(async function transparent_rese
 
 add_task(async function file_open_cannot_reset() {
   let TEST_FILE = OS.Path.join(Path.profileDir, "tmp-" + Math.random());
   do_print("Leaking file descriptor " + TEST_FILE + ", we shouldn't be able to reset");
   let openedFile = await OS.File.open(TEST_FILE, { create: true} );
   let thrown = false;
   try {
     await OS.File.resetWorker();
-  } catch (ex if ex.message.indexOf(OS.Path.basename(TEST_FILE)) != -1 ) {
-    thrown = true;
+  } catch (ex) {
+    if (ex.message.indexOf(OS.Path.basename(TEST_FILE)) != -1 ) {
+      thrown = true;
+    } else {
+      throw ex;
+    }
   }
   do_check_true(thrown);
 
   do_print("Closing the file, we should now be able to reset");
   await openedFile.close();
   await OS.File.resetWorker();
 });
 
 add_task(async function dir_open_cannot_reset() {
   let TEST_DIR = await OS.File.getCurrentDirectory();
   do_print("Leaking directory " + TEST_DIR + ", we shouldn't be able to reset");
   let iterator = new OS.File.DirectoryIterator(TEST_DIR);
   let thrown = false;
   try {
     await OS.File.resetWorker();
-  } catch (ex if ex.message.indexOf(OS.Path.basename(TEST_DIR)) != -1 ) {
-    thrown = true;
+  } catch (ex) {
+    if (ex.message.indexOf(OS.Path.basename(TEST_DIR)) != -1 ) {
+      thrown = true;
+    } else {
+      throw ex;
+    }
   }
   do_check_true(thrown);
 
   do_print("Closing the directory, we should now be able to reset");
   await iterator.close();
   await OS.File.resetWorker();
 });
 
@@ -82,14 +90,14 @@ add_task(async function race_against_its
 add_task(async function finish_with_a_reset() {
   do_print("Reset without waiting for the result");
   // Arbitrary operation, just to wake up the worker
   try {
     await OS.File.read("/foo");
   } catch (ex) {
   }
   // Now reset
-  /*don't yield*/ OS.File.resetWorker();
+  /* don't yield*/ OS.File.resetWorker();
 });
 
 function run_test() {
   run_next_test();
 }
--- a/toolkit/components/osfile/tests/xpcshell/test_shutdown.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_shutdown.js
@@ -54,18 +54,22 @@ add_task(async function system_shutdown(
         do_print("Timeout while waiting for resource: " + resource);
         deferred.reject("timeout");
       });
 
       let resolved = false;
       try {
         await deferred.promise;
         resolved = true;
-      } catch (ex if ex == "timeout") {
-        resolved = false;
+      } catch (ex) {
+        if (ex == "timeout") {
+          resolved = false;
+        } else {
+          throw ex;
+        }
       }
       Services.console.unregisterListener(observer);
       Services.prefs.clearUserPref("toolkit.osfile.log");
       Services.prefs.clearUserPref("toolkit.osfile.log.redirect");
       Services.prefs.clearUserPref("toolkit.osfile.test.shutdown.observer");
       Services.prefs.clearUserPref("toolkit.async_shutdown.testing");
 
       return resolved;