Skip to content

Commit 9c7f53e

Browse files
committed
add support for compileStreaming
1 parent cce42f5 commit 9c7f53e

2 files changed

Lines changed: 26 additions & 22 deletions

File tree

examples/wasm-simple/README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@ export function fibonacciJavascript(i) {
186186
/******/ var installedWasmModuleData = installedWasmModules[wasmModuleId];
187187
/******/
188188
/******/ // a Promise means "currently loading" or "already loaded".
189-
/******/ if(installedWasmModuleData) {
190-
/******/ promises.push(installedWasmModuleData);
191-
/******/ } else {
192-
/******/ var promise = installedWasmModules[wasmModuleId] = fetch(__webpack_require__.p + "" + {"1":"80925f35a6f1cf550d38","3":"3d28950d91bc7246f5af","4":"1d2268b99656e9575a63"}[wasmModuleId] + ".wasm")
193-
/******/ .then(function(response) { return response.arrayBuffer(); })
194-
/******/ .then(function(bytes) { return WebAssembly.compile(bytes); })
195-
/******/ .then(function(module) { __webpack_require__.w[wasmModuleId] = module; })
196-
/******/ promises.push(promise);
197-
/******/ }
189+
/******/ promises.push(installedWasmModuleData ||
190+
/******/ promises.push(installedWasmModules[wasmModuleId] = fetch(__webpack_require__.p + "" + {"1":"80925f35a6f1cf550d38","3":"3d28950d91bc7246f5af","4":"1d2268b99656e9575a63"}[wasmModuleId] + ".wasm").then(function(response) {
191+
/******/ if(WebAssembly.compileStreaming) {
192+
/******/ return WebAssembly.compileStreaming(response);
193+
/******/ } else {
194+
/******/ return response.arrayBuffer().then(function(bytes) { return WebAssembly.compile(bytes); });
195+
/******/ }
196+
/******/ }).then(function(module) { __webpack_require__.w[wasmModuleId] = module; }))
197+
/******/ );
198198
/******/ });
199199
/******/ return Promise.all(promises);
200200
/******/ };
@@ -432,7 +432,7 @@ Version: webpack 3.8.1
432432
3d28950d91bc7246f5af.wasm 62 bytes 0, 1 [emitted]
433433
1d2268b99656e9575a63.wasm 67 bytes 0, 1 [emitted]
434434
1.output.js 486 bytes 1 [emitted]
435-
output.js 8.9 kB 2 [emitted] main
435+
output.js 8.94 kB 2 [emitted] main
436436
Entrypoint main = output.js
437437
chunk {0} 0.output.js, 80925f35a6f1cf550d38.wasm, 3d28950d91bc7246f5af.wasm, 1d2268b99656e9575a63.wasm 585 bytes {2} [rendered]
438438
> [0] ./example.js 3:1-17
@@ -460,6 +460,7 @@ chunk {1} 1.output.js, 80925f35a6f1cf550d38.wasm 41 bytes {2} [rendered]
460460
chunk {2} output.js (main) 788 bytes [entry] [rendered]
461461
> main [0] ./example.js
462462
[0] ./example.js 788 bytes {2} [built]
463+
single entry .\example.js main
463464
```
464465

465466
## Minimized (uglify-js, no zip)
@@ -473,7 +474,7 @@ Version: webpack 3.8.1
473474
3d28950d91bc7246f5af.wasm 62 bytes 0, 1 [emitted]
474475
1d2268b99656e9575a63.wasm 67 bytes 0, 1 [emitted]
475476
1.output.js 155 bytes 1 [emitted]
476-
output.js 8.74 kB 2 [emitted] main
477+
output.js 8.78 kB 2 [emitted] main
477478
Entrypoint main = output.js
478479
chunk {0} 0.output.js, 80925f35a6f1cf550d38.wasm, 3d28950d91bc7246f5af.wasm, 1d2268b99656e9575a63.wasm 585 bytes {2} [rendered]
479480
> [0] ./example.js 3:1-17
@@ -501,6 +502,7 @@ chunk {1} 1.output.js, 80925f35a6f1cf550d38.wasm 41 bytes {2} [rendered]
501502
chunk {2} output.js (main) 788 bytes [entry] [rendered]
502503
> main [0] ./example.js
503504
[0] ./example.js 788 bytes {2} [built]
505+
single entry .\example.js main
504506
505507
ERROR in output.js from UglifyJs
506508
Unexpected token: operator (>) [output.js:194,95]

lib/FetchCompileWasmMainTemplatePlugin.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,23 @@ class FetchCompileWasmMainTemplatePlugin {
4747
"var installedWasmModuleData = installedWasmModules[wasmModuleId];",
4848
"",
4949
"// a Promise means \"currently loading\" or \"already loaded\".",
50-
"if(installedWasmModuleData) {",
50+
"promises.push(installedWasmModuleData ||",
5151
this.indent([
52-
"promises.push(installedWasmModuleData);"
53-
]),
54-
"} else {",
55-
this.indent([
56-
`var promise = installedWasmModules[wasmModuleId] = fetch(${this.requireFn}.p + ${wasmModuleSrcPath})`,
52+
`promises.push(installedWasmModules[wasmModuleId] = fetch(${this.requireFn}.p + ${wasmModuleSrcPath}).then(function(response) {`,
5753
this.indent([
58-
".then(function(response) { return response.arrayBuffer(); })",
59-
".then(function(bytes) { return WebAssembly.compile(bytes); })",
60-
`.then(function(module) { ${this.requireFn}.w[wasmModuleId] = module; })`
54+
"if(WebAssembly.compileStreaming) {",
55+
this.indent([
56+
"return WebAssembly.compileStreaming(response);"
57+
]),
58+
"} else {",
59+
this.indent([
60+
"return response.arrayBuffer().then(function(bytes) { return WebAssembly.compile(bytes); });",
61+
]),
62+
"}"
6163
]),
62-
"promises.push(promise);"
64+
`}).then(function(module) { ${this.requireFn}.w[wasmModuleId] = module; }))`
6365
]),
64-
"}",
66+
");",
6567
]),
6668
"});",
6769
]);

0 commit comments

Comments
 (0)