зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1394849 - Add error.stack to create stacktraces. r=automatedtester
This patch introduces a new error.stack function as a shorthand for creating stacktraces. It is equivalent to calling new Error().stack and removing the first line of the stack. Removing the first line is needed to make it appear as if the error originated from the caller's position in the program. MozReview-Commit-ID: DpSSWU5vPDm --HG-- extra : rebase_source : 52697e348367b2b7dbeb28a711a9bd1fdef076ec
This commit is contained in:
Родитель
7b0b197759
Коммит
482df6f9bf
|
@ -48,6 +48,7 @@ const BUILTIN_ERRORS = new Set([
|
|||
this.EXPORTED_SYMBOLS = [
|
||||
"error",
|
||||
"pprint",
|
||||
"stack",
|
||||
].concat(Array.from(ERRORS));
|
||||
|
||||
/** @namespace */
|
||||
|
@ -215,6 +216,14 @@ this.pprint = function(ss, ...values) {
|
|||
return res.join("");
|
||||
};
|
||||
|
||||
/** Create a stacktrace to the current line in the program. */
|
||||
this.stack = function() {
|
||||
let trace = new Error().stack;
|
||||
let sa = trace.split("\n");
|
||||
sa = sa.slice(1);
|
||||
return "stacktrace:\n" + sa.join("\n");
|
||||
};
|
||||
|
||||
/**
|
||||
* WebDriverError is the prototypal parent of all WebDriver errors.
|
||||
* It should not be used directly, as it does not correspond to a real
|
||||
|
|
|
@ -24,6 +24,7 @@ const {
|
|||
pprint,
|
||||
ScriptTimeoutError,
|
||||
SessionNotCreatedError,
|
||||
stack,
|
||||
StaleElementReferenceError,
|
||||
TimeoutError,
|
||||
UnableToSetCookieError,
|
||||
|
@ -144,6 +145,14 @@ add_test(function test_pprint() {
|
|||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_stack() {
|
||||
equal("string", typeof stack());
|
||||
ok(stack().includes("test_stack"));
|
||||
ok(!stack().includes("add_test"));
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_toJSON() {
|
||||
let e0 = new WebDriverError();
|
||||
let e0s = e0.toJSON();
|
||||
|
|
Загрузка…
Ссылка в новой задаче