Bug 1238639 - HeapAnalysesWorker getCreationTime throws when given non-existant path;r=fitzgen
--- a/devtools/shared/heapsnapshot/HeapAnalysesWorker.js
+++ b/devtools/shared/heapsnapshot/HeapAnalysesWorker.js
@@ -86,18 +86,20 @@ workerHelper.createTask(self, "takeCensu
return delta;
});
/**
* @see HeapAnalysesClient.prototype.getCreationTime
*/
workerHelper.createTask(self, "getCreationTime", snapshotFilePath => {
- let snapshot = snapshots[snapshotFilePath];
- return snapshot ? snapshot.creationTime : null;
+ if (!snapshots[snapshotFilePath]) {
+ throw new Error(`No known heap snapshot for '${snapshotFilePath}'`);
+ }
+ return snapshots[snapshotFilePath].creationTime;
});
/**
* The set of `DominatorTree`s that have been computed, mapped by their id (aka
* the index into this array).
*
* @see /dom/webidl/DominatorTree.webidl
*/
--- a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCreationTime_01.js
+++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_getCreationTime_01.js
@@ -27,21 +27,26 @@ add_task(function* () {
waitForTenMilliseconds();
const snapshotFilePath = saveNewHeapSnapshot();
waitForTenMilliseconds();
const end = Date.now() * 1000;
yield client.readHeapSnapshot(snapshotFilePath);
ok(true, "Should have read the heap snapshot");
- let time = yield client.getCreationTime("/not/a/real/path", {
- breakdown: BREAKDOWN
- });
- equal(time, null, "getCreationTime returns `null` when snapshot does not exist");
+ let threw = false;
+ try {
+ yield client.getCreationTime("/not/a/real/path", {
+ breakdown: BREAKDOWN
+ });
+ } catch (_) {
+ threw = true;
+ }
+ ok(threw, "getCreationTime should throw when snapshot does not exist");
- time = yield client.getCreationTime(snapshotFilePath, {
+ let time = yield client.getCreationTime(snapshotFilePath, {
breakdown: BREAKDOWN
});
ok(time >= start, "creation time occurred after start");
ok(time <= end, "creation time occurred before end");
client.destroy();
});