wasm: disable run-time check for specialHTMLTargets
Recent versions of Emscripten may abort if module_property() is used to look up specialHTMLTargets, which makes run-time checking impossible. The abort is implemented on the JS property getter on the Module object, which means that it's not possible to bypass this by using e.g. EM_ASM instead of the C++ API. Disable usage of specialHTMLTargets on emsdk > 3.1.14 for now, until we can add API (or find some other means) for opting in. This commit also adds functions for comparing Emscripten versions. Pick-to: 6.4 Change-Id: Ibe5d1a82f267fa95dd62cdfc66595bc23036933f Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io> Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
parent
683936d3cb
commit
4711f078b7
@ -16,6 +16,8 @@
|
||||
#include <QtGui/qguiapplication.h>
|
||||
#include <private/qhighdpiscaling_p.h>
|
||||
|
||||
#include <tuple>
|
||||
|
||||
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<int, int, int> a, std::tuple<int, int, int> 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<int, int, int> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user