code wiki / _hdl_build / nx_obj_test.nx

nx_obj_test.nx source

↩ module page · 21 lines · 1328 B

1// nx_obj_test.nx -- pinpoint jQuery's first runtime gap: does `var n={}` bind an object, and does `{}.toString` 2// (an Object.prototype method) resolve? Runs the JS and dumps the fetch() URLs it built (typeof-tagged). 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 tslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 8 9func main() -> i64 { 10 let js: *u8 = "var n={};fetch('https://s/n-is-'+(typeof n)+'.x');var t=n.toString;fetch('https://s/t-is-'+(typeof t)+'.x');var h=n.hasOwnProperty;fetch('https://s/h-is-'+(typeof h)+'.x');var gp=Object.getPrototypeOf;fetch('https://s/getproto-is-'+(typeof gp)+'.x');var arr=[1,2];fetch('https://s/slice-is-'+(typeof arr.slice)+'.x');" as *u8 11 let obx: *i64 = sys_mmap(16) as *i64 12 js_run_source_keep_doc(js, tslen(js), 0 as *u8, 0, obx) 13 let genv: *i64 = (obx[1]) as *i64 14 if (genv as i64) == 0 { cw("NULL genv\n" as *u8); return 1 } 15 let ub: *u8 = sys_mmap(2048) 16 let t: i64 = js_pending_total(genv) 17 var i: i64 = 0 18 while i < t { let ul: i64 = js_pending_url(genv, i, ub, 2048); if ul > 0 { cw(" " as *u8); cw(ub); cw("\n" as *u8) } i = i + 1 } 19 if t == 0 { cw("(no fetches -- the first stmt threw)\n" as *u8) } 20 return 0 21}