diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index 6ac0ebb7d5b..4aa14d820f8 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -16,6 +16,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace emscripten; @@ -174,10 +176,46 @@ std::string QWasmScreen::canvasSpecialHtmlTargetId() const return std::string("!qtcanvas_") + std::to_string(uintptr_t(this)); } +namespace { + +// Compare Emscripten versions, returns > 0 if a is greater than b. + +int compareVersionComponents(int a, int b) +{ + return a >= 0 && b >= 0 ? a - b : 0; +} + +int compareEmscriptenVersions(std::tuple a, std::tuple b) +{ + if (std::get<0>(a) == std::get<0>(b)) { + if (std::get<1>(a) == std::get<1>(b)) { + return compareVersionComponents(std::get<2>(a), std::get<2>(b)); + } + return compareVersionComponents(std::get<1>(a), std::get<1>(b)); + } + return compareVersionComponents(std::get<0>(a), std::get<0>(b)); +} + +bool isEmsdkVersionGreaterThan(std::tuple test) +{ + return compareEmscriptenVersions( + std::make_tuple(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__), test) > 0; +} + +} // namespace + bool QWasmScreen::hasSpecialHtmlTargets() const { static bool gotIt = []{ // Enable use of specialHTMLTargets, if available + + // On Emscripten > 3.1.14 (exact version not known), emscripten::val::module_property() + // aborts instead of returning undefined when attempting to resolve the specialHTMLTargets + // property, in the case where it is not defined. Disable the availability test in this case. + // FIXME: Add alternative way to enable. + if (isEmsdkVersionGreaterThan(std::make_tuple(3, 1, 14))) + return false; + emscripten::val htmlTargets = emscripten::val::module_property("specialHTMLTargets"); if (htmlTargets.isUndefined()) return false;