accept more performance mark name and return dummy 0

This commit is contained in:
Pierre Tachoire
2026-02-24 09:12:18 +01:00
parent 700a3e6ed9
commit 71707b5aa7
2 changed files with 56 additions and 4 deletions

View File

@@ -252,6 +252,28 @@
} }
</script> </script>
<script id=measure_with_navigation_timing_marks>
{
// performance.measure() must accept PerformanceTiming attribute names
// (e.g. "fetchStart") as start/end marks per the W3C User Timing Level 2 spec.
// https://www.w3.org/TR/user-timing/#dom-performance-measure
performance.clearMarks();
performance.clearMeasures();
performance.mark("mark-dataComplete");
let m = performance.measure("dataComplete", "fetchStart", "mark-dataComplete");
testing.expectEqual('dataComplete', m.name);
testing.expectEqual('measure', m.entryType);
testing.expectEqual(true, m.duration >= 0);
// navigationStart is also a valid mark name (was already supported)
performance.mark("mark-end");
let m2 = performance.measure("fromNav", "navigationStart", "mark-end");
testing.expectEqual('fromNav', m2.name);
testing.expectEqual(true, m2.duration >= 0);
}
</script>
<script id=mixed_marks_and_measures> <script id=mixed_marks_and_measures>
{ {
performance.clearMarks(); performance.clearMarks();

View File

@@ -208,11 +208,41 @@ fn getMarkTime(self: *const Performance, mark_name: []const u8) !f64 {
} }
} }
// Recognized mark names by browsers. `navigationStart` is an equivalent // PerformanceTiming attribute names are valid start/end marks per the
// to 0. Others are dependant to request arrival, end of request etc. // W3C User Timing Level 2 spec. All are relative to navigationStart (= 0).
if (std.mem.eql(u8, "navigationStart", mark_name)) { // https://www.w3.org/TR/user-timing/#dom-performance-measure
//
// `navigationStart` is an equivalent to 0.
// Others are dependant to request arrival, end of request etc, but we
// return a dummy 0 value for now.
const navigation_timing_marks = [_][]const u8{
"navigationStart",
"unloadEventStart",
"unloadEventEnd",
"redirectStart",
"redirectEnd",
"fetchStart",
"domainLookupStart",
"domainLookupEnd",
"connectStart",
"connectEnd",
"secureConnectionStart",
"requestStart",
"responseStart",
"responseEnd",
"domLoading",
"domInteractive",
"domContentLoadedEventStart",
"domContentLoadedEventEnd",
"domComplete",
"loadEventStart",
"loadEventEnd",
};
for (navigation_timing_marks) |name| {
if (std.mem.eql(u8, name, mark_name)) {
return 0; return 0;
} }
}
return error.SyntaxError; // Mark not found return error.SyntaxError; // Mark not found
} }