code wiki / (root) / nx_jsbalance.nx

nx_jsbalance.nx

buildroot/runtime/nx_jsbalance.nx

9487 B208 linesdepth 2pulls 2 transitivereach 44 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_jsbalance.nx -- DOES THE EMITTED JAVASCRIPT EVEN LEX? A structural balance check over a page this estate GENERATES, so a bad emit cannot reach a browser as a black screen. WHY THIS EXISTS, AND IT IS MY OWN OUTAGE. 2026-08-25 I edited nx_game_page_emit's emitted guard, shipped it through build -> promote -> ship lane -> live docroot, and /world/beach and /world/craft both went BLACK. Every gate in the chain was GREEN: the organ compiled, the wasm-vm gate passed, the ship lane read the page back and verified its marker. NOT ONE OF THEM PARSES THE JAVASCRIPT. The estate emits ~410 KB of JS per page and had no check that it lexes at all, so a single stray brace or unterminated string takes the whole script down -- and with the script down, even the software-renderer fallback never runs. That is the difference between "ugly" and "black". ★A PIPELINE THAT VERIFIES EVERY STAGE EXCEPT THE ARTIFACT'S OWN LANGUAGE IS GREEN ALL THE WAY TO THE OUTAGE. WHAT IT CHECKS, AND ONLY THIS: the three faults that take a whole script out at once -- 1. an unterminated string or template literal at EOF 2. an unterminated block comment at EOF 3. bracket depth that ends non-zero, or ever goes NEGATIVE (a close before its open) It is a LEXER, not a parser. It cannot see a misspelled identifier or a wrong argument, and it does not pretend to: those fail one call, not the whole file, and the browser reports them. ⚠ DECLARED IMPRECISION, because a checker whose blind spots are unstated gets trusted as exact. JavaScript cannot be lexed without parsing: `/` is division or the start of a regex literal depending on the grammatical position before it, and no scanner settles that without a parser. This one treats every `/` as division, so a REGEX LITERAL containing a quote or a brace would be miscounted. That is the one construct it can be wrong about, and it errs by REPORTING IMBALANCE on a valid file -- loud, never silent. Before wiring, it is calibrated on the known-good live page: if it cannot pass a page a browser runs, it is too naive to gate with, and the calibration says so rather than the ratchet being loosened to fit. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 23 importers

nx_syscalls.nx nx_jsbalance.nx nx_beach_workspace_scripts_gate_t4 nx_craft_body_driver_t138.nx nx_craft_combined_emit_t28.nx nx_craft_combined_emit_t29.nx nx_craft_emit.nx nx_craft_feedback_emit_t28.nx nx_craft_garment_emit_t132.nx nx_craft_integrated_emit_t73.nx nx_craft_knight_emit_t25.nx nx_craft_material_body_emit_t61.nx

diagram shows first 10 each side; +0 more imports, +13 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_beach_workspace_scripts_gate_t48.nxnx_craft_body_driver_t138.nxnx_craft_combined_emit_t28.nxnx_craft_combined_emit_t29.nxnx_craft_emit.nxnx_craft_feedback_emit_t28.nxnx_craft_garment_emit_t132.nxnx_craft_integrated_emit_t73.nxnx_craft_knight_emit_t25.nxnx_craft_material_body_emit_t61.nxnx_craft_material_emit_t55.nxnx_craft_move_emit_t72.nxnx_craft_pipeline_emit_t64.nxnx_craft_recovery_emit_t23.nxnx_craft_search_emit_t53.nxnx_craft_support_emit_t31.nxnx_craft_workspace_emit_t48.nxnx_game_demand_lifecycle_gate_t98.nxnx_imported_body_page_gate_t45.nxnx_imported_body_page_gate_t49.nxnx_imported_body_page_gate_t50.nxnx_imported_body_page_gate_t59.nxnx_jsemit_gate.nx

structs

none

consts

33const JSB_CODE: i64 = 0
34const JSB_SQ: i64 = 1 // '...'
35const JSB_DQ: i64 = 2 // "..."
36const JSB_BT: i64 = 3 // `...`
37const JSB_LINE: i64 = 4 // // ...
38const JSB_BLOCK: i64 = 5 // /* ... */
41const JSB_O_BRACE: i64 = 0 // final {} depth
42const JSB_O_PAREN: i64 = 1 // final () depth
43const JSB_O_BRACK: i64 = 2 // final [] depth
44const JSB_O_STATE: i64 = 3 // scanner state at EOF
45const JSB_O_NEGAT: i64 = 4 // offset of the first NEGATIVE depth, -1 if none
46const JSB_O_OPENAT: i64 = 5 // offset where the unterminated construct began, -1 if none
47const JSB_O_SCAN: i64 = 6 // bytes actually scanned -- the coverage figure
48const JSB_O_N: i64 = 8
51const JSB_OK: i64 = 0
52const JSB_UNTERM_STR: i64 = 0 - 2
53const JSB_UNTERM_CMT: i64 = 0 - 3
54const JSB_DEPTH: i64 = 0 - 4
55const JSB_NEGATIVE: i64 = 0 - 5
163const JSB_NO_SCRIPT: i64 = 0 - 1

functions

57func jsb_check(buf: *u8, n: i64, out: *i64) -> i64
165func jsb_find(buf: *u8, n: i64, from: i64, pat: *u8, plen: i64) -> i64
181func jsb_check_page(buf: *u8, n: i64, out: *i64) -> i64