Debian Codegraph @

js/src/jit-test/tests/saved-stacks/async-livecache.js

raw
1 // Async stacks should not supplant LiveSavedFrameCache hits.
2
3 top();
4
5 // An ordinary function, to give the frame a convenient name.
6 function top() {
7 // Perform an async call. F will run in an activation that has an async stack
8 // supplied.
9 f().catch(catchError);
10 }
11
12 async function f() {
13 // Perform an ordinary call. Its parent frame will be a LiveSavedFrameCache
14 // hit.
15 g();
16 }
17
18 function g() {
19 // Populate the LiveSavedFrameCache.
20 saveStack();
21
22 // Capturing the stack again should find f (if not g) in the cache. The async
23 // stack supplied below the call to f should not supplant f's own frame.
24 let frame = saveStack();
25
26 assertEq(frame.functionDisplayName, 'g');
27 assertEq(parent(frame).functionDisplayName, 'f');
28 assertEq(parent(parent(frame)).functionDisplayName, 'top');
29 }
30
31 // Return the parent of |frame|, skipping self-hosted code and following async
32 // parent links.
33 function parent(frame) {
34 do {
35 frame = frame.parent || frame.asyncParent;
36 } while (frame.source.match(/self-hosted/));
37 return frame;
38 }
39
40 function catchError(e) {
41 print(`${e}\n${e.stack}`);
42 quit(1)
43 }