Skip to content

Commit b9b20ea

Browse files
szuenddevtools-frontend-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[stack_trace]: Augment RawFrames with script IDs
This CL duplicates the existing behavior where we try to match parsed URLs/line/column numbers to a script ID we received via Runtime.getExceptionDetails. This is not 100% bulletproof as URLs are not unique inside a V8 instance, but this has worked well enough in practice that we'll keep it. R=pfaffe@chromium.org Bug: 485142682 Change-Id: Ia0afb5174404594d37b49c90530dad9e279d0ea1 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7754109 Commit-Queue: Simon Zünd <szuend@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
1 parent bea0a33 commit b9b20ea

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

front_end/models/stack_trace/DetailedErrorStackParser.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import type * as Protocol from '../../generated/protocol.js';
6+
57
// eslint-disable-next-line @devtools/es-modules-import
68
import * as StackTraceImpl from './stack_trace_impl.js';
79

@@ -191,4 +193,40 @@ describe('DetailedErrorStackParser', () => {
191193
assert.strictEqual(frames[0].functionName, 'Promise.all');
192194
});
193195
});
196+
197+
describe('augmentRawFramesWithScriptIds', () => {
198+
it('augments raw frames with script IDs from Protocol.Runtime.StackTrace', () => {
199+
const frames: StackTraceImpl.Trie.RawFrame[] = [
200+
{
201+
url: 'http://www.example.org/script.js',
202+
functionName: 'foo',
203+
lineNumber: 9,
204+
columnNumber: 4,
205+
},
206+
{
207+
url: 'http://www.example.org/other.js',
208+
functionName: 'bar',
209+
lineNumber: 19,
210+
columnNumber: 0,
211+
},
212+
];
213+
214+
const protocolStackTrace: Protocol.Runtime.StackTrace = {
215+
callFrames: [
216+
{
217+
functionName: 'foo',
218+
scriptId: '123' as Protocol.Runtime.ScriptId,
219+
url: 'http://www.example.org/script.js',
220+
lineNumber: 9,
221+
columnNumber: 4,
222+
},
223+
],
224+
};
225+
226+
StackTraceImpl.DetailedErrorStackParser.augmentRawFramesWithScriptIds(frames, protocolStackTrace);
227+
228+
assert.strictEqual(frames[0].scriptId, '123');
229+
assert.isUndefined(frames[1].scriptId);
230+
});
231+
});
194232
});

front_end/models/stack_trace/DetailedErrorStackParser.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import * as Common from '../../core/common/common.js';
66
import type * as Platform from '../../core/platform/platform.js';
7+
import type * as Protocol from '../../generated/protocol.js';
78

89
import type {RawFrame} from './Trie.js';
910

@@ -140,3 +141,21 @@ export function parseRawFramesFromErrorStack(stack: string): RawFrame[] {
140141
}
141142
return rawFrames;
142143
}
144+
145+
/**
146+
* Error#stack output only contains script URLs. In some cases we are able to
147+
* retrieve additional exception details from V8 that we can use to augment
148+
* the parsed Error#stack with script IDs.
149+
*/
150+
export function augmentRawFramesWithScriptIds(
151+
rawFrames: RawFrame[], protocolStackTrace: Protocol.Runtime.StackTrace): void {
152+
for (const rawFrame of rawFrames) {
153+
const protocolFrame = protocolStackTrace.callFrames.find(
154+
frame => rawFrame.url === frame.url && rawFrame.lineNumber === frame.lineNumber &&
155+
rawFrame.columnNumber === frame.columnNumber);
156+
if (protocolFrame) {
157+
// @ts-expect-error scriptId is a readonly property.
158+
rawFrame.scriptId = protocolFrame.scriptId;
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)