code wiki / _hdl_build / nx_pre_test.nx
nx_pre_test.nx source
↩ module page · 42 lines · 1999 B
1// nx_pre_test.nx -- run ONLY the surrogate preamble (no jQuery) with the BLK-ERR tracer, to isolate whether
2// the offset-0 error is the preamble/engine interaction itself or something jQuery triggers. Prints errpos +
3// probes typeof window/document/setTimeout after.
4import "nx_syscalls.nx"
5import "nx_video_sniff.nx"
6import "nx_video_sniff_fetch.nx"
7import "nx_surrogate.nx"
8
9func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
10func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
11func pnum(n0: i64) -> i64 {
12 var n: i64 = n0
13 if n < 0 { cw("-" as *u8); n = 0 - n }
14 if n == 0 { cw("0" as *u8); return 0 }
15 let buf: *u8 = sys_mmap(32)
16 var i: i64 = 0
17 while n > 0 { buf[i] = ((n % 10) + 48) as u8; n = n / 10; i = i + 1 }
18 while i > 0 { i = i - 1; sys_write(1, ((buf as i64) + i) as *u8, 1) }
19 return 0
20}
21
22func main() -> i64 {
23 let sgt: *i64 = sg_new(); sg_seed(sgt)
24 let pre: *u8 = sys_mmap(16384)
25 let pl: i64 = sg_build_preamble(sgt, pre, 16384)
26 cw("preamble bytes = " as *u8); pnum(pl); cw("\n" as *u8)
27 js_set_rt_dbg(2)
28 let obx: *i64 = sys_mmap(16) as *i64
29 js_run_source_keep_doc(pre, pl, 0 as *u8, 0, obx)
30 let ep: i64 = js_rt_errpos_get()
31 cw("PREAMBLE-ALONE RT-ERRPOS = " as *u8); pnum(ep); cw("\n" as *u8)
32 let genv: *i64 = (obx[1]) as *i64
33 if (genv as i64) == 0 { cw("NULL genv\n" as *u8); return 1 }
34 js_set_rt_dbg(0)
35 let probe: *u8 = "fetch('https://p/window-'+(typeof window)+'.x');fetch('https://p/document-'+(typeof document)+'.x');fetch('https://p/setTimeout-'+(typeof setTimeout)+'.x');fetch('https://p/ga-'+(typeof ga)+'.x');" as *u8
36 js_run_more_in_genv(genv, probe, slen(probe))
37 let ub: *u8 = sys_mmap(2048)
38 let t: i64 = js_pending_total(genv)
39 var pi: i64 = 0
40 while pi < t { let ul: i64 = js_pending_url(genv, pi, ub, 2048); if ul > 0 { cw(" PROBE " as *u8); cw(ub); cw("\n" as *u8) } pi = pi + 1 }
41 return 0
42}