(binary, binaryFile, imports, callback)
| 817 | } |
| 818 | |
| 819 | function instantiateAsync(binary, binaryFile, imports, callback) { |
| 820 | if (!binary && |
| 821 | typeof WebAssembly.instantiateStreaming == 'function' && |
| 822 | !isDataURI(binaryFile) && |
| 823 | // Don't use streaming for file:// delivered objects in a webview, fetch them synchronously. |
| 824 | !isFileURI(binaryFile) && |
| 825 | // Avoid instantiateStreaming() on Node.js environment for now, as while |
| 826 | // Node.js v18.1.0 implements it, it does not have a full fetch() |
| 827 | // implementation yet. |
| 828 | // |
| 829 | // Reference: |
| 830 | // https://github.com/emscripten-core/emscripten/pull/16917 |
| 831 | !ENVIRONMENT_IS_NODE && |
| 832 | typeof fetch == 'function') { |
| 833 | return fetch(binaryFile, { credentials: 'same-origin' }).then(function(response) { |
| 834 | // Suppress closure warning here since the upstream definition for |
| 835 | // instantiateStreaming only allows Promise<Repsponse> rather than |
| 836 | // an actual Response. |
| 837 | // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure is fixed. |
| 838 | /** @suppress {checkTypes} */ |
| 839 | var result = WebAssembly.instantiateStreaming(response, imports); |
| 840 | |
| 841 | return result.then( |
| 842 | callback, |
| 843 | function(reason) { |
| 844 | // We expect the most common failure cause to be a bad MIME type for the binary, |
| 845 | // in which case falling back to ArrayBuffer instantiation should work. |
| 846 | err('wasm streaming compile failed: ' + reason); |
| 847 | err('falling back to ArrayBuffer instantiation'); |
| 848 | return instantiateArrayBuffer(binaryFile, imports, callback); |
| 849 | }); |
| 850 | }); |
| 851 | } else { |
| 852 | return instantiateArrayBuffer(binaryFile, imports, callback); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | // Create the wasm instance. |
| 857 | // Receives the wasm imports, returns the exports. |
no test coverage detected