Debian Codegraph @

js/src/doc/SavedFrame/index.md

raw
1 # SavedFrame
2
3 A `SavedFrame` instance is a singly linked list of stack frames. It represents a
4 JavaScript call stack at a past moment of execution. Younger frames hold a
5 reference to the frames that invoked them. The older tails are shared across
6 many younger frames.
7
8 `SavedFrame` stacks should generally be captured, allocated, and live within the
9 compartment that is being observed or debugged. Usually this is a content
10 compartment.
11
12 ## Capturing `SavedFrame` Stacks
13
14 ### From C++
15
16 Use `JS::CaptureCurrentStack` declared in `jsapi.h`.
17
18 ### From JS
19
20 Use `saveStack`, accessible via `Components.utils.getJSTestingFunction()`.
21
22 ## Including and Excluding Chrome Frames
23
24 Consider the following `SavedFrame` stack. Arrows represent links from child to
25 parent frame, `content.js` is from a compartment with content principals, and
26 `chrome.js` is from a compartment with chrome principals.
27
28 ```text
29 function A from content.js
30 |
31 V
32 function B from chrome.js
33 |
34 V
35 function C from content.js
36 ```
37 The content compartment will ever have one view of this stack: `A -> C`.
38
39 However, a chrome compartment has a choice: it can either take the same view
40 that the content compartment has (`A -> C`), or it can view all stack frames,
41 including the frames from chrome compartments (`A -> B -> C`). To view
42 everything, use an `XrayWrapper`. This is the default wrapper. To see the stack
43 as the content compartment sees it, waive the xray wrapper with
44 `Components.utils.waiveXrays`:
45
46 const contentViewOfStack = Components.utils.waiveXrays(someStack);
47
48 ## Accessor Properties of the `SavedFrame.prototype` Object
49
50 ### `source`
51 The source URL for this stack frame, as a string.
52
53 ### `sourceId`
54 The process-unique internal integer ID of this source. Usable to match up
55 a SavedFrame with a [Debugger.Source][dbg-source] using its `id` property.
56
57 ### `line`
58 The line number for this stack frame.
59
60 ### `column`
61 The column number for this stack frame.
62
63 ### `functionDisplayName`
64 Either SpiderMonkey's inferred name for this stack frame's function, or
65 `null`.
66
67 ### `asyncCause`
68 If this stack frame is the `asyncParent` of other stack frames, then this is
69 a string representing the type of asynchronous call by which this frame
70 invoked its children. For example, if this frame's children are calls to
71 handlers for a promise this frame created, this frame's `asyncCause` would
72 be `"Promise"`. If the asynchronous call was started in a descendant frame
73 to which the requester of the property does not have access, this will be
74 the generic string `"Async"`. If this is not an asynchronous call point,
75 this will be `null`.
76
77 ### `asyncParent`
78 If this stack frame was called as a result of an asynchronous operation, for
79 example if the function referenced by this frame is a promise handler, this
80 property points to the stack frame responsible for the asynchronous call,
81 for example where the promise was created. If the frame responsible for the
82 call is not accessible to the caller, this points to the youngest accessible
83 ancestor of the real frame, if any. In all other cases, this is `null`.
84
85 ### `parent`
86 This stack frame's caller, or `null` if this is the oldest frame on the
87 stack. In this case, there might be an `asyncParent` instead.
88
89 ## Function Properties of the `SavedFrame.prototype` Object
90
91 ### `toString()`
92 Return this frame and its parents formatted as a human readable stack trace
93 string.
94
95 [dbg-source]: ../Debugger/Debugger.Source.md