Bug 1376128 - Use named options for JavaScriptError; r?automatedtester
Using the {foo = null} = {} shorthand to generate default values exposed
as function scope variables is more readable, and arguably somewhat safer,
than the current approach.
MozReview-Commit-ID: Lxn0fpBSR3a
--- a/testing/marionette/error.js
+++ b/testing/marionette/error.js
@@ -372,40 +372,36 @@ class JavaScriptError extends WebDriverE
* Name of the function to use in the stack trace message.
* @param {string=} file
* Filename of the test file on the client.
* @param {number=} line
* Line number of |file|.
* @param {string=} script
* Script being executed, in text form.
*/
- constructor (
- x,
- fnName = undefined,
- file = undefined,
- line = undefined,
- script = undefined) {
+ constructor(x,
+ {fnName = null, file = null, line = null, script = null} = {}) {
let msg = String(x);
let trace = "";
- if (fnName) {
+ if (fnName !== null) {
trace += fnName;
- if (file) {
+ if (file !== null) {
trace += ` @${file}`;
- if (line) {
+ if (line !== null) {
trace += `, line ${line}`;
}
}
}
if (error.isError(x)) {
let jsStack = x.stack.split("\n");
let match = jsStack[0].match(/:(\d+):\d+$/);
let jsLine = match ? parseInt(match[1]) : 0;
- if (script) {
+ if (script !== null) {
let src = script.split("\n")[jsLine];
trace += "\n" +
`inline javascript, line ${jsLine}\n` +
`src: "${src}"`;
}
trace += "\nStack:\n" + x.stack;
}
--- a/testing/marionette/evaluate.js
+++ b/testing/marionette/evaluate.js
@@ -153,22 +153,22 @@ evaluate.sandbox = function (sb, script,
// timeout and unload handlers
scriptTimeoutID = setTimeout(timeoutHandler, opts.timeout || DEFAULT_TIMEOUT);
sb.window.onunload = unloadHandler;
let res;
try {
res = Cu.evalInSandbox(src, sb, "1.8", opts.filename || "dummy file", 0);
} catch (e) {
- let err = new JavaScriptError(
- e,
- "execute_script",
- opts.filename,
- opts.line,
- script);
+ let err = new JavaScriptError(e, {
+ fnName: "execute_script",
+ file,
+ line,
+ script,
+ });
reject(err);
}
if (!opts.async) {
resolve(res);
}
});