From 1bcb2c46930c98d2720f2bd07a71c7f52fd54840 Mon Sep 17 00:00:00 2001 From: Justin Michaud Date: Sat, 1 Aug 2026 11:38:50 -0600 Subject: [PATCH] Stop JS3 from silently hanging if simd is not supported. Pipe through compilation error promise rejections so that they are not silently ignored. --- JetStreamDriver.js | 31 +++++++++++++++++++++---------- wasm/tfjs-bundle.js | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 7fbced72..78b829af 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -489,6 +489,8 @@ class Driver { const benchmarkResultsUI = document.getElementById(`benchmark-${benchmark.name}`); benchmarkResultsUI.classList.remove("benchmark-running"); benchmarkResultsUI.classList.add("benchmark-error"); + + this.reportErrorToRunBenchmarkRunner(); } pushError(name, error) { @@ -643,6 +645,16 @@ class Driver { } async reportScoreToRunBenchmarkRunner() + { + await this.postToRunBenchmarkRunner(this.resultsJSON()); + } + + async reportErrorToRunBenchmarkRunner() + { + await this.postToRunBenchmarkRunner(JSON.stringify({ errors: this.errors })); + } + + async postToRunBenchmarkRunner(content) { if (!isInBrowser) return; @@ -650,7 +662,6 @@ class Driver { if (!JetStreamParams.report) return; - const content = this.resultsJSON(); await fetch("/report", { method: "POST", headers: { @@ -829,7 +840,13 @@ class ShellScripts extends Scripts { class BrowserScripts extends Scripts { constructor(preloads) { super(preloads); - this.add("window.onerror = top.currentReject;"); + // Rejected promises that nobody handles never reach window.onerror, ex: a wasm module that doesn't + // compile hangs the run. + this.add(`(() => { + const reject = top.currentReject; + window.onerror = (message, source, lineno, colno, error) => reject(error ?? message); + window.onunhandledrejection = (event) => reject(event.reason); + })();`); } run() { @@ -1815,9 +1832,7 @@ class AsyncWasmLegacyBenchmark extends Benchmark { try { andThen(); } catch(e) { - console.log("error running wasm:", e); - console.log(e.stack); - throw e; + top.currentReject(e); } }); `; @@ -1829,11 +1844,7 @@ class AsyncWasmLegacyBenchmark extends Benchmark { preloadCount++; str += `JetStream.loadBlob(${JSON.stringify(name)}, "${resource}", () => {\n`; } - str += `doRun().catch((e) => { - console.log("error running wasm:", e); - console.log(e.stack) - throw e; - });`; + str += `doRun().catch((error) => { top.currentReject(error); });`; for (let i = 0; i < preloadCount; ++i) { str += `})`; } diff --git a/wasm/tfjs-bundle.js b/wasm/tfjs-bundle.js index 34a1bb36..55290c0c 100644 --- a/wasm/tfjs-bundle.js +++ b/wasm/tfjs-bundle.js @@ -23220,7 +23220,7 @@ console.warn("Fatal error: no binary file found for ./wasm/tfjs-backend-wasm-simd.wasm and ./wasm/tfjs-backend-wasm.wasm"); WebAssembly.instantiate(blob, info).then(function (output) { receiveInstance(output.instance, output.module); - }); + }, readyPromiseReject); return {}; // ************************ CHANGE END ************************