mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +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.
52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
// Array methods over VALUES living in the checked-dynamic tree under array-mapped checker
|
|
// types — the record family's array sibling (corpus 2300's stance):
|
|
// `.sort()` on a checked-dynamic array runs the REAL method through the
|
|
// runtime receiver-kind dispatch (dynInvoke) — the spec's snapshot sort,
|
|
// stable, undefined sinking last, default comparator over ToString
|
|
// images, comparator calls JS-exact, the receiver answered by identity.
|
|
// Every static-receiver spelling here was an SC9001 ICE (call %arr.sort
|
|
// arg 0: expected array, got dyn).
|
|
'use strict';
|
|
|
|
// Object.keys of a dyn object answers a dyn array; .sort() orders it.
|
|
const d = JSON.parse('{"beta":1,"alpha":2,"gamma":3}');
|
|
console.log(Object.keys(d).sort().join(','));
|
|
|
|
// Default sort compares ToString images — numbers order lexically.
|
|
const nums = JSON.parse('[3,1,10,2]');
|
|
const same = nums.sort();
|
|
console.log(nums.join(','), 'identity', same === nums);
|
|
|
|
// A comparator orders numerically; the sort is in place.
|
|
nums.sort((a, b) => a - b);
|
|
console.log(nums.join(','));
|
|
nums.sort((a, b) => b - a);
|
|
console.log(nums.join(','));
|
|
|
|
// Strings, with a length tie broken stably by the default comparator.
|
|
console.log(JSON.parse('["b","a","c","aa"]').sort().join(','));
|
|
|
|
// undefined sinks to the end before any comparison; null sorts by text.
|
|
const holes = JSON.parse('[null,2,1]');
|
|
holes.push(undefined);
|
|
holes.sort();
|
|
console.log(holes.join(','), holes.length);
|
|
|
|
// A throwing comparator propagates catchably, and a non-function
|
|
// comparator throws V8's own TypeError.
|
|
try {
|
|
nums.sort(() => { throw new Error('cmp-boom'); });
|
|
} catch (e) {
|
|
console.log('caught', e.message);
|
|
}
|
|
try {
|
|
nums.sort('nope');
|
|
} catch (e) {
|
|
console.log(e.name, e.message);
|
|
}
|
|
|
|
// The chained consumer shape: sort feeding join, and a sorted dyn array
|
|
// validating into a typed slot.
|
|
const keys = Object.keys(JSON.parse('{"z":0,"a":0,"m":0}')).sort();
|
|
console.log(keys.join('|'), keys.length);
|