From c320b614249b92302f43f5f2446ee6714f76509f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Thu, 16 Jun 2022 13:12:59 +0200 Subject: [PATCH] wasm: improve the specialHtmlTargets test It can actually be undefined, so test for that before checking the object type. This fixes the asyncify build. Change-Id: I5a6a0bc60c153290c35c20242400c59cd1312403 Reviewed-by: Aleksandr Reviakin Reviewed-by: Lorn Potter (cherry picked from commit 492b338f570afce3fbadb518bb0b9ab7fdf67e03) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/wasm/qwasmscreen.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index ad9e5b1f5a3..42ca608da17 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -172,10 +172,14 @@ std::string QWasmScreen::canvasSpecialHtmlTargetId() const bool QWasmScreen::hasSpecialHtmlTargets() const { static bool gotIt = []{ - // specialHTMLTargets is a JavaScript Array if available. Note that it is - // an abort() function if not, so a simple isUndefined() test won't work here. - return emscripten::val::module_property("specialHTMLTargets") - ["constructor"]["name"].as() == std::string("Array"); + // Enable use of specialHTMLTargets, if available + emscripten::val htmlTargets = emscripten::val::module_property("specialHTMLTargets"); + if (htmlTargets.isUndefined()) + return false; + + // Check that the object has the expected type - it can also be + // defined as an abort() function which prints an error on usage. + return htmlTargets["constructor"]["name"].as() == std::string("Array"); }(); return gotIt; }