Adjust WebAssembly init (#365)

* Adjust WebAssembly init

* Adjust

* Re-add length check
This commit is contained in:
Jaco
2022-06-21 08:21:29 +03:00
committed by GitHub
parent da37be391e
commit bf924e5da0
+6 -4
View File
@@ -3,8 +3,6 @@
import type { InitFn, InitPromise, InitResult, WasmBaseInstance } from './types';
import { assert } from '@polkadot/util';
/**
* @name createWasmFn
* @description
@@ -22,7 +20,11 @@ export function createWasmFn <C extends WasmBaseInstance> (root: string, wasmByt
};
try {
assert(typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
if (!wasmBytes || !wasmBytes.length) {
throw new Error('No WebAssembly provided for initialization');
} else if (typeof WebAssembly !== 'object' || typeof WebAssembly.instantiate !== 'function') {
throw new Error('WebAssembly is not available in your environment');
}
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
@@ -30,7 +32,7 @@ export function createWasmFn <C extends WasmBaseInstance> (root: string, wasmByt
result.type = 'wasm';
} catch (error) {
// if we have a valid supplied asm.js, return that
if (asmFn) {
if (typeof asmFn === 'function') {
result.wasm = asmFn(wbg);
result.type = 'asm';
} else {