Expand description
V8 ScriptCoverage JSON parser and UTF-16 source-offset mapper.
This is the open-source layer of fallow’s runtime-coverage pipeline. It
provides the two things the fallow CLI consumes:
- Serde input types for the V8 coverage dump format emitted by
node --experimental-test-coverage,c8, the Inspector protocol, or any V8 isolate (V8CoverageDumpand friends). LineOffsetTable, which converts V8 source offsets into 1-indexed line / 0-indexed columnIstanbulPositions.
§Offset semantics (load-bearing)
V8 reports coverage offsets in UTF-16 code units, not UTF-8 bytes (V8
strings are UTF-16). Verified against real Node: a function preceded by a
😀 (2 UTF-16 units / 4 UTF-8 bytes) on the same line is reported at the
UTF-16 offset, not the byte offset. LineOffsetTable therefore stores
line starts in UTF-16 units. This is the invariant the line_table_* tests
pin, and the one a byte-offset implementation gets wrong.
§Relationship to oxc_coverage_v8
oxc_coverage_v8 (in oxc-coverage-instrument) solves the inverse problem:
it takes an AST-built Istanbul FileCoverage and fills its statement /
function / branch counts by converting Istanbul positions into byte
offsets. The two crates are intentionally not consolidated: opposite
directions, opposite unit spaces, and different producers (real Node V8
dumps here vs. an instrumenter-controlled pipeline there). See
decisions/010-v8-coverage-vs-oxc-coverage-boundary.md.
The closed-source cross-reference, combined scoring, hot-path heuristics and
verdict generation live in fallow-cov (private) and consume the CLI’s
remapped function output via the fallow-cov-protocol envelope.
Structs§
- Coverage
Range - A single coverage range.
count == 0means the range was never hit. - Function
Coverage - V8 per-function coverage. Each function carries one or more
CoverageRanges — block-level for instrumented coverage, function-level for--coverage=best-effort. - Istanbul
Position - 1-indexed line + 0-indexed column.
- Line
Offset Table - Pre-computed line-start table for converting V8 source offsets into Istanbul line/column positions in O(log n) per lookup.
- Script
Coverage - V8’s per-script coverage record. Field names mirror the V8 inspector protocol verbatim.
- V8Coverage
Dump - Top-level shape emitted by Node’s
NODE_V8_COVERAGEdirectory: one file per worker / process containing aresultarray ofScriptCoverage.