mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
- Add m_hasPendingNapiException flag to track NAPI exception state - Modify napi_throw and throwErrorWithCStrings to check for pending exceptions - Ignore subsequent throws when exception is already pending - Update NAPI preamble to check for pending exceptions - This prevents crashes from multiple ThrowAsJavaScriptException calls 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import { test, expect } from "bun:test";
|
|
import { join } from "path";
|
|
|
|
// This test reproduces the bug where multiple ThrowAsJavaScriptException calls
|
|
// in the same NAPI function cause Bun to crash with an assertion failure
|
|
|
|
const addonPath = join(import.meta.dir, "napi-app", "build", "Debug", "multiple_exceptions_addon.node");
|
|
|
|
// Build the addon first if needed
|
|
import { spawnSync } from "child_process";
|
|
const buildResult = spawnSync("node-gyp", ["build"], {
|
|
cwd: join(import.meta.dir, "napi-app"),
|
|
stdio: "inherit"
|
|
});
|
|
|
|
let addon;
|
|
try {
|
|
addon = require(addonPath);
|
|
} catch (error) {
|
|
console.warn("Could not load multiple_exceptions_addon.node - skipping tests");
|
|
console.warn("Run 'cd test/napi/napi-app && node-gyp build' to build the addon");
|
|
addon = null;
|
|
}
|
|
|
|
test.skipIf(!addon)("throwing after catching exception should not crash Bun", () => {
|
|
expect(() => {
|
|
addon.throwAfterCatch();
|
|
}).toThrow("Second exception after catch");
|
|
});
|
|
|
|
test.skipIf(!addon)("multiple exceptions should not crash - second overwrites first", () => {
|
|
expect(() => {
|
|
addon.throwMultiple();
|
|
}).toThrow("Second exception");
|
|
});
|
|
|
|
test.skipIf(!addon)("exception pending check should work", () => {
|
|
expect(() => {
|
|
const result = addon.checkExceptionPending();
|
|
// This should throw before returning the result
|
|
}).toThrow("Test exception");
|
|
}); |