| 57 | typeof (element as IStackFrameElement).uiLocation === 'function'; |
| 58 | |
| 59 | export class StackTrace { |
| 60 | public readonly frames: FrameElement[] = []; |
| 61 | private _frameById: Map<number, StackFrame | InlinedFrame> = new Map(); |
| 62 | /** |
| 63 | * Frame index that was last checked for inline expansion. |
| 64 | * @see https://github.com/ChromeDevTools/devtools-frontend/blob/c9f204731633fd2e2b6999a2543e99b7cc489b4b/docs/language_extension_api.md#dealing-with-inlined-functions |
| 65 | */ |
| 66 | private _lastInlineWasmExpanded = Promise.resolve(0); |
| 67 | private _asyncStackTraceId?: Cdp.Runtime.StackTraceId; |
| 68 | private _lastFrameThread?: Thread; |
| 69 | |
| 70 | public static fromRuntime(thread: Thread, stack: Cdp.Runtime.StackTrace): StackTrace { |
| 71 | const result = new StackTrace(thread); |
| 72 | for (const frame of stack.callFrames) { |
| 73 | if (!frame.url.endsWith(SourceConstants.InternalExtension)) { |
| 74 | result.frames.push(StackFrame.fromRuntime(thread, frame, false)); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if (stack.parentId) { |
| 79 | result._asyncStackTraceId = stack.parentId; |
| 80 | console.assert(!stack.parent); |
| 81 | } else { |
| 82 | result._appendStackTrace(thread, stack.parent); |
| 83 | } |
| 84 | |
| 85 | return result; |
| 86 | } |
| 87 | |
| 88 | public static fromDebugger( |
| 89 | thread: Thread, |
| 90 | frames: Cdp.Debugger.CallFrame[], |
| 91 | parent?: Cdp.Runtime.StackTrace, |
| 92 | parentId?: Cdp.Runtime.StackTraceId, |
| 93 | ): StackTrace { |
| 94 | const result = new StackTrace(thread); |
| 95 | for (const callFrame of frames) { |
| 96 | result._appendFrame(StackFrame.fromDebugger(thread, callFrame)); |
| 97 | } |
| 98 | if (parentId) { |
| 99 | result._asyncStackTraceId = parentId; |
| 100 | console.assert(!parent); |
| 101 | } else { |
| 102 | result._appendStackTrace(thread, parent); |
| 103 | } |
| 104 | return result; |
| 105 | } |
| 106 | |
| 107 | constructor(private readonly thread: Thread) { |
| 108 | this._lastFrameThread = thread; |
| 109 | } |
| 110 | |
| 111 | public async loadFrames(limit: number, noFuncEval?: boolean): Promise<FrameElement[]> { |
| 112 | await this.expandAsyncStack(limit, noFuncEval); |
| 113 | await this.expandWasmFrames(); |
| 114 | return this.frames; |
| 115 | } |
| 116 | |