Compare commits

...

1 Commits

Author SHA1 Message Date
Jarred Sumner
f94a8097ac Add cleanup function to ResolvedSource 2025-01-18 12:04:46 -08:00
4 changed files with 25 additions and 3 deletions

View File

@@ -710,3 +710,21 @@ extern "C" void JSC__JSValue__putBunString(
Identifier id = Identifier::fromString(vm, str);
target->putDirect(vm, id, value, 0);
}
void ResolvedSource::cleanup()
{
if (source_url.tag == BunStringTag::WTFStringImpl) {
source_url.impl.wtf->deref();
source_url.tag = BunStringTag::Dead;
}
if (specifier.tag == BunStringTag::WTFStringImpl) {
specifier.impl.wtf->deref();
specifier.tag = BunStringTag::Dead;
}
if (source_code.tag == BunStringTag::WTFStringImpl && needsDeref) {
source_code.impl.wtf->deref();
source_code.tag = BunStringTag::Dead;
needsDeref = false;
}
}

View File

@@ -51,9 +51,8 @@ public:
~ResolvedSourceCodeHolder()
{
if (res->success && res->result.value.source_code.tag == BunStringTag::WTFStringImpl && res->result.value.needsDeref) {
res->result.value.needsDeref = false;
res->result.value.source_code.impl.wtf->deref();
if (res->success) {
res->result.value.cleanup();
}
}

View File

@@ -137,6 +137,9 @@ Ref<SourceProvider> SourceProvider::create(
Bun__addSourceProviderSourceMap(globalObject->bunVM(), provider.ptr(), &resolvedSource.source_url);
}
resolvedSource.source_url = BunStringEmpty;
resolvedSource.source_code = BunStringEmpty;
return provider;
}

View File

@@ -107,6 +107,8 @@ typedef struct ResolvedSource {
bool already_bundled;
uint8_t* bytecode_cache;
size_t bytecode_cache_size;
void cleanup();
} ResolvedSource;
static const uint32_t ResolvedSourceTagPackageJSONTypeModule = 1;
typedef union ErrorableResolvedSourceResult {