mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
Introduce a small set of counters on Document that track the work done while processing :has() invalidation: how often the upward walk runs, how many elements it visits, how often matches_has_pseudo_class() is invoked, how well the per-pass result cache performs, and how many elements transition from clean to needs-style-update. Expose the counters through internals so tests can assert precise bounds on the invalidation work triggered by a mutation, which regular reference tests cannot express. Add a css-has-invalidation test suite that covers subject-position, non-subject-position, sibling-combinator, and no-:has() cases. The baseline tests share a helper script so later coverage can reuse the same counter-printing path. The counters are test-only observation; they do not affect style computation itself.
30 lines
1.5 KiB
JavaScript
30 lines
1.5 KiB
JavaScript
// Shared helpers for :has() invalidation tests.
|
|
// Each test includes include.js first, then this file.
|
|
|
|
function printCounters(label) {
|
|
const c = internals.getStyleInvalidationCounters();
|
|
println(`[${label}]`);
|
|
println(` hasAncestorWalkInvocations: ${c.hasAncestorWalkInvocations}`);
|
|
println(` hasAncestorWalkVisits: ${c.hasAncestorWalkVisits}`);
|
|
println(` hasMatchInvocations: ${c.hasMatchInvocations}`);
|
|
println(` hasResultCacheHits: ${c.hasResultCacheHits}`);
|
|
println(` hasResultCacheMisses: ${c.hasResultCacheMisses}`);
|
|
println(` styleInvalidations: ${c.styleInvalidations}`);
|
|
}
|
|
|
|
// Force a style pass and reset counters so a subsequent mutation can be
|
|
// measured in isolation. Forces the rule cache and style invalidation data
|
|
// to be built by mutating + reading style, so the per-feature has-selector
|
|
// metadata is populated before counters are observed.
|
|
function settleAndReset(triggerElement) {
|
|
// Two passes: the first ensures the rule cache + style invalidation data
|
|
// is built; the second ensures any deferred work from a probe-only mutation
|
|
// has settled. Without this, the very first mutation in a test can look
|
|
// like a hit on the conservative "data not yet built" fallback.
|
|
document.documentElement.classList.add("__settle__");
|
|
getComputedStyle(triggerElement || document.documentElement).color;
|
|
document.documentElement.classList.remove("__settle__");
|
|
getComputedStyle(triggerElement || document.documentElement).color;
|
|
internals.resetStyleInvalidationCounters();
|
|
}
|