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.
--- 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) {