aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/CodeCoverage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/bindings/CodeCoverage.cpp')
-rw-r--r--src/bun.js/bindings/CodeCoverage.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/bun.js/bindings/CodeCoverage.cpp b/src/bun.js/bindings/CodeCoverage.cpp
new file mode 100644
index 000000000..1cb3b6ba2
--- /dev/null
+++ b/src/bun.js/bindings/CodeCoverage.cpp
@@ -0,0 +1,44 @@
+#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;
+}