Skip to main content

Crate fallow_v8_coverage

Crate fallow_v8_coverage 

Source
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:

  1. Serde input types for the V8 coverage dump format emitted by node --experimental-test-coverage, c8, the Inspector protocol, or any V8 isolate (V8CoverageDump and friends).
  2. LineOffsetTable, which converts V8 source offsets into 1-indexed line / 0-indexed column IstanbulPositions.

§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§

CoverageRange
A single coverage range. count == 0 means the range was never hit.
FunctionCoverage
V8 per-function coverage. Each function carries one or more CoverageRanges — block-level for instrumented coverage, function-level for --coverage=best-effort.
IstanbulPosition
1-indexed line + 0-indexed column.
LineOffsetTable
Pre-computed line-start table for converting V8 source offsets into Istanbul line/column positions in O(log n) per lookup.
ScriptCoverage
V8’s per-script coverage record. Field names mirror the V8 inspector protocol verbatim.
V8CoverageDump
Top-level shape emitted by Node’s NODE_V8_COVERAGE directory: one file per worker / process containing a result array of ScriptCoverage.