mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-20 05:40:17 +08:00
- The ratified rename rider (world-unification §7 lane 5): "DOM" collided with the browser DOM and, post-lane-1, the structure is no longer a document tree. Comments and doc prose now say "the checked-dynamic tree" for the noun and "dyn" adjectivally; runtime symbol names (scr_dyn_*), the error.domClone libCall, and the real web DOMException family are unchanged. - The few user-facing strings carrying the nickname move with it (the structuredClone cyclic message, the dc subscriber/publish fences, two emitter ICE texts); diagnostics snapshots regenerated (96 pass). One private compiler constant (DOM_PROTO_METHOD_NAMES -> DYN_PROTO_METHOD_NAMES) rides along. - Mechanical sweep, 142 files, comments/prose only — no behavior change.
46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
// Uint8Array/Buffer values crossing into `unknown`: the checked-dynamic tree's bytes kind —
|
|
// conversion on the way in (a copy, the boundary stance), checked-cast
|
|
// extraction on the way out (another copy), Node-exact String() (elements
|
|
// joined) and JSON.stringify (the index-keyed object form). The stdin
|
|
// toBytes(chunk: unknown) pattern.
|
|
|
|
function toBytes(chunk: unknown): Uint8Array {
|
|
if (typeof chunk === "string") return new TextEncoder().encode(chunk);
|
|
return new TextEncoder().encode(String(chunk));
|
|
}
|
|
|
|
const src = new Uint8Array([104, 105, 33]);
|
|
const u: unknown = src;
|
|
const back = u as Uint8Array;
|
|
console.log(back.length, back[0], back[1], back[2]);
|
|
console.log(String(u));
|
|
console.log(toBytes("hey").length, toBytes(u).length, toBytes(7).length);
|
|
|
|
// typeof over the bytes kind: every scalar kind test misses.
|
|
console.log(typeof u === "string", typeof u === "number", typeof u === "undefined");
|
|
console.log(u === null, u !== undefined);
|
|
|
|
// Under an unknown-valued index signature, and through unknown params.
|
|
const scratch: Record<string, unknown> = {};
|
|
scratch.buf = new Uint8Array([1, 2, 3]);
|
|
console.log(String(scratch.buf), (scratch.buf as Uint8Array).length);
|
|
console.log(JSON.stringify(scratch));
|
|
|
|
// Extraction is a fresh value each time (both directions copy — the
|
|
// documented aliasing divergence is asserted in the dyncheck harness, not
|
|
// against Node); the BYTES are value-exact.
|
|
const again = scratch.buf as Uint8Array;
|
|
console.log(again[0] + again[1] + again[2]);
|
|
|
|
// Buffer is bytes<u8> too. (String() of an unknown holding a BUFFER joins
|
|
// the elements like a Uint8Array — Node decodes UTF-8 there; the checked-dynamic tree
|
|
// cannot tell the two apart. SEMANTICS.md documents it; not asserted here
|
|
// where Node is the oracle.)
|
|
const buf = Buffer.from("hi");
|
|
const ub: unknown = buf;
|
|
console.log((ub as Uint8Array).length, (ub as Uint8Array)[0]);
|
|
|
|
// Empty payloads.
|
|
const empty: unknown = new Uint8Array(0);
|
|
console.log(String(empty) === "", (empty as Uint8Array).length);
|