mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 12:19:46 -04:00
Fix race condition while loading decompressors
Former-commit-id: 588d8f114bcbaf595b95d67b831486e5a82fcb28 [formerly 1dac03025f7974975f85a5399b4194ec536e9552] [formerly d8572192ccb248b85bbd881cc4930f95a930fd7b] [formerly 4b6bf4ca42f2f5ca4bc3d964df0bca673dd9d6a8 [formerly 7480b0a6790073125d42e55eb17d402044e9e705 [formerly fa0b47cb1d48fe9ee3fed96da8a9d2f7ab2939cf]]] Former-commit-id: 5e0565d37a525d347356475e5abc445b614a6fe8 [formerly e595b77eb7baeb73c7cd15224f1808c389ac0933 [formerly d8f99fd4dc692a0d7f484fd382be9f586b934683]] Former-commit-id: e634a80bff96925d9ad901c1812f17cbfd4e801e [formerly ada8d9087c5130595401196ac155104572c8a12c] Former-commit-id: e5c4b37b2d392f48e9aee3e6542d5cb601d690f8
This commit is contained in:
parent
1b92f08e7f
commit
d11dcabce8
@ -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;
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user