Bug 1240550 - Make fnName, file, and line optional arguments; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 18 Jan 2016 18:55:52 +0000
changeset 322698 86130c7b028763f81efa0829c43b3e0c8a73f6b8
parent 322386 a77b73c7723e1060993045fb31eb2f0a30473486
child 513151 0c5ebbe6ca1c41851e647d6a55815744b0687daf
push id9655
push useratolfsen@mozilla.com
push dateTue, 19 Jan 2016 14:09:16 +0000
reviewersautomatedtester
bugs1240550
milestone46.0a1
Bug 1240550 - Make fnName, file, and line optional arguments; r?automatedtester Previously fnName and line was tested as the entry requirement for printing the filename to the trace information. Testing line here was premature since it is meant to be an optional argument. This patch rectifies this behaviour by testing for each of the optional arguments sequentially. This means the file argument is required to print the line, and the fnName argument is required to print any of those two.
testing/marionette/error.js
--- a/testing/marionette/error.js
+++ b/testing/marionette/error.js
@@ -163,35 +163,39 @@ this.InvalidSessionIdError = function(ms
 InvalidSessionIdError.prototype = Object.create(WebDriverError.prototype);
 
 /**
  * Creates an error message for a JavaScript error thrown during
  * executeScript or executeAsyncScript.
  *
  * @param {Error} err
  *     An Error object passed to a catch block or a message.
- * @param {string} fnName
+ * @param {string=} fnName
  *     The name of the function to use in the stack trace message
  *     (e.g. execute_script).
- * @param {string} file
+ * @param {string=} file
  *     The filename of the test file containing the Marionette
  *     command that caused this error to occur.
- * @param {number} line
+ * @param {number=} line
  *     The line number of the above test file.
  * @param {string=} script
  *     The JS script being executed in text form.
  */
-this.JavaScriptError = function(err, fnName, file, line, script) {
+this.JavaScriptError = function(
+    err, fnName = null, file = null, line = null, script = null) {
   let msg = String(err);
   let trace = "";
 
-  if (fnName && line) {
-    trace += `${fnName} @${file}`;
-    if (line) {
-      trace += `, line ${line}`;
+  if (fnName) {
+    trace += fnName;
+    if (file) {
+      trace += ` @${file}`;
+      if (line) {
+        trace += `, line ${line}`;
+      }
     }
   }
 
   if (typeof err == "object" && "name" in err && "stack" in err) {
     let jsStack = err.stack.split("\n");
     let match = jsStack[0].match(/:(\d+):\d+$/);
     let jsLine = match ? parseInt(match[1]) : 0;
     if (script) {