Files
bun.sh/test/napi/simple-c-test.js
Claude Bot 6bcfa2fd1e Fix NAPI multiple exception handling to match Node.js behavior
- 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>
2025-08-11 13:52:45 +00:00

22 lines
659 B
JavaScript

import { test, expect } from "bun:test";
import { join } from "path";
const addonPath = join(import.meta.dir, "napi-app", "build", "Debug", "simple_test_addon.node");
let addon;
try {
addon = require(addonPath);
console.log("Simple C addon loaded successfully");
} catch (error) {
console.warn("Could not load addon:", error.message);
addon = null;
}
// Test the simple C function that throws two exceptions
test.skipIf(!addon)("C API double throw test", () => {
console.log("About to call testDoubleThrow...");
expect(() => {
const result = addon.testDoubleThrow();
console.log("testDoubleThrow returned:", result);
}).toThrow();
});