Bug 1874684 - Part 31: Correctly reject invalid durations in some RoundDuration calls...
[gecko.git] / js / public / SavedFrameAPI.h
blob02bc65a0ea27fe18c4a594e463085f9b0eada26c
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/. */
6 /*
7 * Functions and types related to SavedFrame objects created by the Debugger
8 * API.
9 */
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"
19 struct JSPrincipals;
21 namespace JS {
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
38 * compartment as cx.
40 * You may consider or skip over self-hosted frames by passing
41 * `SavedFrameSelfHosted::Include` or `SavedFrameSelfHosted::Exclude`
42 * respectively.
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 };
58 /**
59 * Given a SavedFrame JSObject, get its source property. Defaults to the empty
60 * string.
62 extern JS_PUBLIC_API SavedFrameResult GetSavedFrameSource(
63 JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
64 MutableHandle<JSString*> sourcep,
65 SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
67 /**
68 * Given a SavedFrame JSObject, get an ID identifying its ScriptSource.
69 * Defaults to 0.
71 extern JS_PUBLIC_API SavedFrameResult GetSavedFrameSourceId(
72 JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
73 uint32_t* sourceIdp,
74 SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
76 /**
77 * Given a SavedFrame JSObject, get its line property (1-origin).
78 * Defaults to 0.
80 extern JS_PUBLIC_API SavedFrameResult GetSavedFrameLine(
81 JSContext* cx, JSPrincipals* principals, Handle<JSObject*> savedFrame,
82 uint32_t* linep,
83 SavedFrameSelfHosted selfHosted = SavedFrameSelfHosted::Include);
85 /**
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);
93 /**
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);
142 } // namespace JS
144 namespace js {
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
149 * nullptr.
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);
157 } // namespace js
159 #endif /* js_SavedFrameAPI_h */