mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 22:01:47 +00:00
This refactor replaces the complex 12-field ResolvedSource struct with a simpler, focused ModuleResult tagged union as outlined in the refactoring plan. **Changes:** Deleted files: - src/bun.js/bindings/ZigSourceProvider.cpp/h (replaced with BunSourceProvider) - src/bun.js/bindings/ResolvedSource.zig (replaced with ModuleResult) New files: - src/bun.js/bindings/TranspiledSource.zig - Thread-safe POD struct for transpiled code - src/bun.js/bindings/SpecialModule.zig - JSValue-based exports handling - src/bun.js/bindings/ModuleResult.zig - Tagged union return type - src/bun.js/bindings/BunSourceProvider.h/cpp - Simplified SourceProvider Updated files: - src/bun.js/jsc.zig - Export new types (ModuleResult, TranspiledSource, etc.) - src/bun.js/ModuleLoader.zig - Use ModuleResult throughout, update AsyncModule - src/bun.js/VirtualMachine.zig - Add ModuleResult import, update fetchWithoutOnLoadPlugins - src/bun.js/bindings/ModuleLoader.cpp - Handle ModuleResult tags in C++ - src/bun.js/bindings/JSCommonJSModule.cpp/h - Use TranspiledSource - src/bun.js/bindings/ZigGlobalObject.cpp - Update includes - src/bun.js/bindings/headers-handwritten.h - Add C++ struct definitions for ModuleResult - build.zig - Remove ResolvedSourceTag from generated modules **Benefits:** - Reduces code complexity by >50% - Eliminates triple string storage - Makes transpilation thread-safe (no JSValue in TranspiledSource) - Clear type safety with tagged unions - Simpler SourceProvider without m_resolvedSource member 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#include "root.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.begin(), basicBlocks.size(), functionStartOffset, ignoreSourceMap);
|
|
return true;
|
|
}
|