// Refusals for builtin surface that loads but cannot act: the name exists so imports // link and feature checks see it, and using it throws ERR_NIB_UNSUPPORTED naming the // module and the reason. export function unsupported(module: string, what: string, reason: string): Error { return Object.assign( new Error(`ERR_NIB_UNSUPPORTED: node:${module} ${what} is not supported (${reason})`), { code: "ERR_NIB_UNSUPPORTED" }, ); } /** Set on a function or class that always refuses, with its reason. The surface walker * (tests/fixtures/guests/surface-walk.cjs) reads it, so a refusal is listed in * compat/divergences.json instead of counting as an implementation. */ export const REFUSED = Symbol.for("nibling.refused"); export function markRefused(target: T, reason: string): T { Object.defineProperty(target, REFUSED, { value: reason }); return target; } export function refused(module: string, name: string, reason: string): (...args: unknown[]) => never { return markRefused(() => { throw unsupported(module, `${name}()`, reason); }, reason); } /** A class whose constructor refuses, so `instanceof` against it is always false. */ export function refusedClass(module: string, name: string, reason: string): new (...args: unknown[]) => object { const cls = class { constructor() { throw unsupported(module, name, reason); } }; Object.defineProperty(cls, "name", { value: name }); return markRefused(cls, reason); }