From 33561b0457fb5067bddf7b0955b44197f4d3b030 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 8 Apr 2025 10:06:06 +0200 Subject: [PATCH] Remove unnecessary try / catch blocks when using the winit-based wasm-preview Commit b2645dff6c60770b9ba53ac4496ade0dbd8c8e66 and 4b37d9a1f110fa9bc7dbd2bfcae83a899074ab4e introduced the use of spawn, which doesn't thrown anymore. --- docs/astro/src/utils/slint-docs-preview.html | 10 +--------- editors/vscode/src/wasm_preview.ts | 6 +----- tools/slintpad/src/lsp.ts | 6 +----- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/docs/astro/src/utils/slint-docs-preview.html b/docs/astro/src/utils/slint-docs-preview.html index 076972b0d..c3df888c9 100644 --- a/docs/astro/src/utils/slint-docs-preview.html +++ b/docs/astro/src/utils/slint-docs-preview.html @@ -85,15 +85,7 @@ async function run() { await slint.default(); - try { - slint.run_event_loop(); - // this will trigger a JS exception, so this line will never be reached! - } catch (e) { - // The winit event loop, when targeting wasm, throws a JavaScript exception to break out of - // Rust without running any destructors. Don't rethrow the exception but swallow it, as - // this is no error and we truly want to resolve the promise of this function by returning - // the model markers. - } + slint.run_event_loop(); let selector = ["code.language-slint", ".rustdoc pre.language-slint", "div.highlight-slint div.highlight", "div.highlight-slint\\,no-auto-preview div.highlight"] .map((sel) => `${sel}:not([class*=slint\\,ignore]):not([class*=slint\\,no-preview])`).join(","); diff --git a/editors/vscode/src/wasm_preview.ts b/editors/vscode/src/wasm_preview.ts index c1aa6c90c..422592ca2 100644 --- a/editors/vscode/src/wasm_preview.ts +++ b/editors/vscode/src/wasm_preview.ts @@ -109,11 +109,7 @@ function getPreviewHtml( const vscode = acquireVsCodeApi(); let promises = {}; - try { - slint_preview.run_event_loop(); - } catch (_) { - // This is actually not an error:-/ - } + slint_preview.run_event_loop(); const canvas_id = "canvas"; diff --git a/tools/slintpad/src/lsp.ts b/tools/slintpad/src/lsp.ts index 80eeae408..11ef1d4a6 100644 --- a/tools/slintpad/src/lsp.ts +++ b/tools/slintpad/src/lsp.ts @@ -222,11 +222,7 @@ export class Lsp { style: string, ): Promise { if (this.#preview_connector === null) { - try { - slint_preview.run_event_loop(); - } catch (e) { - // this is not an error! - } + slint_preview.run_event_loop(); const params = new URLSearchParams(window.location.search); const experimental = params.get("SLINT_EXPERIMENTAL_FEATURES");