diff options
author | Morten Sørvig <morten.sorvig@qt.io> | 2022-06-16 13:12:59 +0200 |
---|---|---|
committer | Morten Sørvig <morten.sorvig@qt.io> | 2022-06-22 07:14:59 +0200 |
commit | 492b338f570afce3fbadb518bb0b9ab7fdf67e03 (patch) | |
tree | d0e3076bd496b485e9c12a4d3ad4996ab70aa342 /src | |
parent | 45de3fedbac73bc8ff501117d64f19092e1b18b4 (diff) |
wasm: improve the specialHtmlTargets test
It can actually be undefined, so test for that before checking
the object type.
This fixes the asyncify build.
Pick-to: 6.4
Change-Id: I5a6a0bc60c153290c35c20242400c59cd1312403
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmscreen.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index ad9e5b1f5a..42ca608da1 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>() == 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>() == std::string("Array"); }(); return gotIt; } |