diff --git a/www/js/lib/uiUtil.js b/www/js/lib/uiUtil.js index f6d4d720..4af8cceb 100644 --- a/www/js/lib/uiUtil.js +++ b/www/js/lib/uiUtil.js @@ -754,12 +754,11 @@ define(rqDef, function(util) { appstate.sessionScale = appstate.windowScale; } - // Reports an error in loading one of the ASM or WASM machines to the UI API Status Panel // This can't be done in app.js because the error occurs after the API panel is first displayed - function reportAssemblerErrorToAPIStatusPanel(decoderType, error) { - // Report error to API panel because error is produced asynchronously after panel is first displayed + function reportAssemblerErrorToAPIStatusPanel(decoderType, error, assemblerMachineType) { console.error('Could not instantiate any ' + decoderType + ' decoder!', error); + params.decompressorAPI.assemblerMachineType = assemblerMachineType; params.decompressorAPI.errorStatus = 'Error loading ' + decoderType + ' decompressor!'; var decompAPI = document.getElementById('decompressorAPIStatus'); decompAPI.innerHTML = 'Decompressor API: ' + params.decompressorAPI.errorStatus; diff --git a/www/js/lib/xzdec_wrapper.js b/www/js/lib/xzdec_wrapper.js index 8107f8c3..292ba7ba 100644 --- a/www/js/lib/xzdec_wrapper.js +++ b/www/js/lib/xzdec_wrapper.js @@ -26,14 +26,17 @@ // because they cannot interpret WebAssembly. var rqDefXZ = ['uiUtil']; +// Variable specific to this decompressor (will be used to populate global variable) +var XZMachineType = null; + // Select asm or wasm conditionally if ('WebAssembly' in self) { console.debug('Instantiating WASM xz decoder'); - params.decompressorAPI.assemblerMachineType = 'WASM'; + XZMachineType = 'WASM'; rqDefXZ.push('xzdec-wasm'); } else { console.debug('Instantiating ASM xz decoder'); - params.decompressorAPI.assemblerMachineType = 'ASM'; + XZMachineType = 'ASM'; rqDefXZ.push('xzdec-asm'); } @@ -54,20 +57,23 @@ define(rqDefXZ, function(uiUtil) { var xzdec; XZ().then(function (instance) { + params.decompressorAPI.assemblerMachineType = XZMachineType; xzdec = instance; }).catch(function (err) { - if (params.decompressorAPI.assemblerMachineType === 'ASM') { + if (XZMachineType === 'ASM') { // There is no fallback, because we were attempting to load the ASM machine, so report error immediately - uiUtil.reportAssemblerErrorToAPIStatusPanel('XZ', err); + uiUtil.reportAssemblerErrorToAPIStatusPanel('XZ', err, XZMachineType); } else { console.warn('WASM failed to load, falling back to ASM...', err); - params.decompressorAPI.assemblerMachineType = 'ASM'; + // Fall back to ASM + XZMachineType = 'ASM'; XZ = null; require(['xzdec-asm'], function () { XZ().then(function (instance) { + params.decompressorAPI.assemblerMachineType = XZMachineType; xzdec = instance; }).catch(function (err) { - uiUtil.reportAssemblerErrorToAPIStatusPanel('XZ', err); + uiUtil.reportAssemblerErrorToAPIStatusPanel('XZ', err, XZMachineType); }); }); } diff --git a/www/js/lib/zstddec_wrapper.js b/www/js/lib/zstddec_wrapper.js index f33f7527..3c057c07 100644 --- a/www/js/lib/zstddec_wrapper.js +++ b/www/js/lib/zstddec_wrapper.js @@ -26,14 +26,17 @@ // because they cannot interpret WebAssembly. var rqDefZD = ['uiUtil']; +// Variable specific to this decompressor (will be used to populate global variable) +var ZSTDMachineType = null; + // Select asm or wasm conditionally if ('WebAssembly' in self) { console.debug('Instantiating WASM zstandard decoder'); - params.decompressorAPI.assemblerMachineType = 'WASM'; + ZSTDMachineType = 'WASM'; rqDefZD.push('zstddec-wasm'); } else { console.debug('Instantiating ASM zstandard decoder'); - params.decompressorAPI.assemblerMachineType = 'ASM'; + ZSTDMachineType = 'ASM'; rqDefZD.push('zstddec-asm'); } @@ -102,20 +105,23 @@ define(rqDefZD, function(uiUtil) { }; ZD().then(function (inst) { + params.decompressorAPI.assemblerMachineType = ZSTDMachineType; instantiateDecoder(inst); }).catch(function (err) { - if (params.decompressorAPI.assemblerMachineType === 'ASM') { + if (ZSTDMachineType === 'ASM') { // There is no fallback, because we were attempting to load the ASM machine, so report error immediately - uiUtil.reportAssemblerErrorToAPIStatusPanel('ZSTD', err); + uiUtil.reportAssemblerErrorToAPIStatusPanel('ZSTD', err, ZSTDMachineType); } else { console.warn('WASM failed to load, falling back to ASM...', err); - params.decompressorAPI.assemblerMachineType = 'ASM'; + // Fall back to ASM + ZSTDMachineType = 'ASM'; ZD = null; require(['zstddec-asm'], function () { ZD().then(function (inst) { + params.decompressorAPI.assemblerMachineType = ZSTDMachineType; instantiateDecoder(inst); }).catch(function (err) { - uiUtil.reportAssemblerErrorToAPIStatusPanel('ZSTD', err); + uiUtil.reportAssemblerErrorToAPIStatusPanel('ZSTD', err, ZSTDMachineType); }); }); }