Simplify asm creation (#131)

This commit is contained in:
Jaco Greeff
2020-11-02 19:02:28 +01:00
committed by GitHub
parent 9e9535cc2b
commit bb748c0225
3 changed files with 7 additions and 8 deletions
+3 -3
View File
@@ -9,7 +9,7 @@ let wasm;
let cachegetInt32 = null;
let cachegetUint8 = null;
async function initWasm (wasmBytes, asmFallback, wbg) {
async function initWasm (wasmBytes, asmFn, wbg) {
try {
assert(typeof WebAssembly !== 'undefined', 'WebAssembly is not available in your environment');
@@ -18,8 +18,8 @@ async function initWasm (wasmBytes, asmFallback, wbg) {
wasm = source.instance.exports;
} catch (error) {
// if we have a valid supplied asm.js, return that
if (asmFallback && asmFallback.ext_blake2b) {
wasm = asmFallback;
if (asmFn) {
wasm = asmFn(wbg);
} else {
console.error(`ERROR: Unable to initialize ${pkg.name} ${pkg.version}`);
console.error(error);
+1 -1
View File
@@ -3,4 +3,4 @@
// Stub replaced at build time
module.exports = {};
module.exports = null;
+3 -4
View File
@@ -41,8 +41,7 @@ echo "*** Building asm.js version"
# cleanup the generated asm, converting to cjs
sed -i -e '/import {/d' $ASM
echo "const imports = require('../js/imports');
$(cat $ASM)" > $ASM
sed -i -e 's/{abort.*},memasmFunc/imports, memasmFunc/g' $ASM
sed -i -e 's/export var /module\.exports\./g' $ASM
sed -i -e '/export var /d' $ASM
sed -i -e 's/{abort.*},memasmFunc/wbg, memasmFunc/g' $ASM
sed -i -e 's/var retasmFunc = /module.exports = (wbg) => /' $ASM
rm -rf build/wasm/*-e