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

--HG--
extra : rebase_source : 63fa829657d726e8987a77b5add817a3b7d0b7d3
This commit is contained in:
Andreas Tolfsen 2017-06-28 11:24:58 -07:00
Родитель ed364ef1d6
Коммит ee51d983c0
2 изменённых файлов: 12 добавлений и 16 удалений

Просмотреть файл

@ -377,20 +377,16 @@ class JavaScriptError extends WebDriverError {
* @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}`;
}
}
@ -400,7 +396,7 @@ class JavaScriptError extends WebDriverError {
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` +

Просмотреть файл

@ -158,12 +158,12 @@ evaluate.sandbox = function (sb, script, args = [], opts = {}) {
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);
}