code wiki / _hdl_build / nx_fn7_test.nx
nx_fn7_test.nx source
↩ module page · 24 lines · 1973 B
1// nx_fn7_test.nx -- isolate jQuery factory statement #7 shape: chained assign of a big object literal to a
2// FUNCTION's .fn and .prototype (ce.fn=ce.prototype={...}). Each probe fetches a marker; MISSING = it threw.
3import "nx_syscalls.nx"
4import "nx_js_eval.nx"
5func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
6func cw(s: *u8) -> i64 { sys_write(1,s,slen(s)); return 0 }
7func run1(label: *u8, js: *u8) -> i64 {
8 js_set_rt_dbg(1)
9 let obx: *i64 = sys_mmap(16) as *i64
10 js_run_source_keep_doc(js, slen(js), 0 as *u8, 0, obx)
11 let genv: *i64 = (obx[1]) as *i64
12 cw(label); cw(": " as *u8)
13 if (genv as i64)==0 { cw("NULL\n" as *u8); return 1 }
14 let ub: *u8 = sys_mmap(2048); let t: i64 = js_pending_total(genv)
15 if t==0 { cw("THREW(no fetch)" as *u8) } else { var i: i64=0; while i<t { let ul: i64=js_pending_url(genv,i,ub,2048); if ul>0 { cw(ub); cw(" " as *u8) } i=i+1 } }
16 cw("\n" as *u8); return 0
17}
18func main() -> i64 {
19 run1("A fn-prop-assign " as *u8, "var f=function(){};f.fn=f.prototype={a:1,b:function(){return 2}};fetch('x/fn-'+(typeof f.fn)+'-proto-'+(typeof f.prototype));" as *u8)
20 run1("B read-back-proto-meth" as *u8, "var f=function(){};f.fn=f.prototype={a:1,b:function(){return 2}};fetch('x/b-'+(typeof f.prototype.b)+'-a-'+f.prototype.a);" as *u8)
21 run1("C big-obj-lit-20props " as *u8, "var f=function(){};f.fn=f.prototype={jq:'v',ctor:f,len:0,toArray:function(){return 1},get:function(e){return e},each:function(e){return e},map:function(n){return n},slice:function(){return 1},first:function(){return 1},last:function(){return 1},eq:function(i){return i},end:function(){return 1},push:1,sort:2,splice:3};fetch('x/big-'+(typeof f.fn.eq));" as *u8)
22 run1("D chained-eq-nested " as *u8, "var ce=function(){};ce.fn=ce.prototype={map:function(n){return this.pushStack(ce.map(this,function(e,t){return n.call(e,t,e)}))}};fetch('x/d-'+(typeof ce.fn.map));" as *u8)
23 return 0
24}