From 41a62cbd05e4f071054c649d46279282d498b24b Mon Sep 17 00:00:00 2001 From: Greg Tatum Date: Tue, 28 Nov 2017 12:08:04 -0600 Subject: [PATCH] Handle -1 libIndex values; Resolves #623 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. --- src/components/calltree/ProfileCallTreeContextMenu.js | 2 +- src/profile-logic/symbolication.js | 2 +- src/profile-logic/transforms.js | 2 +- src/test/unit/process-profile.test.js | 2 +- src/types/profile.js | 7 ++++--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/calltree/ProfileCallTreeContextMenu.js b/src/components/calltree/ProfileCallTreeContextMenu.js index fdbc690330..26caf81489 100644 --- a/src/components/calltree/ProfileCallTreeContextMenu.js +++ b/src/components/calltree/ProfileCallTreeContextMenu.js @@ -217,7 +217,7 @@ class ProfileCallTreeContextMenu extends PureComponent { 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; diff --git a/src/profile-logic/symbolication.js b/src/profile-logic/symbolication.js index 3719d9cf7f..778dce256d 100644 --- a/src/profile-logic/symbolication.js +++ b/src/profile-logic/symbolication.js @@ -106,7 +106,7 @@ function gatherFuncsInThread(thread: Thread): Map { } 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]; diff --git a/src/profile-logic/transforms.js b/src/profile-logic/transforms.js index 4ed075d41f..249723283c 100644 --- a/src/profile-logic/transforms.js +++ b/src/profile-logic/transforms.js @@ -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'); diff --git a/src/test/unit/process-profile.test.js b/src/test/unit/process-profile.test.js index 8efa5e161f..5ff0657f77 100644 --- a/src/test/unit/process-profile.test.js +++ b/src/test/unit/process-profile.test.js @@ -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]; diff --git a/src/types/profile.js b/src/types/profile.js index 69e8f44fe2..720f961284 100644 --- a/src/types/profile.js +++ b/src/types/profile.js @@ -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, + // 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, name: Array, host: Array, type: resourceTypeEnum[],