1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * Functions and types related to SavedFrame objects created by the Debugger
11 #ifndef js_SavedFrameAPI_h
12 #define js_SavedFrameAPI_h
14 #include "jstypes.h" // JS_PUBLIC_API
16 #include "js/ColumnNumber.h" // JS::TaggedColumnNumberOneOrigin
17 #include "js/TypeDecls.h"
24 * Accessors for working with SavedFrame JSObjects
26 * Each of these functions assert that if their `HandleObject savedFrame`
27 * argument is non-null, its JSClass is the SavedFrame class (or it is a
28 * cross-compartment or Xray wrapper around an object with the SavedFrame class)
29 * and the object is not the SavedFrame.prototype object.
31 * Each of these functions will find the first SavedFrame object in the chain
32 * whose underlying stack frame principals are subsumed by the given
33 * |principals|, and operate on that SavedFrame object. This prevents leaking
34 * information about privileged frames to un-privileged callers
36 * The SavedFrame in parameters do _NOT_ need to be in the same compartment as
37 * the cx, and the various out parameters are _NOT_ guaranteed to be in the same
40 * You may consider or skip over self-hosted frames by passing
41 * `SavedFrameSelfHosted::Include` or `SavedFrameSelfHosted::Exclude`
44 * Additionally, it may be the case that there is no such SavedFrame object
45 * whose captured frame's principals are subsumed by |principals|! If the
46 * `HandleObject savedFrame` argument is null, or the |principals| do not
47 * subsume any of the chained SavedFrame object's principals,
48 * `SavedFrameResult::AccessDenied` is returned and a (hopefully) sane default
49 * value is chosen for the out param.
51 * See also `js/src/doc/SavedFrame/SavedFrame.md`.
54 enum class SavedFrameResult
{ Ok
, AccessDenied
};
56 enum class SavedFrameSelfHosted
{ Include
, Exclude
};
59 * Given a SavedFrame JSObject, get its source property. Defaults to the empty
62 extern JS_PUBLIC_API SavedFrameResult
GetSavedFrameSource(
63 JSContext
* cx
, JSPrincipals
* principals
, Handle
<JSObject
*> savedFrame
,
64 MutableHandle
<JSString
*> sourcep
,
65 SavedFrameSelfHosted selfHosted
= SavedFrameSelfHosted::Include
);
68 * Given a SavedFrame JSObject, get an ID identifying its ScriptSource.
71 extern JS_PUBLIC_API SavedFrameResult
GetSavedFrameSourceId(
72 JSContext
* cx
, JSPrincipals
* principals
, Handle
<JSObject
*> savedFrame
,
74 SavedFrameSelfHosted selfHosted
= SavedFrameSelfHosted::Include
);
77 * Given a SavedFrame JSObject, get its line property (1-origin).
80 extern JS_PUBLIC_API SavedFrameResult
GetSavedFrameLine(
81 JSContext
* cx
, JSPrincipals
* principals
, Handle
<JSObject
*> savedFrame
,
83 SavedFrameSelfHosted selfHosted
= SavedFrameSelfHosted::Include
);
86 * Given a SavedFrame JSObject, get its column property. Defaults to 0.
88 extern JS_PUBLIC_API SavedFrameResult
GetSavedFrameColumn(
89 JSContext
* cx
, JSPrincipals
* principals
, Handle
<JSObject
*> savedFrame
,
90 JS::TaggedColumnNumberOneOrigin
* columnp
,
91 SavedFrameSelfHosted selfHosted
= SavedFrameSelfHosted::Include
);
94 * Given a SavedFrame JSObject, get its functionDisplayName string, or nullptr
95 * if SpiderMonkey was unable to infer a name for the captured frame's
96 * function. Defaults to nullptr.
98 extern JS_PUBLIC_API SavedFrameResult
GetSavedFrameFunctionDisplayName(
99 JSContext
* cx
, JSPrincipals
* principals
, Handle
<JSObject
*> savedFrame
,
100 MutableHandle
<JSString
*> namep
,
101 SavedFrameSelfHosted selfHosted
= SavedFrameSelfHosted::Include
);
104 * Given a SavedFrame JSObject, get its asyncCause string. Defaults to nullptr.
106 extern JS_PUBLIC_API SavedFrameResult
GetSavedFrameAsyncCause(
107 JSContext
* cx
, JSPrincipals
* principals
, Handle
<JSObject
*> savedFrame
,
108 MutableHandle
<JSString
*> asyncCausep
,
109 SavedFrameSelfHosted selfHosted
= SavedFrameSelfHosted::Include
);
112 * Given a SavedFrame JSObject, get its asyncParent SavedFrame object or nullptr
113 * if there is no asyncParent. The `asyncParentp` out parameter is _NOT_
114 * guaranteed to be in the cx's compartment. Defaults to nullptr.
116 extern JS_PUBLIC_API SavedFrameResult
GetSavedFrameAsyncParent(
117 JSContext
* cx
, JSPrincipals
* principals
, Handle
<JSObject
*> savedFrame
,
118 MutableHandle
<JSObject
*> asyncParentp
,
119 SavedFrameSelfHosted selfHosted
= SavedFrameSelfHosted::Include
);
122 * Given a SavedFrame JSObject, get its parent SavedFrame object or nullptr if
123 * it is the oldest frame in the stack. The `parentp` out parameter is _NOT_
124 * guaranteed to be in the cx's compartment. Defaults to nullptr.
126 extern JS_PUBLIC_API SavedFrameResult
GetSavedFrameParent(
127 JSContext
* cx
, JSPrincipals
* principals
, Handle
<JSObject
*> savedFrame
,
128 MutableHandle
<JSObject
*> parentp
,
129 SavedFrameSelfHosted selfHosted
= SavedFrameSelfHosted::Include
);
132 * Given a SavedFrame object, convert it and its transitive parents to plain
133 * objects. Because SavedFrame objects store their properties on the prototype,
134 * they cannot be usefully stringified to JSON. Assigning their properties to
135 * plain objects allow those objects to be stringified and the saved frame stack
136 * can be encoded as a string.
138 JS_PUBLIC_API JSObject
* ConvertSavedFrameToPlainObject(
139 JSContext
* cx
, JS::HandleObject savedFrame
,
140 JS::SavedFrameSelfHosted selfHosted
);
147 * Get the first SavedFrame object in this SavedFrame stack whose principals are
148 * subsumed by the given |principals|. If there is no such frame, return
151 * Do NOT pass a non-SavedFrame object here.
153 extern JS_PUBLIC_API JSObject
* GetFirstSubsumedSavedFrame(
154 JSContext
* cx
, JSPrincipals
* principals
, JS::Handle
<JSObject
*> savedFrame
,
155 JS::SavedFrameSelfHosted selfHosted
);
159 #endif /* js_SavedFrameAPI_h */