code wiki / _hdl_build / nx_js_unicode_probe.nx

nx_js_unicode_probe.nx source

↩ module page · 48 lines · 2733 B

1// nx_js_unicode_probe.nx -- ISOLATE the construct that blocks real bundles (2026-07-27). 2// netflix's 3.9MB bundle fails to parse at a lodash deburr map: {À:"A",Á:"A",...} -- object 3// keys that are NON-ASCII (UTF-8 multibyte) IDENTIFIERS, legal JS and near-universal in 4// bundled apps. This probe pins whether that is really the blocker, ASCII control first. 5// Each row prints its own verdict; exit 0 iff the ASCII controls pass (so a RED row is a 6// NAMED gap, not a broken probe). 7import "nx_syscalls.nx" 8import "nx_js_eval.nx" 9 10func up_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func up_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 12 13// run a snippet; print PARSE-OK/PARSE-FAIL. returns 1 if it parsed+ran, else 0. 14func up_try(label: *u8, src: *u8) -> i64 { 15 let out: *i64 = sys_mmap(16) as *i64 16 let rc: i64 = js_run_source(src, up_len(src), out) 17 up_p(label) 18 if rc == 0 { up_p(" OK\x0a\x00" as *u8); return 1 } 19 up_p(" FAIL\x0a\x00" as *u8) 20 return 0 21} 22 23func main() -> i64 { 24 // --- ASCII controls: these MUST pass, else the probe itself is wrong. 25 let c1: i64 = up_try("C1 ascii ident key {a:1} \x00" as *u8, 26 "var o={a:1}; o.a;\x00" as *u8) 27 let c2: i64 = up_try("C2 quoted non-ascii key {\"A-grave\":1} \x00" as *u8, 28 "var o={\"\xC3\x80\":1}; o[\"\xC3\x80\"];\x00" as *u8) 29 // --- the suspect: BARE non-ASCII identifier as an object key (lodash deburr shape). 30 let s1: i64 = up_try("S1 BARE non-ascii key {A-grave:\"A\"} \x00" as *u8, 31 "var o={\xC3\x80:\"A\"}; 1;\x00" as *u8) 32 // --- the same character as a plain variable name (is it the KEY position or the LEXER?). 33 let s2: i64 = up_try("S2 non-ascii var name var A-grave=1 \x00" as *u8, 34 "var \xC3\x80=1; \xC3\x80;\x00" as *u8) 35 // --- the exact netflix shape: several such keys in one literal. 36 let s3: i64 = up_try("S3 netflix deburr shape {A-g:..,A-a:..} \x00" as *u8, 37 "var m={\xC3\x80:\"A\",\xC3\x81:\"A\",\xC3\xA0:\"a\"}; 1;\x00" as *u8) 38 39 up_p("\x0aREAD: C1/C2 are controls (must be OK). S1-S3 name the gap.\x0a\x00" as *u8) 40 if c1 == 1 { if c2 == 1 { 41 up_p("controls GREEN -- any S FAIL above is a REAL, NAMED engine gap\x0a\x00" as *u8) 42 if s1 == 1 { if s2 == 1 { if s3 == 1 { up_p("verdict=NO-GAP (unicode idents already work)\x0a\x00" as *u8); return 0 } } } 43 up_p("verdict=GAP-CONFIRMED: non-ASCII identifiers\x0a\x00" as *u8) 44 return 0 45 } } 46 up_p("verdict=PROBE-BROKEN (a control failed)\x0a\x00" as *u8) 47 return 1 48}