Skip to content

Commit 1bcb2c4

Browse files
committed
Stop JS3 from silently hanging if simd is not supported. Pipe through compilation error promise rejections so that they are not silently ignored.
1 parent b7babdf commit 1bcb2c4

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎JetStreamDriver.js‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ class Driver {
489489
const benchmarkResultsUI = document.getElementById(`benchmark-${benchmark.name}`);
490490
benchmarkResultsUI.classList.remove("benchmark-running");
491491
benchmarkResultsUI.classList.add("benchmark-error");
492+
493+
this.reportErrorToRunBenchmarkRunner();
492494
}
493495

494496
pushError(name, error) {
@@ -643,14 +645,23 @@ class Driver {
643645
}
644646

645647
async reportScoreToRunBenchmarkRunner()
648+
{
649+
await this.postToRunBenchmarkRunner(this.resultsJSON());
650+
}
651+
652+
async reportErrorToRunBenchmarkRunner()
653+
{
654+
await this.postToRunBenchmarkRunner(JSON.stringify({ errors: this.errors }));
655+
}
656+
657+
async postToRunBenchmarkRunner(content)
646658
{
647659
if (!isInBrowser)
648660
return;
649661

650662
if (!JetStreamParams.report)
651663
return;
652664

653-
const content = this.resultsJSON();
654665
await fetch("/report", {
655666
method: "POST",
656667
headers: {
@@ -829,7 +840,13 @@ class ShellScripts extends Scripts {
829840
class BrowserScripts extends Scripts {
830841
constructor(preloads) {
831842
super(preloads);
832-
this.add("window.onerror = top.currentReject;");
843+
// Rejected promises that nobody handles never reach window.onerror, ex: a wasm module that doesn't
844+
// compile hangs the run.
845+
this.add(`(() => {
846+
const reject = top.currentReject;
847+
window.onerror = (message, source, lineno, colno, error) => reject(error ?? message);
848+
window.onunhandledrejection = (event) => reject(event.reason);
849+
})();`);
833850
}
834851

835852
run() {
@@ -1815,9 +1832,7 @@ class AsyncWasmLegacyBenchmark extends Benchmark {
18151832
try {
18161833
andThen();
18171834
} catch(e) {
1818-
console.log("error running wasm:", e);
1819-
console.log(e.stack);
1820-
throw e;
1835+
top.currentReject(e);
18211836
}
18221837
});
18231838
`;
@@ -1829,11 +1844,7 @@ class AsyncWasmLegacyBenchmark extends Benchmark {
18291844
preloadCount++;
18301845
str += `JetStream.loadBlob(${JSON.stringify(name)}, "${resource}", () => {\n`;
18311846
}
1832-
str += `doRun().catch((e) => {
1833-
console.log("error running wasm:", e);
1834-
console.log(e.stack)
1835-
throw e;
1836-
});`;
1847+
str += `doRun().catch((error) => { top.currentReject(error); });`;
18371848
for (let i = 0; i < preloadCount; ++i) {
18381849
str += `})`;
18391850
}

‎wasm/tfjs-bundle.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23220,7 +23220,7 @@
2322023220
console.warn("Fatal error: no binary file found for ./wasm/tfjs-backend-wasm-simd.wasm and ./wasm/tfjs-backend-wasm.wasm");
2322123221
WebAssembly.instantiate(blob, info).then(function (output) {
2322223222
receiveInstance(output.instance, output.module);
23223-
});
23223+
}, readyPromiseReject);
2322423224
return {};
2322523225
// ************************ CHANGE END ************************
2322623226

0 commit comments

Comments
 (0)