mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 12:29:07 +00:00
* WIP code coverage initial commit * almost works * one approach * Code Coverage * Update WebKit * it works but is not yet accurate * skip double ascii check * wrapper * it works but i'm not sure what to do about blocks * hide blocks for now * Update ZigSourceProvider.cpp * Create coverage.md * Update nav.ts --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
45 lines
1.5 KiB
C++
45 lines
1.5 KiB
C++
#include "root.h"
|
|
#include "ZigSourceProvider.h"
|
|
#include <JavaScriptCore/ControlFlowProfiler.h>
|
|
|
|
using namespace JSC;
|
|
|
|
extern "C" bool CodeCoverage__withBlocksAndFunctions(
|
|
JSC::VM* vmPtr,
|
|
JSC::SourceID sourceID,
|
|
void* ctx,
|
|
bool ignoreSourceMap,
|
|
void (*blockCallback)(void* ctx, JSC::BasicBlockRange* range, size_t len, size_t functionOffset, bool ignoreSourceMap))
|
|
{
|
|
|
|
VM& vm = *vmPtr;
|
|
|
|
auto basicBlocks = vm.controlFlowProfiler()->getBasicBlocksForSourceIDWithoutFunctionRange(
|
|
sourceID, vm);
|
|
|
|
if (basicBlocks.isEmpty()) {
|
|
blockCallback(ctx, nullptr, 0, 0, ignoreSourceMap);
|
|
return true;
|
|
}
|
|
|
|
size_t functionStartOffset = basicBlocks.size();
|
|
|
|
const Vector<std::tuple<bool, unsigned, unsigned>>& functionRanges = vm.functionHasExecutedCache()->getFunctionRanges(sourceID);
|
|
|
|
basicBlocks.reserveCapacity(functionRanges.size() + basicBlocks.size());
|
|
|
|
for (const auto& functionRange : functionRanges) {
|
|
BasicBlockRange range;
|
|
range.m_hasExecuted = std::get<0>(functionRange);
|
|
range.m_startOffset = static_cast<int>(std::get<1>(functionRange));
|
|
range.m_endOffset = static_cast<int>(std::get<2>(functionRange));
|
|
range.m_executionCount = range.m_hasExecuted
|
|
? 1
|
|
: 0; // This is a hack. We don't actually count this.
|
|
basicBlocks.append(range);
|
|
}
|
|
|
|
blockCallback(ctx, basicBlocks.data(), basicBlocks.size(), functionStartOffset, ignoreSourceMap);
|
|
return true;
|
|
}
|