Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/jsc/modules/BunJSCModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ JSC_DEFINE_HOST_FUNCTION(functionGenerateHeapSnapshotForDebugging,
}
scope.releaseAssertNoException();

return JSValue::encode(JSONParse(globalObject, WTF::move(jsonString)));
RELEASE_AND_RETURN(scope, JSValue::encode(JSONParse(globalObject, WTF::move(jsonString))));
}

JSC_DEFINE_HOST_FUNCTION(functionSerialize,
Expand Down
23 changes: 23 additions & 0 deletions test/js/bun/jsc/bun-jsc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,26 @@ it("deserialize applies the same nesting depth limit to arrays as to objects", a
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout, exitCode }).toEqual({ stdout: "rejected\n65\n", exitCode: 0 });
});

it("generateHeapSnapshotForDebugging survives BUN_JSC_validateExceptionChecks", async () => {
// JSONParse (LiteralParser::parseRecursively) can throw, so the enclosing
// throw scope must release before returning. With validateExceptionChecks
// enabled the process aborts when the scope goes unchecked; on release
// builds the option is a no-op and this just exercises the snapshot path.
await using proc = Bun.spawn({
cmd: [
bunExe(),
"-e",
`const snap = require("bun:jsc").generateHeapSnapshotForDebugging(); console.log("ok", typeof snap);`,
],
env: { ...bunEnv, BUN_JSC_validateExceptionChecks: "1" },
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
const uncheckedScopes = stderr
.split("\n")
.map(line => line.trim())
.filter(line => line.startsWith("This scope can throw") || line.startsWith("But the exception was unchecked"));
expect({ stdout, uncheckedScopes, exitCode }).toEqual({ stdout: "ok object\n", uncheckedScopes: [], exitCode: 0 });
});