Skip to content

Commit

Permalink
Fix lifetime issue in BunString (#16930)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Jan 31, 2025
1 parent 3a4df79 commit b59b793
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/bun.js/bindings/BunString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,23 @@ extern "C" JSC::EncodedJSValue BunString__createArray(

extern "C" void BunString__toWTFString(BunString* bunString)
{
WTF::String str;
if (bunString->tag == BunStringTag::ZigString) {
if (Zig::isTaggedExternalPtr(bunString->impl.zig.ptr)) {
bunString->impl.wtf = Zig::toString(bunString->impl.zig).impl();
str = Zig::toString(bunString->impl.zig);
} else {
bunString->impl.wtf = Zig::toStringCopy(bunString->impl.zig).impl();
str = Zig::toStringCopy(bunString->impl.zig);
}

bunString->tag = BunStringTag::WTFStringImpl;
} else if (bunString->tag == BunStringTag::StaticZigString) {
bunString->impl.wtf = Zig::toStringStatic(bunString->impl.zig).impl();
bunString->tag = BunStringTag::WTFStringImpl;
str = Zig::toStringStatic(bunString->impl.zig);
} else {
return;
}

auto impl = str.releaseImpl();
bunString->impl.wtf = impl.leakRef();
bunString->tag = BunStringTag::WTFStringImpl;
}

extern "C" BunString URL__getFileURLString(BunString* filePath)
Expand Down

0 comments on commit b59b793

Please sign in to comment.