Files
scriptc/tests/diagnostics/native-shim-monkeypatching.ts
T
Malte UblandClaude Opus 5.5 2b03f66ff3 Host patching H1: typed process output write slot
Reading `process.stdout.write` as a value, `write.bind(stream)`, and
`process.stdout.write = fn` now reach the runtime stream object's write
slot in TypeScript, and a program that replaces an output write method
calls its typed writes through that slot (SC8020 refuses the combination
with Node islands until H2 shares the stream object with them).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 05:37:56 -07:00

21 lines
778 B
TypeScript

// Patching a NATIVE host object: Node lets a library swap
// `process.stdout.write`, hand out `process.stdout.write.bind(...)`, or
// redefine a module member with Object.defineProperty. The process output
// stream's write slot is the runtime stream object's, so the assignment and
// the bind compile. A builtin module's exports are direct calls, so those
// forms keep an explicit refusal instead of silently patching nothing. The
// working split: use the module's functions directly.
import * as fs from "node:fs";
export function bindReadFileSync(): typeof fs.readFileSync {
return fs.readFileSync.bind(fs);
}
export function defineReadFileSync(): void {
Object.defineProperty(fs, "readFileSync", { value: () => "" });
}
bindReadFileSync();
defineReadFileSync();