diff options
author | David Skoland <david.skoland@qt.io> | 2022-06-01 11:39:35 +0200 |
---|---|---|
committer | David Skoland <david.skoland@qt.io> | 2022-06-03 05:30:46 +0200 |
commit | 2c66a8a850ca1a25e6b00f6c42d423328621ede7 (patch) | |
tree | 55afa80d95cae3d7beb22bf19c0d5dfc7e79775b | |
parent | 18f0793f9cc23042fe78efe2a3dcc8e6e9a90ccf (diff) | |
download | qtbase-2c66a8a850ca1a25e6b00f6c42d423328621ede7.tar.gz |
Streamline error handling in qtloader.js
Added new function handleError which does the usual work whenever there
there is an error, including logging the error to console. Also make
the app exit when the emscripten module fails to load.
Additionally, make sure we correctly report it as crash
if the module fails to load.
Change-Id: I9d723373a34ccbb146959a2207ebded8bcbd4f18
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
-rw-r--r-- | src/plugins/platforms/wasm/qtloader.js | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js index 33280237ab..f51a574078 100644 --- a/src/plugins/platforms/wasm/qtloader.js +++ b/src/plugins/platforms/wasm/qtloader.js @@ -61,6 +61,8 @@ // Optional exited element constructor function. // showError : function(crashed, exitCode, containerElement) // Optional error element constructor function. +// statusChanged : function(newStatus) +// Optional callback called when the status of the app has changed // // path : <string> // Prefix path for wasm file, realative to the loading HMTL file. @@ -232,13 +234,19 @@ function QtLoader(config) self.restartCount = 0; + function handleError(error) { + self.error = error; + setStatus("Error"); + console.error(error); + } + function fetchResource(filePath) { var fullPath = config.path + filePath; return fetch(fullPath).then(function(response) { if (!response.ok) { - self.error = response.status + " " + response.statusText + " " + response.url; - setStatus("Error"); - return Promise.reject(self.error) + let err = response.status + " " + response.statusText + " " + response.url; + handleError(err); + return Promise.reject(err) } else { return response; } @@ -287,13 +295,11 @@ function QtLoader(config) // Check for Wasm & WebGL support; set error and return before downloading resources if missing if (!webAssemblySupported()) { - self.error = "Error: WebAssembly is not supported" - setStatus("Error"); + handleError("Error: WebAssembly is not supported"); return; } if (!webGLSupported()) { - self.error = "Error: WebGL is not supported" - setStatus("Error"); + handleError("Error: WebGL is not supported"); return; } @@ -319,8 +325,9 @@ function QtLoader(config) Promise.all([emscriptenModuleSourcePromise, wasmModulePromise]).then(function(){ completeLoadEmscriptenModule(applicationName, emscriptenModuleSource, wasmModule); }).catch(function(error) { - self.error = error; - setStatus("Error"); + handleError(error); + // An error here is fatal, abort + self.moduleConfig.onAbort(error) }); } @@ -333,8 +340,7 @@ function QtLoader(config) WebAssembly.instantiate(wasmModule, imports).then(function(instance) { successCallback(instance, wasmModule); }, function(error) { - self.error = error; - setStatus("Error"); + handleError(error) }); return {}; }; @@ -418,8 +424,7 @@ function QtLoader(config) // Restart by readling the emscripten app module. ++self.restartCount; if (self.restartCount > config.restartLimit) { - self.error = "Error: This application has crashed too many times and has been disabled. Reload the page to try again." - setStatus("Error"); + handleError("Error: This application has crashed too many times and has been disabled. Reload the page to try again."); return; } loadEmscriptenModule(applicationName); |