mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
* Test for #8687 * Fix reference counting of Bun.file(0) etc. (#8687) Fixes #8687.
This commit is contained in:
@@ -1553,20 +1553,19 @@ pub const Blob = struct {
|
||||
break :brk copy;
|
||||
},
|
||||
.fd => {
|
||||
switch (bun.FDTag.get(path_or_fd.fd)) {
|
||||
.stdin => return Blob.initWithStore(
|
||||
vm.rareData().stdin(),
|
||||
const optional_store: ?*Store = switch (bun.FDTag.get(path_or_fd.fd)) {
|
||||
.stdin => vm.rareData().stdin(),
|
||||
.stderr => vm.rareData().stderr(),
|
||||
.stdout => vm.rareData().stdout(),
|
||||
else => null,
|
||||
};
|
||||
|
||||
if (optional_store) |store| {
|
||||
store.ref();
|
||||
return Blob.initWithStore(
|
||||
store,
|
||||
globalThis,
|
||||
),
|
||||
.stderr => return Blob.initWithStore(
|
||||
vm.rareData().stderr(),
|
||||
globalThis,
|
||||
),
|
||||
.stdout => return Blob.initWithStore(
|
||||
vm.rareData().stdout(),
|
||||
globalThis,
|
||||
),
|
||||
else => {},
|
||||
);
|
||||
}
|
||||
break :brk path_or_fd.*;
|
||||
},
|
||||
|
||||
@@ -310,6 +310,14 @@ it("Bun.write(Bun.stderr, 'new TextEncoder().encode(Bun.write STDERR TEST'))", a
|
||||
expect(await Bun.write(Bun.stderr, new TextEncoder().encode("\nBun.write STDERR TEST\n\n"))).toBe(24);
|
||||
});
|
||||
|
||||
it("Bun.file(0) survives GC", async () => {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
let f = Bun.file(0);
|
||||
await gcTick();
|
||||
expect(Bun.inspect(f)).toContain("FileRef (fd: 0)");
|
||||
}
|
||||
});
|
||||
|
||||
// FLAKY TEST
|
||||
// Since Bun.file is resolved lazily, this needs to specifically be checked
|
||||
it("Bun.write('output.html', HTMLRewriter.transform(Bun.file)))", async done => {
|
||||
|
||||
Reference in New Issue
Block a user