FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
WebKit/Source/JavaScriptCore/inspector/AsyncStackTrace.cpp at main · WebKit/WebKit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
WebKit
/
WebKit
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Pull requests
2.6k
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
WebKit
/
Source
/
JavaScriptCore
/
inspector
/
AsyncStackTrace.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
219 lines (173 loc) · 6.57 KB
Breadcrumbs
WebKit
/
Source
/
JavaScriptCore
/
inspector
/
AsyncStackTrace.cpp
Copy path
File metadata and controls
219 lines (173 loc) · 6.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#
include
"
config.h
"
#
include
"
AsyncStackTrace.h
"
#
include
"
ScriptCallStack.h
"
#
include
<
wtf/Ref.h
>
namespace
Inspector
{
Ref<AsyncStackTrace>
AsyncStackTrace::create
(Ref<ScriptCallStack>&& callStack,
bool
singleShot, RefPtr<AsyncStackTrace> parent)
{
return
adoptRef
(*
new
AsyncStackTrace
(
WTF::move
(callStack), singleShot,
WTF::move
(parent)));
}
AsyncStackTrace::AsyncStackTrace
(Ref<ScriptCallStack>&& callStack,
bool
singleShot, RefPtr<AsyncStackTrace> parent)
: m_callStack(
WTF
::move(callStack))
, m_parent(parent)
, m_singleShot(singleShot)
{
ASSERT
(
size
());
if
(m_parent)
m_parent->
m_childCount
++;
}
AsyncStackTrace::~AsyncStackTrace
()
{
if
(m_parent)
remove
();
ASSERT
(!m_childCount);
}
bool
AsyncStackTrace::isPending
()
const
{
return
m_state == State::Pending;
}
bool
AsyncStackTrace::isLocked
()
const
{
return
m_state == State::Pending || m_state == State::Active || m_childCount >
1
;
}
const
ScriptCallFrame&
AsyncStackTrace::at
(
size_t
index)
const
{
return
m_callStack->
at
(index);
}
size_t
AsyncStackTrace::size
()
const
{
return
m_callStack->
size
();
}
bool
AsyncStackTrace::topCallFrameIsBoundary
()
const
{
return
at
(
0
).
isNative
();
}
void
AsyncStackTrace::willDispatchAsyncCall
(
size_t
maxDepth)
{
ASSERT
(m_state == State::Pending);
m_state = State::Active;
truncate
(maxDepth);
}
void
AsyncStackTrace::didDispatchAsyncCall
()
{
ASSERT
(m_state == State::Active || m_state == State::Canceled);
if
(m_state == State::Active && !m_singleShot) {
m_state = State::Pending;
return
;
}
m_state = State::Dispatched;
if
(!m_childCount)
remove
();
}
void
AsyncStackTrace::didCancelAsyncCall
()
{
if
(m_state == State::Canceled)
return
;
if
(m_state == State::Pending && !m_childCount)
remove
();
m_state = State::Canceled;
}
RefPtr<Protocol::Console::StackTrace>
AsyncStackTrace::buildInspectorObject
()
const
{
RefPtr<Protocol::Console::StackTrace> topStackTrace;
RefPtr<Protocol::Console::StackTrace> previousStackTrace;
for
(
auto
* stackTrace =
this
; stackTrace; stackTrace = stackTrace->
m_parent
.
get
()) {
auto
& callStack = stackTrace->
m_callStack
;
bool
truncated = stackTrace->
m_truncated
;
bool
topCallFrameIsBoundary = stackTrace->
topCallFrameIsBoundary
();
//
Skip async stack traces that only contain the boundary frame.
//
If none contain more than the boundary frame then pretend there are no async stack traces.
if
(topCallFrameIsBoundary && !truncated && stackTrace->
size
() ==
1
)
continue
;
auto
protocolObject =
Protocol::Console::StackTrace::create
()
.
setCallFrames
(callStack->
buildInspectorArray
())
.
release
();
if
(truncated)
protocolObject->
setTruncated
(
true
);
if
(topCallFrameIsBoundary)
protocolObject->
setTopCallFrameIsBoundary
(
true
);
if
(!topStackTrace)
topStackTrace = protocolObject.
ptr
();
if
(previousStackTrace)
previousStackTrace->
setParentStackTrace
(protocolObject.
copyRef
());
previousStackTrace =
WTF::move
(protocolObject);
}
return
topStackTrace;
}
void
AsyncStackTrace::truncate
(
size_t
maxDepth)
{
AsyncStackTrace* lastUnlockedAncestor =
nullptr
;
size_t
depth =
0
;
auto
* newStackTraceRoot =
this
;
while
(newStackTraceRoot) {
depth += newStackTraceRoot->
size
();
if
(depth >= maxDepth)
break
;
auto
* parent = newStackTraceRoot->
m_parent
.
get
();
if
(!lastUnlockedAncestor && parent && parent->
isLocked
())
lastUnlockedAncestor = newStackTraceRoot;
newStackTraceRoot = parent;
}
if
(!newStackTraceRoot || !newStackTraceRoot->
m_parent
)
return
;
if
(!lastUnlockedAncestor) {
//
No locked nodes belong to the trace. The subtree at the new root
//
is moved to a new tree, and marked as truncated if necessary.
newStackTraceRoot->
m_truncated
=
true
;
newStackTraceRoot->
remove
();
return
;
}
//
The new root has a locked descendent. Since truncating a stack trace
//
cannot mutate locked nodes or their ancestors, a new tree is created by
//
cloning the locked portion of the trace (the path from the locked node
//
to the new root). The subtree rooted at the last unlocked ancestor is
//
then appended to the new tree.
auto
* previousNode = lastUnlockedAncestor;
//
The subtree being truncated must be removed from it's parent before
//
updating its parent pointer chain.
RefPtr<AsyncStackTrace> sourceNode = lastUnlockedAncestor->
m_parent
;
lastUnlockedAncestor->
remove
();
while
(sourceNode) {
previousNode->
m_parent
=
AsyncStackTrace::create
(sourceNode->
m_callStack
.
copyRef
(),
true
,
nullptr
);
previousNode->
m_parent
->
m_childCount
=
1
;
previousNode = previousNode->
m_parent
.
get
();
if
(sourceNode.
get
() == newStackTraceRoot)
break
;
sourceNode = sourceNode->
m_parent
;
}
previousNode->
m_truncated
=
true
;
}
void
AsyncStackTrace::remove
()
{
if
(!m_parent)
return
;
ASSERT
(m_parent->
m_childCount
);
m_parent->
m_childCount
--;
m_parent =
nullptr
;
m_callStack->
removeParentStackTrace
();
}
}
//
namespace Inspector
Back
|
FazBrowse Home
|
New Git URL