Merge remote-tracking branch 'origin/main' into nektro-patch-44307

This commit is contained in:
Meghan Denny
2025-08-25 11:24:49 -07:00
424 changed files with 43409 additions and 7115 deletions

View File

@@ -30,7 +30,7 @@ if (cluster.isPrimary) {
}
`,
});
bunRun(joinP(dir, "index.ts"), bunEnv);
bunRun(joinP(dir, "index.ts"), bunEnv, true);
});
test("cloneable and non-transferable not-equals (BunFile)", () => {
@@ -49,6 +49,11 @@ if (cluster.isPrimary) {
worker.on("online", function () {
worker.send({ file });
});
worker.on("exit", function (code, signal) {
if (code !== 0) {
process.exit(code);
}
});
worker.on("message", function (data) {
worker.kill();
const { file } = data;
@@ -63,10 +68,14 @@ if (cluster.isPrimary) {
console.log("W", msg);
process.send!(msg);
});
process.on("uncaughtExceptionMonitor", (error) => {
console.error(error);
process.exit(1);
});
}
`,
});
bunRun(joinP(dir, "index.ts"), bunEnv);
bunRun(joinP(dir, "index.ts"), bunEnv, true);
});
test("cloneable and non-transferable not-equals (net.BlockList)", () => {
@@ -84,6 +93,11 @@ if (cluster.isPrimary) {
worker.on("online", function () {
worker.send({ blocklist });
});
worker.on("exit", function (code, signal) {
if (code !== 0) {
process.exit(code);
}
});
worker.on("message", function (data) {
worker.kill();
const { blocklist } = data;
@@ -95,10 +109,14 @@ if (cluster.isPrimary) {
} else {
process.on("message", msg => {
console.log("W", msg);
process.send!(msg);
process.send!(msg);
});
process.on("uncaughtExceptionMonitor", (error) => {
console.error(error);
process.exit(1);
});
}
`,
});
bunRun(joinP(dir, "index.ts"), bunEnv);
bunRun(joinP(dir, "index.ts"), bunEnv, true);
});

View File

@@ -2038,4 +2038,52 @@ describe("readline.createInterface()", () => {
// rl.write("text");
// rl.write(null, { ctrl: true, name: "c" });
// });
it("should support Symbol.dispose for using statements", () => {
const input = new PassThrough();
const output = new PassThrough();
let closed = false;
{
using rl = readline.createInterface({
input: input,
output: output,
});
rl.on("close", () => {
closed = true;
});
// Verify the interface has the Symbol.dispose method
assert.strictEqual(typeof rl[Symbol.dispose], "function");
assert.strictEqual(!closed, true);
}
// After exiting the using block, the interface should be closed
assert.strictEqual(closed, true);
});
it("should support Symbol.dispose as alias for close()", () => {
const input = new PassThrough();
const output = new PassThrough();
let closed = false;
const rl = readline.createInterface({
input: input,
output: output,
});
rl.on("close", () => {
closed = true;
});
// Verify Symbol.dispose exists and works the same as close()
assert.strictEqual(typeof rl[Symbol.dispose], "function");
assert.strictEqual(!closed, true);
rl[Symbol.dispose]();
assert.strictEqual(closed, true);
assert.strictEqual(rl.closed, true);
});
});

View File

@@ -46,4 +46,50 @@ describe("readline/promises.createInterface()", () => {
done();
});
});
it("should support Symbol.dispose for using statements", () => {
const fi = new FakeInput();
let closed = false;
{
using rl = readlinePromises.createInterface({
input: fi,
output: fi,
});
rl.on("close", () => {
closed = true;
});
// Verify the interface has the Symbol.dispose method
assert.strictEqual(typeof rl[Symbol.dispose], "function");
assert.strictEqual(!closed, true);
}
// After exiting the using block, the interface should be closed
assert.strictEqual(closed, true);
});
it("should support Symbol.dispose as alias for close()", () => {
const fi = new FakeInput();
let closed = false;
const rl = readlinePromises.createInterface({
input: fi,
output: fi,
});
rl.on("close", () => {
closed = true;
});
// Verify Symbol.dispose exists and works the same as close()
assert.strictEqual(typeof rl[Symbol.dispose], "function");
assert.strictEqual(!closed, true);
rl[Symbol.dispose]();
assert.strictEqual(closed, true);
assert.strictEqual(rl.closed, true);
});
});

View File

@@ -2,6 +2,7 @@
'use strict';
const common = require('../common');
if (common.isWindows) return; // TODO: BUN
const assert = require('assert');
const cp = require('child_process');

View File

@@ -0,0 +1,58 @@
import { expect, test } from "bun:test";
import { Worker } from "worker_threads";
test("Worker implements Symbol.asyncDispose", async () => {
const worker = new Worker(
`
const { parentPort } = require("worker_threads");
parentPort?.postMessage("ready");
`,
{ eval: true },
);
// Wait for the worker to be ready
await new Promise(resolve => {
worker.on("message", msg => {
if (msg === "ready") {
resolve(msg);
}
});
});
// Test that Symbol.asyncDispose exists and is a function
expect(typeof worker[Symbol.asyncDispose]).toBe("function");
// Test that calling Symbol.asyncDispose terminates the worker
const disposeResult = await worker[Symbol.asyncDispose]();
expect(disposeResult).toBeUndefined();
});
test("Worker can be used with await using", async () => {
let workerTerminated = false;
{
await using worker = new Worker(
`
const { parentPort } = require("worker_threads");
parentPort?.postMessage("hello from worker");
`,
{ eval: true },
);
// Listen for worker exit to confirm termination
worker.on("exit", () => {
workerTerminated = true;
});
// Wait for the worker message to ensure it's running
await new Promise(resolve => {
worker.on("message", resolve);
});
// Worker should automatically terminate when leaving this block via Symbol.asyncDispose
}
// Give a moment for the exit event to be emitted
await new Promise(resolve => setTimeout(resolve, 100));
expect(workerTerminated).toBe(true);
});