diff --git a/cli/rt/40_performance.js b/cli/rt/40_performance.js index b921ca43a48e6f..573fc8051fb881 100644 --- a/cli/rt/40_performance.js +++ b/cli/rt/40_performance.js @@ -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."); } diff --git a/cli/tests/unit/performance_test.ts b/cli/tests/unit/performance_test.ts index 2a25887dbb7a2b..1df46b1b23794b 100644 --- a/cli/tests/unit/performance_test.ts +++ b/cli/tests/unit/performance_test.ts @@ -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); }