Debian Codegraph @

js/src/jit-test/tests/errors/capture-stack-async.js

raw
1 // |jit-test| skip-if: getBuildConfiguration("release_or_beta"); --setpref=experimental.error_capture_stack_trace;
2
3 function test_async_reparenting_with_filter() {
4 let obj = {};
5 let err = undefined;
6
7 async function caller(callee) {
8 return callee();
9 }
10
11
12 async function* a() {
13 yield {};
14 Error.captureStackTrace(obj, caller)
15 err = new Error;
16 yield {};
17 }
18
19 async function b() {
20 return { a: 10 }
21 }
22
23
24 b().then(async () => {
25 caller(async () => {
26 let g = a();
27 await g.next();
28 await g.next();
29 await g.next();
30 })
31 }).then(() => {
32 // Note: No browser is re-parenting a stack and then filtering.
33 // So Safari & Chrome both report empty stacks for obj, where
34 // the stack obtained through Error is re-parented.
35 //
36 // Chrome 132:
37 // Error
38 // at a (<anonymous>:12:11)
39 // at a.next (<anonymous>)
40 // at <anonymous>:24:17
41 //
42 // Safari
43 // @
44 // @
45 //
46 console.log("Capture: ")
47 console.log(obj.stack);
48 console.log("Stack")
49 console.log(err.stack);
50 assertEq(obj.stack, "");
51 assertEq(err.stack == "", false);
52 })
53 }
54 test_async_reparenting_with_filter();
55
56
57
58 function test_async_reparenting_without_filter() {
59 let obj = {};
60 let err = undefined;
61
62 async function caller(callee) {
63 return callee();
64 }
65
66
67 async function* a() {
68 yield {};
69 Error.captureStackTrace(obj)
70 err = new Error;
71 yield {};
72 }
73
74 async function b() {
75 return { a: 10 }
76 }
77
78
79 b().then(async () => {
80 caller(async () => {
81 let g = a();
82 await g.next();
83 await g.next();
84 await g.next();
85 })
86 }).then(() => {
87 // Note: In the shell we re-parent this stack and so get the same
88 // stack as the Error getter.
89 console.log("Capture: ")
90 console.log(obj.stack);
91 console.log("Stack")
92 console.log(err.stack);
93 assertEq(obj.stack.length, err.stack.length);
94 })
95 }
96 test_async_reparenting_without_filter();