Skip to content

Commit

Permalink
Handle -1 libIndex values; Resolves firefox-devtools#623
Browse files Browse the repository at this point in the history
The libIndex for profile.thread.resourceTable.lib is incosistent in its historical
use. This is a quick patch to ensure we don't have runtime errors.
  • Loading branch information
gregtatum committed Nov 30, 2017
1 parent f828d20 commit 41a62cb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/calltree/ProfileCallTreeContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class ProfileCallTreeContextMenu extends PureComponent<Props> {
return null;
}
const libIndex = resourceTable.lib[resourceIndex];
if (libIndex === undefined || libIndex === null) {
if (libIndex === undefined || libIndex === null || libIndex === -1) {
return null;
}
return libs[libIndex].name;
Expand Down
2 changes: 1 addition & 1 deletion src/profile-logic/symbolication.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function gatherFuncsInThread(thread: Thread): Map<Lib, IndexIntoFuncTable[]> {
}

const libIndex = resourceTable.lib[resourceIndex];
if (libIndex === null || libIndex === undefined) {
if (libIndex === null || libIndex === undefined || libIndex === -1) {
throw new Error('libIndex must be a valid index.');
}
const lib = libs[libIndex];
Expand Down
2 changes: 1 addition & 1 deletion src/profile-logic/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export function getTransformLabels(
if (transform.type === 'collapse-resource') {
const libIndex = resourceTable.lib[transform.resourceIndex];
let resourceName;
if (libIndex === undefined || libIndex === null) {
if (libIndex === undefined || libIndex === null || libIndex === -1) {
const nameIndex = resourceTable.name[transform.resourceIndex];
if (nameIndex === -1) {
throw new Error('Attempting to collapse a resource without a name');
Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/process-profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('extract functions and resource from location strings', function() {
resourceType = resourceTable.type[resourceIndex];
}
const lib =
libIndex === undefined || libIndex === null
libIndex === undefined || libIndex === null || libIndex === -1
? undefined
: libs[libIndex];

Expand Down
7 changes: 4 additions & 3 deletions src/types/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ export type FuncTable = {
*/
export type ResourceTable = {
length: number,
// lib SHOULD be void in this case, but some profiles in the store seem to have
// null here. We should probably investigate and provide an upgrader.
lib: Array<IndexIntoLibs | void | null>,
// lib SHOULD be void in this case, but some profiles in the store have null or -1
// here. We should investigate and provide an upgrader.
// See https://github.com/devtools-html/perf.html/issues/652
lib: Array<IndexIntoLibs | void | null | -1>,
name: Array<IndexIntoStringTable | -1>,
host: Array<IndexIntoStringTable | void>,
type: resourceTypeEnum[],
Expand Down

0 comments on commit 41a62cb

Please sign in to comment.