Skip to content

Commit 465c2be

Browse files
committed
fix[devtools]: feature-check structure stack trace methods
1 parent 378973b commit 465c2be

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

packages/react-devtools-shared/src/backend/utils/parseStackTrace.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,41 +154,63 @@ function collectStackTrace(
154154
// We mirror how V8 serializes stack frames and how we later parse them.
155155
for (let i = framesToSkip; i < structuredStackTrace.length; i++) {
156156
const callSite = structuredStackTrace[i];
157-
let name = callSite.getFunctionName() || '<anonymous>';
157+
let name =
158+
typeof callSite.getFunctionName === 'function'
159+
? callSite.getFunctionName() || '<anonymous>'
160+
: '';
158161
if (
159162
name.includes('react_stack_bottom_frame') ||
160163
name.includes('react-stack-bottom-frame')
161164
) {
162165
// Skip everything after the bottom frame since it'll be internals.
163166
break;
164-
} else if (callSite.isNative()) {
167+
} else if (typeof callSite.isNative === 'function' && callSite.isNative()) {
165168
// $FlowFixMe[prop-missing]
166-
const isAsync = callSite.isAsync();
169+
const isAsync =
170+
typeof callSite.isAsync === 'function' && callSite.isAsync();
167171
result.push([name, '', 0, 0, 0, 0, isAsync]);
168172
} else {
169173
// We encode complex function calls as if they're part of the function
170174
// name since we cannot simulate the complex ones and they look the same
171175
// as function names in UIs on the client as well as stacks.
172-
if (callSite.isConstructor()) {
176+
if (
177+
typeof callSite.isConstructor === 'function' &&
178+
callSite.isConstructor()
179+
) {
173180
name = 'new ' + name;
174-
} else if (!callSite.isToplevel()) {
181+
} else if (
182+
typeof callSite.isToplevel === 'function' &&
183+
!callSite.isToplevel()
184+
) {
175185
name = getMethodCallName(callSite);
176186
}
177187
if (name === '<anonymous>') {
178188
name = '';
179189
}
180-
let filename = callSite.getScriptNameOrSourceURL() || '<anonymous>';
190+
let filename =
191+
typeof callSite.getScriptNameOrSourceURL === 'function'
192+
? callSite.getScriptNameOrSourceURL() || '<anonymous>'
193+
: '';
181194
if (filename === '<anonymous>') {
182195
filename = '';
183-
if (callSite.isEval()) {
184-
const origin = callSite.getEvalOrigin();
196+
if (typeof callSite.isEval === 'function' && callSite.isEval()) {
197+
const origin =
198+
typeof callSite.getEvalOrigin === 'function'
199+
? callSite.getEvalOrigin()
200+
: null;
185201
if (origin) {
186202
filename = origin.toString() + ', <anonymous>';
187203
}
188204
}
189205
}
190-
const line = callSite.getLineNumber() || 0;
191-
const col = callSite.getColumnNumber() || 0;
206+
const line =
207+
(typeof callSite.getLineNumber === 'function' &&
208+
callSite.getLineNumber()) ||
209+
0;
210+
const col =
211+
(typeof callSite.getColumnNumber === 'function' &&
212+
callSite.getColumnNumber()) ||
213+
0;
192214
const enclosingLine: number =
193215
// $FlowFixMe[prop-missing]
194216
typeof callSite.getEnclosingLineNumber === 'function'
@@ -200,7 +222,8 @@ function collectStackTrace(
200222
? (callSite: any).getEnclosingColumnNumber() || 0
201223
: 0;
202224
// $FlowFixMe[prop-missing]
203-
const isAsync = callSite.isAsync();
225+
const isAsync =
226+
typeof callSite.isAsync === 'function' && callSite.isAsync();
204227
result.push([
205228
name,
206229
filename,

0 commit comments

Comments
 (0)