mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-31 07:23:06 +08:00
The first Object.freeze, Object.seal or Object.preventExtensions of a typed function creates its property table from the function's dynamic box. The box had no name, so later `f.name` reads answered "". The box now carries the function's JS name, as a closure flowing into any checked-dynamic slot does. The runtime's own callers (published values, os and node constants, the private-range block list, Wasm exports) freeze data they built, and now call scr_dyn_freeze_data, the freeze for values that are not functions. Object.isFrozen, Object.isSealed and Object.isExtensible read a function's existing table and answer false, false and true when it has none. Fully typed programs therefore link no dynamic-tier object code for these calls again.
22 lines
1.0 KiB
TypeScript
22 lines
1.0 KiB
TypeScript
// Integrity operations on typed functions keep their names: the first one
|
|
// creates the function's property table, whose `name` must be the
|
|
// function's own. Queries on functions no operation has touched answer
|
|
// without creating a table.
|
|
function hashC(x: number): number {
|
|
return x + 1;
|
|
}
|
|
const arrow = (s: string): string => s + "!";
|
|
const untouched = (a: number, b: number): number => a * b;
|
|
console.log(Object.isFrozen(untouched), Object.isSealed(untouched), Object.isExtensible(untouched));
|
|
Object.freeze(hashC);
|
|
Object.seal(arrow);
|
|
console.log(Object.isFrozen(hashC), Object.isSealed(hashC), Object.isExtensible(hashC), hashC(1));
|
|
console.log(Object.isFrozen(arrow), Object.isSealed(arrow), Object.isExtensible(arrow), arrow("a"));
|
|
function later(): number {
|
|
return 7;
|
|
}
|
|
Object.preventExtensions(later);
|
|
console.log(Object.isFrozen(later), Object.isSealed(later), Object.isExtensible(later), later());
|
|
const functions: any[] = [hashC, arrow, untouched, later];
|
|
console.log(functions.map((f) => `${f.name}/${f.length}`).join(" "));
|