// Auto-generated by scripts/gen_parity_tests.py from docs/runtime-parity.md.
// Module: node:worker_threads
// This file is a byte-for-byte parity test against `node --experimental-strip-types`.
// Edit the TODO lines below to exercise each API; rerun
// `./run_parity_tests.sh --filter test_parity_worker_threads` to verify.

import * as worker_threads from "node:worker_threads";


// ── Module-Level Functions ──
// worker_threads.setEnvironmentData(key[, value]) + getEnvironmentData(key)
try {
  worker_threads.setEnvironmentData("parity-key", "parity-value");
  console.log("worker_threads.setEnvironmentData typeof:", typeof worker_threads.setEnvironmentData);
  console.log("worker_threads.getEnvironmentData('parity-key'):", worker_threads.getEnvironmentData("parity-key"));
} catch (e: any) { console.log("worker_threads.setEnvironmentData ERR:", e && e.message); }

// worker_threads.markAsUntransferable(object) + isMarkedAsUntransferable(object)
try {
  const buf = new ArrayBuffer(8);
  console.log("worker_threads.isMarkedAsUntransferable(before):", worker_threads.isMarkedAsUntransferable(buf));
  worker_threads.markAsUntransferable(buf);
  console.log("worker_threads.isMarkedAsUntransferable(after):", worker_threads.isMarkedAsUntransferable(buf));
} catch (e: any) { console.log("worker_threads.markAsUntransferable ERR:", e && e.message); }

// worker_threads.markAsUncloneable(object) — type probe only (avoid postMessage side effects)
try {
  console.log("worker_threads.markAsUncloneable typeof:", typeof worker_threads.markAsUncloneable);
} catch (e: any) { console.log("worker_threads.markAsUncloneable ERR:", e && e.message); }

// worker_threads.moveMessagePortToContext(port, ctx) — type probe (needs vm.Context)
try {
  console.log("worker_threads.moveMessagePortToContext typeof:", typeof worker_threads.moveMessagePortToContext);
} catch (e: any) { console.log("worker_threads.moveMessagePortToContext ERR:", e && e.message); }

// worker_threads.receiveMessageOnPort(port) — type probe (port closed below)
try {
  console.log("worker_threads.receiveMessageOnPort typeof:", typeof worker_threads.receiveMessageOnPort);
} catch (e: any) { console.log("worker_threads.receiveMessageOnPort ERR:", e && e.message); }

// worker_threads.postMessageToThread(threadId, value[, transferList][, timeout]) — type probe (no other thread)
try {
  console.log("worker_threads.postMessageToThread typeof:", typeof worker_threads.postMessageToThread);
} catch (e: any) { console.log("worker_threads.postMessageToThread ERR:", e && e.message); }

// ── Module-Level Properties ──
console.log("worker_threads.isMainThread:", worker_threads.isMainThread);
console.log("worker_threads.isInternalThread:", worker_threads.isInternalThread);
console.log("worker_threads.parentPort:", worker_threads.parentPort);
console.log("worker_threads.threadId:", worker_threads.threadId);
console.log("worker_threads.threadName:", worker_threads.threadName);
console.log("worker_threads.workerData:", worker_threads.workerData);
console.log("worker_threads.resourceLimits:", worker_threads.resourceLimits);
console.log("worker_threads.SHARE_ENV:", worker_threads.SHARE_ENV);
console.log("worker_threads.locks:", worker_threads.locks);

// ── Class: Worker ──
// new Worker(filename[, options]) — type probe only (don't spawn a worker process)
try {
  console.log("Worker typeof:", typeof worker_threads.Worker);
} catch (e: any) { console.log("Worker ERR:", e && e.message); }

// ── Worker Events ──
// 'online' / 'message' / 'messageerror' / 'error' / 'exit' — type probe only
try {
  console.log("Worker events: probe-only (don't spawn)");
} catch (e: any) { console.log("Worker events ERR:", e && e.message); }

// ── Class: MessagePort ──
// port.postMessage / port.close / port.start / port.ref / port.unref / port.hasRef
try {
  const ch = new worker_threads.MessageChannel();
  console.log("MessagePort.postMessage typeof:", typeof ch.port1.postMessage);
  console.log("MessagePort.close typeof:", typeof ch.port1.close);
  console.log("MessagePort.start typeof:", typeof ch.port1.start);
  console.log("MessagePort.ref typeof:", typeof ch.port1.ref);
  console.log("MessagePort.unref typeof:", typeof ch.port1.unref);
  console.log("MessagePort.hasRef typeof:", typeof ch.port1.hasRef);
  ch.port1.close();
  ch.port2.close();
} catch (e: any) { console.log("MessagePort ERR:", e && e.message); }

// ── MessagePort Events ──
// 'close' — type probe (covered above via close())
try {
  console.log("MessagePort 'close' event: probe-only");
} catch (e: any) { console.log("MessagePort 'close' ERR:", e && e.message); }

// ── Class: MessageChannel ──
try {
  const channel = new worker_threads.MessageChannel();
  console.log("MessageChannel.port1 typeof:", typeof channel.port1);
  console.log("MessageChannel.port2 typeof:", typeof channel.port2);
  channel.port1.close();
  channel.port2.close();
  console.log("MessageChannel constructed + closed");
} catch (e: any) { console.log("MessageChannel ERR:", e && e.message); }

// ── Class: BroadcastChannel ──
try {
  const bc = new worker_threads.BroadcastChannel("parity-bc");
  console.log("BroadcastChannel.postMessage typeof:", typeof bc.postMessage);
  console.log("BroadcastChannel.close typeof:", typeof bc.close);
  console.log("BroadcastChannel.ref typeof:", typeof bc.ref);
  console.log("BroadcastChannel.unref typeof:", typeof bc.unref);
  console.log("BroadcastChannel.onmessage initially:", bc.onmessage);
  console.log("BroadcastChannel.onmessageerror initially:", bc.onmessageerror);
  bc.close();
} catch (e: any) { console.log("BroadcastChannel ERR:", e && e.message); }

// ── Web Locks (experimental) ──
// PERRY-SKIP: locks.request / locks.query — experimental Web Locks API,
// not yet implemented in Perry and tied to async scheduler internals.

// Coverage: 9 auto-emitted, 33 TODO, 0 skip-listed.

/*
@covers
crates/perry-stdlib/src/worker_threads.rs:
  - js_worker_threads_get_worker_data
  - js_worker_threads_has_pending
  - js_worker_threads_on
  - js_worker_threads_parent_port
  - js_worker_threads_post_message
  - js_worker_threads_process_pending
*/
