mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:27:44 +00:00
LibJS: Implement non standard error.stack attribute
All other browser already support this feature. There is a Stage 1 proposal to standardize this, but it does not seem to be active.
This commit is contained in:
parent
8c3942d90c
commit
89c82abf1f
6 changed files with 100 additions and 0 deletions
28
Userland/Libraries/LibJS/Tests/error-stack.js
Normal file
28
Userland/Libraries/LibJS/Tests/error-stack.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
test("Anonymous function", function () {
|
||||
let stackString = (() => {
|
||||
return Error();
|
||||
})().stack;
|
||||
let [header, ...stackFrames] = stackString.split("\n");
|
||||
|
||||
expect(header).toBe("Error");
|
||||
expect(!!stackFrames[0].match(/^ at Error \(.*\/error-stack\.js:3:\d+\)$/)).toBeTrue();
|
||||
expect(!!stackFrames[1].match(/^ at .*\/error-stack\.js:3:\d+$/)).toBeTrue();
|
||||
expect(!!stackFrames[2].match(/^ at .*\/error-stack\.js:2:\d+$/)).toBeTrue();
|
||||
});
|
||||
|
||||
test("Named function with message", function () {
|
||||
function f() {
|
||||
throw Error("You Shalt Not Pass!");
|
||||
}
|
||||
try {
|
||||
f();
|
||||
} catch (e) {
|
||||
let stackString = e.stack;
|
||||
let [header, ...stack_frames] = stackString.split("\n");
|
||||
|
||||
expect(header).toBe("Error: You Shalt Not Pass!");
|
||||
expect(!!stack_frames[0].match(/^ at Error \(.*\/error-stack\.js:15:\d+\)$/)).toBeTrue();
|
||||
expect(!!stack_frames[1].match(/^ at f \(.*\/error-stack\.js:15:\d+\)$/)).toBeTrue();
|
||||
expect(!!stack_frames[2].match(/^ at .*\/error-stack\.js:18:\d+$/)).toBeTrue();
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue