code wiki / _hdl_build / nx_js_bom_gate.nx
nx_js_bom_gate.nx source
↩ module page · 58 lines · 4117 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_js_bom_gate.nx -- proves the R-JS-BOM rung: window/location/navigator/history host namespaces --
4// property reads (location.href, navigator.userAgent, window.innerWidth, window.location.href chaining)
5// and no-op methods that hydration code calls (history.pushState, window.addEventListener, location.reload)
6// do NOT throw. Uses js_run_source_read. license_tier: ORIGINAL
7import "nx_js_eval.nx"
8
9func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
10" as *u8); return ok }
11func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
12
13func gr_str(label: *u8, src: *u8, rn: *u8, want: *u8) -> i64 {
14 let out: *i64 = sys_mmap(16) as *i64
15 let rc: i64 = js_run_source_read(src, gsl(src), rn, out)
16 gw(" "); gw(label); gw(": " as *u8)
17 if rc != 0 { gw("FAIL (eval rc=1)\n" as *u8); return 0 }
18 if out[0] != VAL_STR { gw("FAIL (not a string, tag="); gn(out[0]); gw(")\n" as *u8); return 0 }
19 let rec: *i64 = (out[1]) as *i64
20 let wl: i64 = gsl(want)
21 if ev_str_len(rec) != wl { gw("FAIL (len; got '" as *u8); sys_write(1, ev_str_bytes(rec), ev_str_len(rec)); gw("')\n" as *u8); return 0 }
22 let rb: *u8 = ev_str_bytes(rec)
23 var i: i64 = 0
24 while i < wl { if (rb[i] & 0xff) != (want[i] & 0xff) { gw("FAIL (got '" as *u8); sys_write(1, rb, wl); gw("')\n" as *u8); return 0 } i = i + 1 }
25 gw("ok ('" as *u8); gw(want); gw("')\n" as *u8); return 1
26}
27func gr_num(label: *u8, src: *u8, rn: *u8, want: i64) -> i64 {
28 let out: *i64 = sys_mmap(16) as *i64
29 let rc: i64 = js_run_source_read(src, gsl(src), rn, out)
30 gw(" "); gw(label); gw(": " as *u8)
31 if rc != 0 { gw("FAIL (eval rc=1)\n" as *u8); return 0 }
32 if out[0] != VAL_NUM { gw("FAIL (not a number, tag="); gn(out[0]); gw(")\n" as *u8); return 0 }
33 if out[1] != want { gw("FAIL (got "); gn(out[1]); gw(" want "); gn(want); gw(")\n" as *u8); return 0 }
34 gw("ok ("); gn(want); gw(")\n" as *u8); return 1
35}
36
37func main(argc: i64, argv: *i64) -> i64 {
38 gw("=== nx_js_bom_gate: window / location / navigator / history ===\n" as *u8)
39 var pass: i64 = 0
40 var tot: i64 = 0
41 tot = tot + 1; pass = pass + gr_str("T0 location.href" as *u8, "var x=location.href;" as *u8, "x" as *u8, "https://nishi.local/" as *u8)
42 tot = tot + 1; pass = pass + gr_str("T1 location.pathname" as *u8, "var x=location.pathname;" as *u8, "x" as *u8, "/" as *u8)
43 tot = tot + 1; pass = pass + gr_str("T2 navigator.userAgent" as *u8, "var x=navigator.userAgent;" as *u8, "x" as *u8, "Mozilla/5.0 (NishiOS) NishiBrowser/1.0" as *u8)
44 tot = tot + 1; pass = pass + gr_str("T3 window.location.href (chain)" as *u8, "var x=window.location.href;" as *u8, "x" as *u8, "https://nishi.local/" as *u8)
45 tot = tot + 1; pass = pass + gr_num("T4 window.innerWidth" as *u8, "var x=window.innerWidth;" as *u8, "x" as *u8, 1280)
46 tot = tot + 1; pass = pass + gr_num("T5 history.pushState no-op" as *u8, "var x=1;history.pushState(0,0,'/p');x=7;" as *u8, "x" as *u8, 7)
47 tot = tot + 1; pass = pass + gr_num("T6 window.addEventListener no-op" as *u8, "var x=0;window.addEventListener('load',function(){});x=3;" as *u8, "x" as *u8, 3)
48 tot = tot + 1; pass = pass + gr_str("T7 navigator.language" as *u8, "var x=navigator.language;" as *u8, "x" as *u8, "en-US" as *u8)
49 tot = tot + 1; pass = pass + gr_num("T8 location.reload no-op" as *u8, "var x=0;location.reload();x=8;" as *u8, "x" as *u8, 8)
50 // T9 LIAR-KILL: a WRONG expectation must FAIL (proves the harness reads the real value, not a constant).
51 tot = tot + 1
52 let neg: i64 = gr_str("T9 liar-kill (expect wrong lang)" as *u8, "var x=navigator.language;" as *u8, "x" as *u8, "fr-FR" as *u8)
53 if neg == 0 { pass = pass + 1; gw(" (correctly did NOT match 'fr-FR' -> liar-kill holds)\n" as *u8) } else { gw(" !! liar-kill BROKE\n" as *u8) }
54
55 gw("=== "); gn(pass); gw("/"); gn(tot); gw(" "); if pass == tot { gw("GREEN ===\n" as *u8) } else { gw("RED ===\n" as *u8) }
56 if pass == tot { return 0 }
57 return 1
58}