Files
bun.sh/test/js/node/async_hooks/async-context/async-context-crypto-randomInt.js
Jarred Sumner e1505b7143 Use JSC::Integrity:: auditCellFully in bindings (#22538)
### What does this PR do?

### How did you verify your code works?
2025-09-10 00:31:54 -07:00

20 lines
563 B
JavaScript

process.exitCode = 1;
const { AsyncLocalStorage } = require("async_hooks");
const crypto = require("crypto");
const asyncLocalStorage = new AsyncLocalStorage();
asyncLocalStorage.run({ test: "crypto.randomInt" }, () => {
crypto.randomInt(100, (err, n) => {
if (asyncLocalStorage.getStore()?.test !== "crypto.randomInt") {
console.error("FAIL: crypto.randomInt callback lost context");
process.exit(1);
}
if (n >= 100) {
throw new Error("crypto.randomInt callback returned a number >= 100");
}
process.exit(0);
});
});