Skip to content

Commit

Permalink
fix(cli/rt/performance): check for object props in startOrMeasureOpti…
Browse files Browse the repository at this point in the history
…ons before throwing (#7884)

Fixes #7876

Co-authored-by: Ryan Dahl <[email protected]>
Co-authored-by: Bartek Iwańczuk <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2020
1 parent 4ff5003 commit 992c2a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
5 changes: 4 additions & 1 deletion cli/rt/40_performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@
startOrMeasureOptions = {},
endMark,
) {
if (startOrMeasureOptions && typeof startOrMeasureOptions === "object") {
if (
startOrMeasureOptions && typeof startOrMeasureOptions === "object" &&
Object.keys(startOrMeasureOptions).length > 0
) {
if (endMark) {
throw new TypeError("Options cannot be passed with endMark.");
}
Expand Down
45 changes: 30 additions & 15 deletions cli/tests/unit/performance_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,44 @@ unitTest(function performanceMark() {
});

unitTest(function performanceMeasure() {
const mark = performance.mark("test");
const markName1 = "mark1";
const measureName1 = "measure1";
const measureName2 = "measure2";
const mark1 = performance.mark(markName1);
return new Promise((resolve, reject) => {
setTimeout(() => {
try {
const measure = performance.measure("test", "test");
assert(measure instanceof PerformanceMeasure);
assertEquals(measure.detail, null);
assertEquals(measure.name, "test");
assertEquals(measure.entryType, "measure");
assert(measure.startTime > 0);
assertEquals(mark.startTime, measure.startTime);
const measure1 = performance.measure(measureName1, markName1);
const measure2 = performance.measure(
measureName2,
undefined,
markName1,
);
assert(measure1 instanceof PerformanceMeasure);
assertEquals(measure1.detail, null);
assertEquals(measure1.name, measureName1);
assertEquals(measure1.entryType, "measure");
assert(measure1.startTime > 0);
assertEquals(measure2.startTime, 0);
assertEquals(mark1.startTime, measure1.startTime);
assertEquals(mark1.startTime, measure2.duration);
assert(
measure.duration >= 100,
`duration below 100ms: ${measure.duration}`,
measure1.duration >= 100,
`duration below 100ms: ${measure1.duration}`,
);
assert(
measure.duration < 500,
`duration exceeds 500ms: ${measure.duration}`,
measure1.duration < 500,
`duration exceeds 500ms: ${measure1.duration}`,
);
const entries = performance.getEntries();
assert(entries[entries.length - 1] === measure);
const measureEntries = performance.getEntriesByName("test", "measure");
assert(measureEntries[measureEntries.length - 1] === measure);
assert(entries[entries.length - 1] === measure2);
const entriesByName = performance.getEntriesByName(
measureName1,
"measure",
);
assert(entriesByName[entriesByName.length - 1] === measure1);
const measureEntries = performance.getEntriesByType("measure");
assert(measureEntries[measureEntries.length - 1] === measure2);
} catch (e) {
return reject(e);
}
Expand Down

0 comments on commit 992c2a4

Please sign in to comment.