Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/jsc/bindings/FormatStackTraceForJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,11 @@ JSC_DEFINE_HOST_FUNCTION(errorConstructorFuncAppendStackTrace, (JSC::JSGlobalObj
return {};
}

if (!destination->stackTrace()) {
if (!destination->stackTrace() && !destination->hasMaterializedErrorInfo()) {
destination->captureStackTrace(vm, globalObject, 1);
}

if (source->stackTrace()) {
if (source->stackTrace() && destination->stackTrace() && source != destination) {
destination->stackTrace()->appendVector(*source->stackTrace());
source->stackTrace()->clear();
}
Expand Down
28 changes: 27 additions & 1 deletion test/js/bun/util/error-gc-test.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "bun:test";
import { readFileSync } from "fs";
import { tmpdirSync } from "harness";
import { bunEnv, bunExe, tmpdirSync } from "harness";
import { join } from "path";
// This test checks that printing stack traces increments and decrements
// reference-counted strings
Expand Down Expand Up @@ -45,6 +45,32 @@ test("error gc test #3", () => {
}
});

test("Error.appendStackTrace after materialized error info doesn't crash in GC", async () => {
const src = `
let keep = [];
for (let i = 0; i < 200; i++) {
eval(\`(function inner\${i}() {
const a = new Error();
const b = new Error();
a.sourceURL;
b.sourceURL;
Error.appendStackTrace(a, b);
keep.push(b);
})();\`);
}
Bun.gc(true);
Bun.gc(true);
process.stdout.write("ok");
`;
await using proc = Bun.spawn({
cmd: [bunExe(), "-e", src],
env: bunEnv,
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout, exitCode }).toEqual({ stdout: "ok", exitCode: 0 });
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
});

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
// This test fails if:
// - it crashes
// - The test failure message gets a non-sensical error
Expand Down
Loading