@@ -775,8 +775,8 @@ class Benchmark {
775
775
776
776
if ( this . plan . preload ) {
777
777
let str = "" ;
778
- for ( let [ variableName , blobUrlOrPath ] of this . preloads )
779
- str += `const ${ variableName } = "${ blobUrlOrPath } ";\n` ;
778
+ for ( let [ variableName , blobURLOrPath ] of this . preloads )
779
+ str += `const ${ variableName } = "${ blobURLOrPath } ";\n` ;
780
780
addScript ( str ) ;
781
781
}
782
782
@@ -1174,7 +1174,7 @@ class AsyncBenchmark extends DefaultBenchmark {
1174
1174
// part of a larger project's build system or a wasm benchmark compiled from a language that doesn't compile with emcc.
1175
1175
class WasmEMCCBenchmark extends AsyncBenchmark {
1176
1176
get prerunCode ( ) {
1177
- let str = `
1177
+ return `
1178
1178
let verbose = false;
1179
1179
1180
1180
let globalObject = this;
@@ -1205,31 +1205,38 @@ class WasmEMCCBenchmark extends AsyncBenchmark {
1205
1205
},
1206
1206
};
1207
1207
globalObject.Module = Module;
1208
+ ` ;
1209
+ }
1210
+
1211
+ // This is in runnerCode rather than prerunCode because prerunCode isn't currently structured to be async by default.
1212
+ get runnerCode ( ) {
1213
+ let str = `(async function doRunWrapper() {`
1214
+ if ( isInBrowser ) {
1215
+ str += `
1216
+ async function getBinary(key, blobURL) {
1217
+ const response = await fetch(blobURL);
1218
+ Module[key] = new Int8Array(await response.arrayBuffer());
1219
+ }
1220
+ ` ;
1221
+ } else
1222
+ str += `
1223
+ // Needed because SpiderMonkey shell doesn't have a setTimeout.
1224
+ Module.setStatus = null;
1225
+ Module.monitorRunDependencies = null;
1226
+ function getBinary(key, path) {
1227
+ Module[key] = new Int8Array(read(path, "binary"));
1228
+ }
1208
1229
` ;
1209
1230
1210
- if ( isInBrowser ) {
1211
- str += `
1212
- function getBinary(key, blobUrl) {
1213
- var xhr = new XMLHttpRequest();
1214
- xhr.open('GET', blobUrl, false);
1215
- xhr.responseType = 'arraybuffer';
1216
- xhr.send(null);
1217
- Module[key] = new Int8Array(xhr.response);
1218
- }
1219
- ` ;
1220
- } else
1221
- str += `
1222
- Module.setStatus = null;
1223
- Module.monitorRunDependencies = null;
1224
- function getBinary(key, path) {
1225
- Module[key] = new Int8Array(read(path, "binary"));
1226
- }
1227
- ` ;
1228
-
1229
- for ( let [ preloadKey , blobUrlOrPath ] of this . preloads )
1230
- str += `getBinary("${ preloadKey } ", "${ blobUrlOrPath } ");\n`
1231
-
1232
- return str ;
1231
+ for ( let [ preloadKey , blobURLOrPath ] of this . preloads )
1232
+ str += `await getBinary("${ preloadKey } ", "${ blobURLOrPath } ");\n`
1233
+
1234
+ str += super . runnerCode ;
1235
+
1236
+ str += "\n})().catch((error) => { top.currentReject(error); });"
1237
+
1238
+ return str ;
1239
+
1233
1240
}
1234
1241
} ;
1235
1242
0 commit comments