mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-19 05:29:46 +08:00
Represent ordinary JavaScript arrays with hole, value, and explicit-undefined states; add sparse side storage and carry missing values through the frontend, native backends, runtime, and Node-facing consumers.
38 lines
1022 B
TypeScript
38 lines
1022 B
TypeScript
// An unchecked outer array read still produces JavaScript's undefined at
|
|
// runtime. A nested read must validate that receiver before typed tuple,
|
|
// record, or inner-array access reaches the native backend.
|
|
const pairs: [string, string][] = [["a", "b"]];
|
|
const records: { value: number }[] = [{ value: 9 }];
|
|
const matrix: number[][] = [[3]];
|
|
|
|
function readPair(index: number): void {
|
|
try {
|
|
console.log("pair", pairs[index][0]);
|
|
} catch (error) {
|
|
console.log("pair-error", error instanceof TypeError, typeof error);
|
|
}
|
|
}
|
|
|
|
function readRecord(index: number): void {
|
|
try {
|
|
console.log("record", records[index].value);
|
|
} catch (error) {
|
|
console.log("record-error", error instanceof TypeError, typeof error);
|
|
}
|
|
}
|
|
|
|
function readMatrix(index: number): void {
|
|
try {
|
|
console.log("matrix", matrix[index][0]);
|
|
} catch (error) {
|
|
console.log("matrix-error", error instanceof TypeError, typeof error);
|
|
}
|
|
}
|
|
|
|
readPair(0);
|
|
readPair(1);
|
|
readRecord(0);
|
|
readRecord(1);
|
|
readMatrix(0);
|
|
readMatrix(1);
|