code wiki / _hdl_build / nx_dcl_test.nx
nx_dcl_test.nx source
↩ module page · 28 lines · 1859 B
1// nx_dcl_test.nx -- diagnose the async player-init lifecycle. Runs page JS in DOM_TREE mode (via
2// js_render_page_pending_begin) and dumps EVERY pending fetch URL, revealing:
3// rs-<v>.m3u8 -> document.readyState is <v> (jQuery fires $(ready) SYNC iff 'complete'/'interactive')
4// dcl.m3u8 -> a document 'DOMContentLoaded' listener FIRED during the initial parse+drain
5// onload.m3u8 -> window.onload FIRED
6// sync.m3u8 -> a plain top-level fetch fired (sanity: the script ran at all)
7// If only sync.m3u8 + rs-loading/undefined appear (no dcl/onload), async init never runs -> we must dispatch it.
8import "nx_syscalls.nx"
9import "nx_js_eval.nx"
10
11func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func tslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
13
14func main() -> i64 {
15 let html: *u8 = "<div id='x'></div><script>fetch('https://s/sync.m3u8');try{fetch('https://s/rs-'+document.readyState+'.m3u8');}catch(e){fetch('https://s/rs-undef.m3u8');}try{document.addEventListener('DOMContentLoaded',function(){fetch('https://s/dcl.m3u8');});}catch(e2){}try{window.onload=function(){fetch('https://s/onload.m3u8');};}catch(e3){}</script>" as *u8
16 let empty: *u8 = "" as *u8
17 let obx: *i64 = sys_mmap(32) as *i64
18 js_render_page_pending_begin(html, tslen(html), empty, 0, obx)
19 let genv: *i64 = (obx[1]) as *i64
20 if (genv as i64) == 0 { cw("NULL genv\n" as *u8); return 1 }
21 let ub: *u8 = sys_mmap(2048)
22 cw("=== pending after initial DOM_TREE run+drain ===\n" as *u8)
23 let t: i64 = js_pending_total(genv)
24 var i: i64 = 0
25 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 }
26 if t == 0 { cw(" (no pending fetches at all)\n" as *u8) }
27 return 0
28}