code wiki / _hdl_build / nx_umd_test.nx

nx_umd_test.nx source

↩ module page · 37 lines · 1957 B

1// nx_umd_test.nx -- test the EXACT jQuery sub-expressions the tracer flagged (@2536 UMD wrapper, @6586 Symbol 2// install). Each is a `fetch('.../<label>-'+(<expr as bool/typeof>)+'.x')`; a MISSING fetch = that expr threw. 3import "nx_syscalls.nx" 4import "nx_js_eval.nx" 5 6func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 7func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 8 9func run1(label: *u8, js: *u8) -> i64 { 10 js_set_rt_dbg(1) 11 let obx: *i64 = sys_mmap(16) as *i64 12 js_run_source_keep_doc(js, slen(js), 0 as *u8, 0, obx) 13 let ep: i64 = js_rt_errpos_get() 14 let genv: *i64 = (obx[1]) as *i64 15 cw(label); cw(": " as *u8) 16 if (genv as i64) == 0 { cw("NULL-genv\n" as *u8); return 1 } 17 let ub: *u8 = sys_mmap(2048) 18 let t: i64 = js_pending_total(genv) 19 if t == 0 { cw("THREW (no fetch)" as *u8) } else { 20 var pi: i64 = 0 21 while pi < t { let ul: i64 = js_pending_url(genv, pi, ub, 2048); if ul > 0 { cw(ub); cw(" " as *u8) } pi = pi + 1 } 22 } 23 if ep >= 0 { cw(" [errpos>=0]" as *u8) } 24 cw("\n" as *u8) 25 return 0 26} 27 28func main() -> i64 { 29 run1("A typeof module " as *u8, "fetch('x/'+(typeof module));" as *u8) 30 run1("B obj==typeof module " as *u8, "fetch('x/'+('object'==typeof module));" as *u8) 31 run1("C umd-full-cond " as *u8, "fetch('x/'+('object'==typeof module&&'object'==typeof module.exports));" as *u8) 32 run1("D umd-ternary " as *u8, "var r='object'==typeof module&&'object'==typeof module.exports?'m':'t';fetch('x/'+r);" as *u8) 33 run1("E typeof Symbol " as *u8, "fetch('x/'+(typeof Symbol));" as *u8) 34 run1("F fn==typeof Symbol&&idx " as *u8, "var o={};var a=[1];'function'==typeof Symbol&&(o[Symbol.iterator]=a[Symbol.iterator]);fetch('x/done');" as *u8) 35 run1("G bareword this at top " as *u8, "fetch('x/'+(typeof this));" as *u8) 36 return 0 37}