mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
T10 and T12 of the zero-cost compatibility plan, plus the maintainer decisions: - Programs that name Temporal type-check against TS 7's temporal lib (added only for them) and lower to Node 24's answers: typeof is "undefined", globalThis.Temporal is undefined, other uses throw ReferenceError at the root read. - node:v8 is importable; getHeapStatistics answers allocator-derived figures in Node's shape; other members fence with the by-design reason. vm's refusal says why. - node:stream/web exports the web stream globals themselves. - node:dns/promises and dns.promises: lookup and lookupService as promises, in the link-gated scr_dns_promises.c unit. - eval and the Function constructor throw Node's EvalError under --disallow-code-generation-from-strings; the corpus harness runs the Node oracle with that flag for `// @disallow-code-generation`. - graceful-fs is served as node:fs. Every new lowering replaces a refusal, and the new runtime code links only when used, so other programs compile to identical bytes (zero-cost gate). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
963 B
JavaScript
37 lines
963 B
JavaScript
// @disallow-code-generation
|
|
// The probe packages ship (zod 4's allowsEval): an aliased Function
|
|
// constructor inside try/catch decides between a generated fast path and
|
|
// an interpreted fallback. Arguments convert to strings before the
|
|
// refusal, calling an object's toString.
|
|
const F = Function;
|
|
function allowsEval() {
|
|
try {
|
|
new F("");
|
|
return true;
|
|
} catch (e) {
|
|
console.log("probe:", e.constructor === EvalError, e.message);
|
|
return false;
|
|
}
|
|
}
|
|
const parse = allowsEval()
|
|
? new F("input", "return input.trim()")
|
|
: (input) => input.trim();
|
|
console.log(JSON.stringify(parse(" value ")));
|
|
|
|
try {
|
|
new Function({ toString() { console.log("toString called"); return "x"; } }, "return x");
|
|
} catch (e) {
|
|
console.log(String(e));
|
|
}
|
|
try {
|
|
eval({ toString() { console.log("never called"); return "1"; } });
|
|
} catch (e) {
|
|
console.log(String(e));
|
|
}
|
|
const indirect = eval;
|
|
try {
|
|
indirect("1");
|
|
} catch (e) {
|
|
console.log(e.name);
|
|
}
|