mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +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
Notes:
sideshowbarker
2024-07-17 19:40:04 +09:00
Author: https://github.com/Hendiadyoin1
Commit: 89c82abf1f
Pull-request: https://github.com/SerenityOS/serenity/pull/12318
Reviewed-by: https://github.com/davidot
Reviewed-by: https://github.com/linusg ✅
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