onNewScript-wasm-02.js (1346B)
1 // |jit-test| skip-if: !wasmDebuggingEnabled() 2 // Draining the job queue from an onNewScript hook reporting a streamed wasm 3 // module should not deadlock. 4 5 ignoreUnhandledRejections(); 6 7 try { 8 WebAssembly.compileStreaming(); 9 // Avoid mixing the test's jobs with the debuggee's, so that 10 // automated checks can make sure AutoSaveJobQueue only 11 // suspends debuggee work. 12 drainJobQueue(); 13 } catch (err) { 14 assertEq(String(err).indexOf("not supported with --no-threads") !== -1, true); 15 quit(); 16 } 17 18 var g = newGlobal({newCompartment: true}); 19 20 var source = new g.Uint8Array(wasmTextToBinary('(module (func unreachable))')); 21 g.source = source; 22 23 var dbg = new Debugger(g); 24 dbg.allowWasmBinarySource = true; 25 dbg.onNewScript = function (s, g) { 26 drainJobQueue(); 27 }; 28 29 // For the old code to deadlock, OffThreadPromiseRuntimeState::internalDrain 30 // needs to get two Dispatchables at once when it swaps queues. A call to 31 // instantiateStreaming enqueues a job that will kick off a helper thread, so to 32 // make sure that two helper threads have had time to complete and enqueue their 33 // Dispatchables, we put a delay in the job queue after the helper thread 34 // launches. 35 g.eval(` 36 WebAssembly.instantiateStreaming(source); 37 WebAssembly.instantiateStreaming(source); 38 Promise.resolve().then(() => sleep(0.1)); 39 `); 40 41 drainJobQueue();