mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix(cli/rt/performance): check for object props in startOrMeasureOptions before throwing (#7884)
Fixes #7876 Co-authored-by: Ryan Dahl <ry@tinyclouds.org> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
4ff5003eb6
commit
992c2a436e
2 changed files with 34 additions and 16 deletions
|
@ -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.");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue